'**************************************************************** * '* Notes : To use this example with MicroCode Studio, you * '* : should: * '* : (1) Compile this code and program your target * '* : MCU using the 'Compile and Program' button * '* : or F10 * '* : (2) Ensure that a serial cable is connected to * '* : your PC and development board (using a * '* : suitable line driver like a MAX232) * '* : (3) Open the Serial Communications Window (from * '* : VIEW or just press F4 * '* : (4) Select the correct COM port and set the * '* : baudrate to 19200 * '* : (5) Press the 'Connect' button * '**************************************************************** define LOADER_USED 1 ' using a loader, OK to leave in if a loader is not used define OSC 20 ' this example uses a 20MHz clock DEFINE HSER_BAUD 19200 ' set baud rate to 19200 Minute var byte ' Define minute variable Second var byte ' Define second variable Ticks var byte ' Define pieces of seconds variable DoUpdate var byte ' Define variable to indicate update clear ' clear all RAM (sets all VAR declarations to zero) DoUpdate = 1 ' Force first display OPTION_REG = $57 ' Set TMR0 configuration INTCON = $A0 ' Enable TMR0 interrupts On Interrupt Goto TickInterrupt ' Main program loop MainLoop: if DoUpdate then hserout [dec2 Minute,":", dec2 Second,$D,$A] DoUpdate = 0 endif Goto MainLoop ' Interrupt routine to handle each timer tick ' Disable interrupts during interrupt handler disable TickInterrupt: Ticks = Ticks + 1 ' Count pieces of seconds If Ticks < 61 Then ExitInterrupt ' 61 ticks per second ' 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 endif Endif DoUpdate = 1 ' Set update ExitInterrupt: INTCON.2 = 0 ' Reset timer interrupt flag Resume