The value of Keydata is 0 if no key is pressed: here is how I've set that,
if keyin = nokey then keydata = %00000000
Thank you for your help.
The value of Keydata is 0 if no key is pressed: here is how I've set that,
if keyin = nokey then keydata = %00000000
Thank you for your help.
define osc 4
INCLUDE "MODEDEFS.BAS"
CMCON = 7
serpin var porta.3
nokey con %11111111
preamble con %01010101
synch con 254
keyin var portb
keydata var byte
trisb = %11111111
trisa = %00010111
key1 VAR PORTB.0
key2 VAR PORTB.1
key3 VAR PORTB.2
key4 VAR PORTB.3
key5 VAR PORTB.4
key6 VAR PORTB.5
key7 VAR PORTB.6
na VAR PORTB.7
findkey:
clear
pause 50
if key1 = 0 then sw1
if key2 = 0 then sw2
if key3 = 0 then sw3
if key4 = 0 then sw4
if key5 = 0 then sw5
if key6 = 0 then sw6
if key7 = 0 then sw7
if key8 = 0 then sw8
goto findkey
sw1:
keydata = 1
goto transmit
sw2:
keydata = 2
goto transmit
sw3:
keydata = 3
goto transmit
sw4:
keydata = 4
goto transmit
sw5:
keydata = 5
goto dout
sw6:
keydata = 6
goto transmit
sw7:
keydata = 7
goto transmit
sw8:
keydata = 8
goto transmit
transmit:
serout serpin,N2400,[preamble,synch,keydata]
pause 50
if keyin = nokey then keydata = %00000000
goto findkey
end
All define's must be capitalized (not that it makes any difference in this case)
1. There is no Key8.
2. You can send the content of the whole PORTB when a change occurs; may be it would be more convenient but it is up to your choice.
For example:
This code will transmit the content of the PORTB every time there is a change on PORTB.Code:FindKey: CLEAR KeyData = PORTB PAUSE 50 IF PORTB = KeyData THEN FindKey 'Transmit only if there is at least a (one) change on PORTB. SEROUT SerPin,N2400,[PreAmble,Synch,PORTB] PAUSE 50 GOTO FindKey
Thus, for instance, if PORTB.0 is 0, it will transmit, and then if it is still 0, it will NOT transmit.
If PORTB.0 is still 0 and then another change occurs at say PORTB.1 then it will transmit.
This way, you can handle the process at receiver side.
Last edited by sayzer; - 29th January 2008 at 11:59.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Bookmarks