Here's what you need. i'm using the internal USART @2400 baud.
Forget about the INTCON stuff i said before..Code:' Pic define ' ========== ' Using PIC18F2320 ' define LOADER_USED 1 DEFINE OSC 4 ' Hardware definition ' =================== ' ' TRISB=0 TRISC=%10000000 ' Interrupt definition ' ==================== ' ' INTCON = $a0 ' Enable TMR0 interrupts T0CON = %11010101 On Interrupt Goto Gettime ' Serial Communication definition ' =============================== ' ' DEFINE HSER_TXSTA 24h DEFINE HSER_RCSTA 90h DEFINE HSER_BAUD 2400 ' I/O alias definition ' ==================== ' ' PowerLED VAR PORTB.5 'Pin 26 Red StatusLED VAR PORTB.4 'Pin 27 Green ' Variable definition ' =================== ' ' hour var byte ' Define hour variable minute var byte ' Define minute variable second var byte ' Define second variable ticks var byte ' Define pieces of seconds variable Delay var word CLEAR RsetAll: toggle PowerLED 'RED LED ' Delay loop ' ========== ' ' for delay =1 to 10000 pauseus 10 next goto RsetAll ' Interrupt routine to handle each timer tick ' =========================================== ' ' disable ' Disable interrupts during interrupt handler Gettime: ticks = ticks + 1 ' Count pieces of seconds If ticks < 59 Then T1Exit ' 61 ticks per second (16.384ms per tick) ' One second elasped - update time & display ' ========================================== ' ' ticks = 0 second = second + 1 If second >= 60 Then second = 0 minute = minute + 1 If minute >= 60 Then minute = 0 hour = hour + 1 Endif write 43,hour write 44,minute write 45,second Endif hSerOut [#hour,":",#minute,":",#second,13,10] T1Exit: INTCON.2=0 ' clear interrupt flag Resume enable
P.S. By writing to internal EEPROM as often as you do, you'll burn it soon, You should consider the use of external EEPROM like FRAM OR by saving your data only when the Voltage goes bellow a certain threshold. For cheapness i'll use the last option.




Bookmarks