Ok, I'm back. In the last program I posted, I had the values hardcoded in the transmitter side, so since they displayed correctly, now try a couple of dummy values hardcoded in the receiver side. Try out these programs and let me know what happens....
Things I changed since the last programs posted a couple of days ago:
Removed the hardcoded '444' and '888' on the transmitter side
Added a hardcoded '444' and '888' on the receiver side.
On both the transmit and receive side, I split the serout and serin into 4 seperate lines, each sending (or receiving) one byte. I don't know if this will fix the problem or not.
I also added a couple of lines in there to 'sync' up the transmit and receive sides in the case that the receive side starts receiving in the middle of a transmission (which could happen). Very simple setup - 6 bytes are sent, 1st byte - $aa , 2nd-3rd-tempC, 4th-5th-tempF, 6th byte-$55. 1st and 6th byte should add up to $FF. If it doesn't, it was received in the wrong order is values are thrown out. (actually, the 2 numbers from the transmit side could be any pair, as long as they add up to $ff, the receiver will take it, which could mess up the values at the receiver if the right temperature combination comes along, but we'll stay with this for now)
If the receive side shows '444' and '888', remove the lines and comments, and try it again. It just might work...
Of course then again, over the past couple of days, you might've gotten it fixed, which would be a sweet deal overall...
Added a line to idle the transmit line high between characters. This might fix the whole problem...?(see next post)
'RECEIVE PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
'try1 = count of times waiting for data, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
leader var byte : trailer var byte
input portb.2 : pause 2500
try1 = 0 : try2 = 0
loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2 : try1 = try1 + 1
temp = 0 : tempf = 0 : leader = 0 : trailer = 0 'clear out old values
temp1 = 0 : temp2 = 0 : temp3 = 0 : temp4 = 0 'clear out old values
serin portb.2 , t2400 , [ leader ] 'get leader byte
serin portb.2 , t2400 , [ temp1 ]:serin portb.2 , t2400 , [ temp2 ] 'get data
serin portb.2 , t2400 , [ temp3 ]:serin portb.2 , t2400 , [ temp4 ] 'get data
serin portb.2 , t2400 , [ trailer ] 'get trailer byte
'remove the line below if 444 and 888 show up on the LCD
temp1 = 1 : temp2 = 188 : temp3 = 3 : temp4 = 120
'remove the line above if 444 and 888 show up on the LCD
if ( leader + trailer ) <> $ff then 'if leader + trailer doesn't add up right...
lcdout $fe , $c0 , "No Sync..", DEC3 try1 , "," , DEC3 try2
pause 200 : goto loop 'try again
endif
temp.highbyte = temp1 : temp.lowbyte = temp2 'put the received values
tempf.highbyte = temp3 : tempf.lowbyte = temp4 'where they need to be
if temp + tempf > 0 then try2 = try2 + 1 'if temp+tempf are not 0 then data received
lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FR" : pause 100
lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
goto loop
End
'TRANSMIT PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 33333
try1 var byte : try2 var byte : output portb.2 : high portb.2 : input portb.3
dq var portb.4 : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
pause 2500
try1 = 0 : try2 = 0
loop:
lcdout $fe , $c0 , "Getting.." , DEC3 try1 , "," , DEC3 try2 : try1 = try1 + 1
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FT"
lcdout $fe , $c0 , "Sending.." , DEC3 try1 , "," , DEC3 try2
high portb.2 : serout portb.2, t2400 , [ $aa ] 'send a leader byte
temp1 = temp.highbyte : temp2 = temp.lowbyte
high portb.2 : serout portb.2 , t2400 , [ temp1 ]
high portb.2 : serout portb.2 , t2400 , [ temp2 ] 'send data
temp3 = tempf.highbyte : temp4 = tempf.lowbyte
high portb.2 : serout portb.2 , t2400 , [ temp3 ]
high portb.2 : serout portb.2 , t2400 , [ temp4 ] 'send data
high portb.2 : serout portb.2 , t2400 , [ $ff ] 'send a trailer byte
high portb.2 : try2 = try2 + 4 : lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
goto loop
Bookmarks