//timer1 interrupt
//Press spacebar to get time
//display Time 00:00:00
//#include <16F628.h>
#include <16F648A.h>
#use delay(clock=4000000)
#fuses XT,PUT,BROWNOUT,MCLR,NOWDT,NOPROTECT,NOLVP
#define TxD PIN_A0
#define RxD PIN_A1
#use rs232(baud=9600, xmit=TxD,rcv=RxD)
int hour,min,sec;
int TmSum=0;
#INT_TIMER1
void INTTM1(void)
{
TmSum++;
set_timer1(3036); //Reload
}
void main(void)
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
set_timer1(3036);
hour =0;
min = 0;
sec = 0;
printf("Interrupt Timer1 press Any key to get Time\r\n");
while(TRUE)
{
if(TmSum>2)
{
printf(".");
if(++sec==60)
{
sec = 0;
if(++min==60)
{
min = 0;
if(++hour==24)
hour = 0;
}
}
TmSum = 0;
}
//Press Any key to get time
if(kbhit())
printf("\r\nTime:%02d:%02d:%02d\r\n",hour,min,sec);
}
}