Virtual Integrated Design

RS232 LCD Circuit

 



Main File:


/*
main_lcd.c
Compiler: Hitech
Device: Pic16F84
Oscillator Freq: 4Mhz
Baud Rate: 9600
www.viddata.com
Copyright 2002, Virtual Integrated Design, all rights reserved.

Use this project to build an RS232 lcd driver. The commands to
get the desired results are listed below.

Command: Description: Example String:
WRITE_CHAR Write 1 char to lcd. "01010421" = '!' to lcd
WRITE_STRING Write string to lcd. "010208576f726c64" = "HELLO"
CURSOR_BLINK Cursor on and blink. "010303"
CURSOR_OFF Cursor off. "010403"
HOME_LINE1 First space line 1. "010503"
HOME_LINE2 First space line 2. "010603"
CLEAR_LCD Clear/cursor space 1. "010703" = '!' to lcd

*/

#include <pic.h>
#include "main_lcd.h"
#include "09f14m4.h"
#include "lcd.h"
#include "delay.h"

unsigned char i=0, x=0;
unsigned char rx_buffer[BUFFER_SIZE];
const char web_site[]="www.viddata.com";

void main()
{

 TRISA0=INPUT;
 TRISA1=OUTPUT;
 TRISA2=OUTPUT;
 TRISA3=OUTPUT;
 TRISB=OUTPUT;
 RA1=1;
 __CONFIG(UNPROTECT|WDTE|1); /* xtal, wd, no protect */

 CLRWDT();
 lcd_init();
 lcd_clear();
 display_website();
 clear_rx_buffer();

while(1)
{
  while(rx_buffer[0]!=ADDRESS)
  {
    CLRWDT();
    if(RB7){ RB7=0; } else{ RB7=1; }
    rx_buffer[0]=receive_9600_RA0_delay(65535);
  }

  rx_buffer[COMMAND]=receive_9600_RA0();
  rx_buffer[PACKET_SIZE]=receive_9600_RA0();

  for(i=3;i<(rx_buffer[PACKET_SIZE]);i++)
  {
    CLRWDT();
    rx_buffer[i]=receive_9600_RA0();
  }

  switch(rx_buffer[COMMAND])
  {
    case WRITE_CHAR:{ lcd_putch(rx_buffer[3]); break; }
    case WRITE_STRING:
    { 
      for(i=3;i<(rx_buffer[PACKET_SIZE]);i++)
      {
        CLRWDT();
        lcd_putch(rx_buffer[i]);
        transmit_9600_RA1(rx_buffer[i]);
      }
      break; 
    }
    case CURSOR_BLINK:{ RA2=0; lcd_write(0x0F); break; }
    case CURSOR_OFF:{ RA2=0; lcd_write(0x0C); break; }
    case HOME_LINE1:{ lcd_goto(LINE_ONE); break; }
    case HOME_LINE2:{ lcd_goto(LINE_TWO); break; }
    case CLEAR_LCD:{ lcd_clear(); break; }
  }
  clear_rx_buffer();
 }

}


void clear_rx_buffer(void)
{
  for(i=0;i<BUFFER_SIZE;i++){ rx_buffer[i]=0; }
}

void display_website(void)
{
  RA2=0;
  lcd_write(0x0C);
  DelayMs(100);
  lcd_puts(web_site);
  for(i=0;i<50;i++){ DelayMs(100); CLRWDT(); }
  RA2=0;
  lcd_write(0x0F);
  lcd_clear();
}

Hex File:

:10000000830100308A0004280C30840027300D2042
:100010008301962B04068001840A0406031D0A2826
:100020000034A800A91B1B2829088A002808A80A50
:100030000319A90A82008313291883172808A80A1C
:1000400084000008080082077734773477342E3430
:1000500076346934643464346134743461342E34F5
:0800600063346F346D34003489
:1004A200831205110130A42202305D2AA2008312B8
:1004B20005112208803EA42AA3000430A400533070
:1004C200A500A50B622AA40B602AA30B5E2A831245
:1004D20008008C01712A0C080E3E840080018C0AEF
:1004E20014300C02031C6C2A8312080083120515B7
:1004F200832A2308A9002208A20A0319A30A1120A9
:100502008312A4222308A90022081120003803190B
:1005120008007A2A831205110C30A42264305D226D
:100522002430A2000030A30077228C019C2A643080
:100532005D2264008C0A32300C02031C982A0511D9
:100542000F30A422512AA400240E0F39A7008312CF
:100552000608F039270486008515851124080F390D
:10056200A7000608F03927048600851585110D308D
:10057200A500A50BBA2A83120800A2008312051552
:10058200220E0F39A7000608F039270486008515C8
:10059200851122080F39A7000608F03927048600C2
:1005A200851585110D30A300A30BD52A83120800EF
:1005B200831205110F305D220330860085158511E7
:1005C20005305D22851585112130A200A20BE72A94
:1005D20083128515851105305D220230860085154E
:1005E20085110D30A200A20BF42A28308312A42216
:1005F2000830A4220F30A4220630A42AA2008312BB
:1006020085101F30A400A40B042B00000000000082
:100612000000A3010310A20C8312031C122B8514E9
:10062200142B851000001D30A400A40B162B000013
:1006320000000000A30A08302302031C0C2B000058
:100642000000831285142130A400A40B262B8312F0
:100652000800A301831205182C2B3130A400A40B2F
:10066200302BA2018312051C382BA3173A2B23141B
:1006720000000310A30C1D30A400A40B3E2B0000AD
:100682000000A20A073022028312031C342B051C2D
:100692004C2BA3174D2B00003130A400A40B4F2B81
:1006A2000000000000000000000000002308831288
:1006B2000800A501602BA2080319A303A203831259
:1006C20023082204051C692B031D5C2B230822042A
:1006D2000319932B2D30A600A60B6D2B00000000F2
:1006E2000000A4018312051C782BA5177A2B251470
:1006F20000000310A50C1D30A600A60B7E2B0000E7
:100702000000A40A073024028312031C742B051C68
:100712008C2BA5178D2B00003330A600A60B8F2B38
:1007220000000000250883120800831605148510B6
:1007320005118511860183128514D92251228B223B
:100742006A220E030319B12B6400861FAA2B86139B
:10075200AB2B8617FF30A200A3005A238E00A22BD8
:100762002A238F002A23900003308C0010080C02E9
:100772000318E92B64002A23A7000C080E3E84000C
:10078200270880008C0AB72B1108BE22A12B033048
:100792008C0010080C020318A12B64000C080E3EFA
:1007A20084000008BE220C080E3E84000008FF22CE
:1007B2008C0ACA2B05110F30E02B05110C30A42234
:1007C200A12B0030E52B28305722A12B5122A12B3F
:1007D2000F08013A0319C52B033A0319C82B013A32
:1007E2000319DB2B073A0319DE2B013A0319E22B1B
:0E07F200033A0319E42B013A0319E72BA12B5C
:04400E00F53F640016
:00000001FF


Free RS232

 Home | Applications | Industry Links | C++ Builder Stop | Micro Stop | Hex to Ascii Chart