'/--------------------------------------------------------------------- '/ PROGRAM for VENTILATION FAN CONTROLLER ** '/ AUTHOR: JAROON KEAWKHRUA '/ START 14/10/2542 '/ UPDATE 14/10/2542 '/ modified from PIC CLOCK.BAS '/--------------------------------------------------------------------- Include "bs1defs.bas" sout var portb.3 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 th var word vr var word comp var word sen var portb.0 serout sout,n9600,["Hello",10,13] minute=0 : second=0 : comp=0 high porta.2 low portb.1 low portb.2 update = 1 ' Force first display ' Set TMR0 to interrupt every 16.384 milliseconds OPTION_REG = $d5 ' Set TMR0 configuration INTCON = $a0 ' Enable TMR0 interrupts On Interrupt Goto tickint ' Main program loop - in this case, it only updates the LCD with the time mainloop: If update = 1 Then ' Display time as hh:mm:ss SENT: HIGH SEN PAUSE 1 RCTIME SEN,1,TH ' use RC time instruction to read POT resistance vr = th*8 vr = vr+50 if comp => vr then low porta.2 high portb.1 high portb.2 endif serout sout,n9600,[#minute,":",#second," ",#vr," ",13] ' used during debugging update = 0 ' Screen updated Endif Goto mainloop ' 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 elapsed - update real-time clock ticks = 0 comp = comp + 1 second = second + 1 If second >= 60 Then second = 0 minute = minute + 1 If minute >= 10 Then minute = 0 comp = 0 high porta.2 low portb.1 low portb.2 Endif Endif update = 1 ' Set to update LCD tiexit: INTCON.2 = 0 ' Reset timer interrupt flag Resume