Hi Guys. I'm pretty new to picbasic pro. I've tried to create a temperature control system but having endless dead-ends. I've tried my best with the code and so far I managed to get the program to display the temperature. Adding in buttons though is what's giving me problems. Below is a copy of my program. Please help me somebody.
/Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 5
Define LCD_EREG PORTB
Define LCD_EBIT 4
dEFINE LCD_BITS 4
DEFINE LCD_LINES 2
adval var word ' Create adval to store result
tempc var word ' Create tempc to store result
Setpoint var word
sethigh var byte
setlow var byte
Temp_Up var PORTC.0
Temp_Down var PORTC.1
High_sp var PORTC.2
Low_sp VAR PORTC.3
Main_disp VAR PORTC.4
TRISC = %11111111 ' Set PORTC to all input
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and RIGHT justify result
ADCON0 = %11000001 ' Configure and turn on A/D Module
Pause 100 ' Wait 0.1 second
START:
if High_sp = 1 then gosub Set_High
IF Low_sp = 1 then gosub Set_Low
IF Main_disp = 1 then gosub Main
pause 10 '????????????? debounce how?
Keypress:
if Temp_Up = 1 then gosub Up_Loop
if Temp_Down = 1 then gosub Down_Loop
GOTO START
Main: ADCON0.2 = 1 ' Start Conversion
AGAIN: Pause 1
If ADCON0.2 = 1 Then AGAIN ' Wait for low on bit-2 of ADCON0, conversion finished
adval.highbyte = ADRESH ' Move HIGH byte of result to adval
adval.lowbyte = ADRESL ' Move LOW byte of result to adval
Lcdout $fe, 1 ' Clear screen
tempc=50*adval ' Conversion to Degrees
tempc=tempc/100
Lcdout "Temp = ",DEC tempc,$DF,"C" ' Display the value of temp
if Tempc > 100 then
lcdout "Out of range!"
endif
if Tempc < 0 then
lcdout "Out of Range!"
endif
Pause 1000 ' Wait 1 second
Goto Main ' Do it forever
Up_Loop:
If Temp_Up = 1 Then
Setpoint = Setpoint + 1
if Setpoint>100 then SetPoint=0
lcdout $fe, 1, "Setpoint = ", Setpoint
Pause 10
Else
Goto Keypress
Endif
Goto Up_Loop
Down_Loop:
If Temp_Down = 1 Then
Setpoint = Setpoint - 1
if Setpoint>0 then SetPoint=100
lcdout $fe, 1, "Setpoint = ", Setpoint
Pause 10
Else
Goto Keypress
Endif
Goto Down_Loop
Set_High: '?????????? Im trying to store the value
gosub Keypress '?????????? from the Temp_Up/Temp_Down.
write sethigh, Keypress '??????????
Set_Low: '?????????? Im trying to store the value
gosub Keypress '?????????? from the Temp_Up/Temp_Down.
write setlow, Keypress '??????????
end
Bookmarks