Some of the things I see are Variable that have not been declared.
This is not like some basics, in PBP all variables have to be defined
For example:
MYVAR VAR BYTE
A label name can only be used once.
You have bad_tag used at least twice.
Read through the code you have and see if it flows the way you want it.
You may find it easier to write your own from scratch and not do a copy paste. That is what it looks like to me.
Below is the code as you have it posted in code brackets
Make it easier for people to see and maybe help you.
Code:
' LCD clock program using On Interrupt
' Uses TMR0 and prescaler. Watchdog Timer should be
' set to off at program time and Nap and Sleep should not be used.
' Buttons may be used to set time
define LOADER_USED 1
define OSC 4
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
adcon1 = 7
trisa = %11111111
hour var byte ' Define hour variable
dhour var byte ' Define display hour variable
minute var byte ' Define minute variable
second var byte ' Define second variable
ticks var byte ' Define pieces of seconds variable
update var byte ' Define variable to indicate update of LCD
i var byte ' Debounce loop variable
@ device WDT_OFF
CMCON = 7 ' PORTA digital
Pause 100 ' Wait for LCD to startup
hour = 0 ' Set initial time to 00:00:00
minute = 0
second = 0
ticks = 0
update = 1 ' Force first display
' Set TMR0 to interrupt every 16.384 milliseconds
OPTION_REG = $55 ' Set TMR0 configuration and enable PORTB pullups
INTCON = $a0 ' Enable TMR0 interrupts
On Interrupt Goto tickint
PORTB = 0 ' PORTB lines low to read buttons
TRISB = %11001111 ' Enable buttons
' Main program loop - in this case, it only updates the LCD with the time
mainloop:
' Check any button pressed to set time
If PORTa.2 = 1 Then decmin
If PORTA.3 = 1 Then incmin
' Check for time to update screen
chkup: If update = 1 Then
Lcdout $fe, 1 ' Clear screen
lcdout $FE,$c0,"12:10:00"
' Display time as hh:mm:ss
dhour = hour ' Change hour 0 to 12
If (hour // 12) = 0 Then
dhour = dhour + 12
Endif
' Check for AM or PM
If hour < 12 Then
Lcdout dec2 dhour, ":", dec2 minute, ":", dec2 second, " AM"
Else
Lcdout dec2 (dhour - 12), ":", dec2 minute, ":", dec2 second, " PM"
Endif
update = 0 ' Screen updated
Endif
if hour = 12 and minute = 10 and second = 00 then run
run:
next
bad_tag:
low porta.3 'green LED
pause 500
high portc.0 'red LED
tagnum = 0
lcdout $FE,1,"Sorry Wrong medicine"
freqout portC.5,1000*/$100,115*/$100
pause 3000
serin2 portc.0,84,[str buf\10]
for tagnum = 1 to 2
for idx = 0 to 9
read(((tagnum-1)*10)+idx),char
if(char<>buf(idx)) then goto bad_char
next
goto tag_found_unlock
bad_char:
next
bad_tag:
low porta.3
pause 500
high portc.0
tagnum = 0
lcdout $FE,1,"Incorrect~!!"
freqout portC.5,1000*/$100,115*/$100
pause 3000
goto main
tag_found_unlock
low portc.0
high porta.3
freqout portC.5,2000*/$100,880*/$100
lcdout $FE,1,"Correct"
lcdout $FE,$c0,"right medicine!!"
high porta.3
Goto mainloop ' Do it all foreve
' Increment minutes
incmin: minute = minute + 1
If minute >= 60 Then
minute = 0
hour = hour + 1
If hour >= 24 Then
hour = 0
Endif
Endif
Goto debounce
' Decrement minutes
decmin: minute = minute - 1
If minute >= 60 Then
minute = 59
hour = hour - 1
If hour >= 24 Then
hour = 23
Endif
Endif
' Debounce and delay for 250ms
debounce: For i = 1 to 25
Pause 10 ' 10ms at a time so no interrupts are lost
Next i
update = 1 ' Set to update screen
Goto chkup
' Interrupt routine to handle each timer tick
disable ' Disable interrupts during interrupt handler
tickint: ticks = ticks + 1 ' Count pieces of seconds
If ticks < 61 Then tiexit ' 61 ticks per second (16.384ms per tick)
' One second elasped - update time
ticks = 0
second = second + 1
If second >= 60 Then
second = 0
minute = minute + 1
If minute >= 60 Then
minute = 0
hour = hour + 1
If hour >= 24 Then
hour = 0
Endif
Endif
Endif
update = 1 ' Set to update LCD
tiexit: INTCON.2 = 0 ' Reset timer interrupt flag
Resume
End
Bookmarks