Cool, theres deff communication because I've got the LCD to display the value of the Dat variable, only problem is, when I press 1 on the keypad I get 10 on the display, and for 2 I get 40 and then it changes to 60 when I press 2 again, so something strange is going on... any ideas?
Keypad:
Code:
INCLUDE "modedefs.bas"
' Declare Variables...
Col1 VAR PORTA.0
Col2 VAR PORTA.1
Col3 VAR PORTA.2
Row1 VAR PORTB.4
Row2 VAR PORTB.5
Row3 VAR PORTB.6
Row4 VAR PORTB.7
LED var PORTB.1
SERTX var PORTB.2
SERoK var PORTB.3
Key var byte
' Setup Ports
input row1 : input row2 : input row3 : input row4
output col1 : output col2 : output col3 : output SERTX
' Setup Var
key = 20
' Program Start
Boot:
high led
pause 500
low led
pause 100
high led
pause 100
low led
pause 2000
high serok
goto main
Main:
gosub ScanKeys
if key <> 20 then gosub transmit
goto main
ScanKeys:
high col1
pause 50
if row1 = 1 then Key = 1
if row2 = 1 then Key = 4
if row3 = 1 then Key = 7
if row4 = 1 then Key = 10
low col1
high col2
pause 50
if row1 = 1 then Key = 2
if row2 = 1 then Key = 5
if row3 = 1 then Key = 8
if row4 = 1 then Key = 0
low col2
high col3
pause 50
if row1 = 1 then Key = 3
if row2 = 1 then Key = 6
if row3 = 1 then Key = 9
if row4 = 1 then Key = 11
low col3
return
Transmit:
gosub flash
serout sertx,T2400,[key]
pause 50
key = 20
low led
return
Flash:
high led
pause 50
low led
pause 50
high led
pause 50
return
end
Robot:
Code:
INCLUDE "modedefs.bas"
' Define LCD registers and bits
Define LCD_DREG PORTA
Define LCD_DBIT 0
Define LCD_RSREG PORTA
Define LCD_RSBIT 4
Define LCD_EREG PORTA
Define LCD_EBIT 5
DEFINE LCD_LINES 4
' Define HSER Registers
' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h
' Set baud rate
DEFINE HSER_BAUD 2400
'Define Aliases
RHF var PORTB.0
RHB VAR PORTB.1
LHF VAR PORTB.2
LHB VAR PORTB.3
LineCom var PORTB.4
LEDS var PORTB.5
SERoK var PORTB.7
SERRX var PORTB.6
'Define Vars
Dat var byte
ADCON1 = 7
'Begin program
Boot:
dat = 20
Pause 500 ' Wait for LCD to startup
gosub display
low leds
repeat
Lcdout $FE, $C0, "!! Insert Ctrl !!"
Lcdout $FE, $94, "Waiting..."
Lcdout $FE, $D4, "Dat = ",#Dat
pause 100
until serok = 1
goto modeselect
ModeSelect:
Lcdout $FE, $C0, "!! Select Mode !!"
Lcdout $FE, $94, "Waiting..."
Lcdout $FE, $D4, "Dat = ",#Dat
gosub commrx
if dat <> 20 then
goto discon
else
goto modeselect
endif
Discon:
Lcdout $FE, $94, "Pls Discon..."
Lcdout $FE, $D4, "Dat = ",#Dat
if serok = 0 then GoMode
goto discon
CommRX:
HSERIN [Dat]
return
GoMode:
if dat <> 20 then
select case dat
case 20
goto boot
case 2
goto linefollow
end select
endif
goto boot
Display:
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "PIC-Bot... v1.0"
Lcdout $FE, $94, "Pls Wait..."
Pause 1000
return
'Check for controler
ChkCtrl:
if serok = 1 then modeselect
return
'Line Follow loop
LineFollow:
Lcdout $FE, $C0, "~~ LiNe FoLlOw ~~"
Lcdout $FE, $94, "...Scan Line..."
low RHF
low LHF
PWM LHF,60,18
pause 100
if linecom = 0 then gosub moveleft
low RHF
low LHF
PWM RHF,60,18
pause 100
if linecom = 0 then gosub moveright
gosub chkctrl
goto linefollow
MoveLeft:
Lcdout $FE, $94, "Correct Left"
repeat
low RHF
low LHF
PWM RHF,60,20
PWM LHb,60,20
pause 100
until linecom = 1
pause 50
low RHF
low LHF
PWM RHF,60,18
return
MoveRight:
Lcdout $FE, $94, "Correct Right"
repeat
low RHF
low LHF
PWM LHF,60,20
PWM rHb,60,20
pause 100
until linecom = 1
pause 50
low RHF
low LHF
PWM LHF,60,18
return
end
Bookmarks