so after a couple of days of trouble shooting and debugging i finally got this LCD Driver thing to work. my problem was that i was using serout and needed to use serout2. with serout2 i can send ascii value numbers so if i send DEC 123, i will recieve the string "123" where as with serout if i send 123 i will receive "{" and i couldn't use the operator "DEC" with serout because the compiler would say that i have a syntax error.
so this is defenitely NOT the most effecient way of making an LCD driver but it works for me. i have to initialize serout2 everytime with the "start" string and end it with the "null" (ascii 0) character. i also changed it so that the LCD commands are as follows:
"$FE, 1" = 1
"$FE, 2" = 2
"$FE, $0C" = 3
"$FE, $0E" = 4
"$FE, $0F" = 5
"$FE, $10" = 6
"$FE, $14" = 7
"$FE, $80" = 8
"$FE, $C0" = 9
so here is my code:
===============Transmitter===============
Define OSC 4 'osc at 4 MHZ
TRISA = %000000 'PORTA.5 output rest input
TRISC = %111111 'PORTC INPUT
ANSEL = 0 '0 analog inputs
CMCON0 = 7 'comparators off
LCD var PORTA.1
T2400 con 396 '2400 baud
counter VAR WORD
counter = 1
loopa:
serout2 LCD, T2400, ["start", 1, 0] ' 1 = $FE, 1clear screan
pause 5
serout2 LCD, T2400, ["start", 9, "Second Line", 0] ' 9 = $FE, $C0
pause 5
serout2 LCD, T2400, ["start", 8, "counter = ", DEC (counter), 0] ' 8 = $FE, $80
pause 2000
counter = counter + 1
goto loopa
===============Reciever=================
Define OSC 4 'OSC at 4 MHZ
Define LCD_DREG PORTC 'Port for LCD Data
Define LCD_DBIT 0 'Use lower 4 bits of Port
Define LCD_EREG PORTA 'Port for Enable (E) bit
Define LCD_EBIT 4 'Port Pin for E bit
Define LCD_RSREG PORTA 'Port for RegisterSelect (RS) bit
Define LCD_RSBIT 5 'Port Pin for RS bit
Define LCD_BITS 4 'Using 4-bit bus
Define LCD_LINES 2 'Using 2 line Display
Define LCD_COMMANDUS 2000 ' Command Delay (uS)
Define LCD_DATAUS 50 'Data Delay (uS)
TRISA = %000100 'Set PORTA.0 as input rest output
TRISC = %000000 'Set PORTA as OUTPUT
ANSEL = 0 '0 analog inputs
CMCON0 = 7 'Disable analog comparator
SerialIn var PORTA.2 'Serial Input
mode con 396 '2400 baud
first VAR BYTE
initial VAR BYTE
last VAR BYTE
i1 VAR BYTE
testSTR VAR BYTE[30]
i1 = 0
pause 1000
lcdout $FE, $0F 'clear screen
lcdout $FE, 1
LCDOUT "LCD WORKS"
pause 2000
LCDOUT $FE, 1
begin:
serin2 SerialIn, mode, [WAIT ("start"), STR testSTR\30\0]
for i1 = 0 to 29
if testSTR[i1] = 0 then
last = i1
i1 = 29
endif
next i1
first = testSTR[0]
initial = 0
last = last - 1
if (first >= 0) and (first <= 9) then
initial = 1
endif
if (first >= 10) and (first <= 15) then
initial = 2
endif
if first = 1 then
LCDOUT $FE, 1
GOTO writeW
endif
if first = 2 then
LCDOUT $FE, 2
GOTO writeW
endif
if first = 3 then
LCDOUT $FE, $0C
GOTO writeW
endif
if first = 4 then
LCDOUT $FE, $0E
GOTO writeW
endif
if first = 5 then
LCDOUT $FE, $0F
GOTO writeW
endif
if first = 6 then
LCDOUT $FE, $10
GOTO writeW
endif
if first = 7 then
LCDOUT $FE, $14
GOTO writeW
endif
if first = 8 then
LCDOUT $FE, $80
GOTO writeW
endif
if first = 9 then
LCDOUT $FE, $C0
GOTO writeW
endif
writeW:
for i1 = initial to last
LCDOUT testSTR[i1]
next i1
goto begin
by the way thank you skimask, if it wasn't for your bright idia of searching for the fricken character in the Rx i probably wouldv blanked out and not have figured it out.
Bookmarks