Try those with direct connection.
Code:
'
' TX code
' =======
'
@ device HS_OSC, LVP_OFF
define OSC 20
DEFINE LCD_DREG PORTC 'LCD data port
DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTB 'LCD register select port
DEFINE LCD_RSBIT 7 'LCD register select bit
DEFINE LCD_EREG PORTB 'LCD enable port
DEFINE LCD_EBIT 5 'LCD enable bit
DEFINE LCD_RWREG PORTB 'LCD read/write port
DEFINE LCD_RWBIT 6 'LCD read/write bit
DEFINE LCD_BITS 8 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us
TransmitterPIN VAR PORTA.0
DEFINE CHAR_PACING 500
TRISA = 0 'Set port A as output
TRISB = 0 'Set port B as output
TRISC = 0 'Set port C as output
TRISD = 0 'Set port D as output
' Define program variables
INCLUDE "modedefs.bas"
col var byte ' Keypad column
row var byte ' Keypad row
key var byte ' Key value
Synk VAR BYTE
Synk = $55
ADCON1 = 7 ' Make PORTA and PORTE digital
low PORTB.6 'Set the R/W bit to low
High TransmitterPin
Pause 500 ' Wait for LCD to start
Lcdout $fe, 1, "Key In Bus ID" ' Display sign on message
loop:
Gosub getkey ' Get a key from the keypad
Lcdout $FE, $C0, "BUS",DEC2 key ' Display ASCII key number
SEROUT TransmitterPIN,T2400,[Synk,Synk,"~",KEY]
Goto loop ' Do it forever
' Subroutine to get a key from keypad
getkey:
PORTD = 0 ' All output pins low
TRISD = $f0 ' Bottom 4 pins out, top 4 pins in
WHILE PORTD != $F0 : wEND ' Wait 'till all key=up
PAUSE 50 ' Debounce
ScanKeypad:
For col = 0 to 3 '
TRISD=~(DCD COL) ' Set one I/O to output
PAUSEUS 5 ' wait a little bit to avoid
' erratic results
'
ROW=ncd((~(PORTD>>4)) & $f) ' read row
'
IF ROW THEN ' Any key pressed?
key = ((row-1)*4)+ col+1' --- YES convert key value
return ' and getout of here
ENDIF '
NEXT '
Goto ScanKeypad ' No keys down, go look again
Notice the change in the Keypad scanning routine... this one seems to never have any erratic results now.
Code:
'
' RX code
' =======
'
@ device HS_OSC, LVP_OFF
define OSC 20
DEFINE LCD_DREG PORTC 'LCD data port
DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTB 'LCD register select port
DEFINE LCD_RSBIT 7 'LCD register select bit
DEFINE LCD_EREG PORTB 'LCD enable port
DEFINE LCD_EBIT 5 'LCD enable bit
DEFINE LCD_RWREG PORTB 'LCD read/write port
DEFINE LCD_RWBIT 6 'LCD read/write bit
DEFINE LCD_BITS 8 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us
TRISA = 1 ' PORTA.0 input, other as output
TRISB = 0 ' Set port B as output
TRISC = 0 ' Set port C as output
TRISD = 0 ' Set port D as output
ReciverPIN VAR PORTA.0
ADCON1 = 7 ' Alla digitala
INCLUDE "modedefs.bas"
YourByteVar var byte
low PORTB.6 'Set the R/W bit to low
pause 500 'wait until the LCD initializes
LCDOUT $FE,1, " Receiving Bus ID"
Main:
SERIN ReciverPIN,T2400,["~"],YourByteVar
Lcdout $FE,$C0,"BUS", DEC2 YourByteVar
GOTO Main
Side note...There's no major advantage to use LCD in 8 bit mode.. R/W pin could also be tied directly to ground. This done you save 5 I/Os.
Bookmarks