0% found this document useful (0 votes)
17 views

Timer&amp Int

This document contains C code for a clock program. It defines interrupt service routines to increment or decrement the hour variable when external interrupt or push button inputs occur. It also defines an interrupt service routine for a 1 second timer interrupt that increments the seconds, minutes, and hours variables to display the time. The main program configures the interrupts, sets up Timer 1, and enters an infinite loop to continuously display the updated time values.

Uploaded by

Ajsk Sriprang
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Timer&amp Int

This document contains C code for a clock program. It defines interrupt service routines to increment or decrement the hour variable when external interrupt or push button inputs occur. It also defines an interrupt service routine for a 1 second timer interrupt that increments the seconds, minutes, and hours variables to display the time. The main program configures the interrupts, sets up Timer 1, and enters an infinite loop to continuously display the updated time values.

Uploaded by

Ajsk Sriprang
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C:\CCS C_code\Time01\clock.

13-..-11 10:42 am

Page 1 of 2

#include <16F877A.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000)
//Variable use
int overflow=0;
int sec=0;
int min=0;
int hour=0;
#INT_EXT
void ExtInt_isr(void)
{
hour++;
if(hour>24)
{
hour=0;
}
}

EL
T-

RM

TR

#INT_RB
void RBInt_isr(void)
{
if(!input(PIN_B4))
{
hour--;
if(hour<1)
{
hour=0;
}
}
if(!input(PIN_B5))
{
hour=0;
}
}

rig

ht

#INT_TIMER1
void IntT1_isr(void) //Interrupt rounteen 1 second
{
overflow++;
if(overflow>10)
{
overflow=0;
sec++;
output_toggle(PIN_C7);
if(sec>60)
{
sec=0;
min++;
if(min>60)
{
min=0;
hour++;
if(hour>24)
{
hour=0;
}
}
}
}
}

Co
py

1 :
2 :
3 :
4 :
5 :
6 :
7 :
8 :
9 :
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:

void main()
{
ENABLE_INTERRUPTS(GLOBAL);
ENABLE_INTERRUPTS(INT_EXT);
ENABLE_INTERRUPTS(INT_RB);

C:\CCS C_code\Time01\clock.c

13-..-11 10:42 am

Page 2 of 2

rig

ht

EL
T-

RM

TR

EXT_INT_EDGE(H_TO_L);
//ENABLE_INTERRUPTS(INT_TIMER0);
//SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_256);
ENABLE_INTERRUPTS(INT_TIMER1);
SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_8);
set_tris_c(0x00);
set_tris_d(0x00);
set_timer0(0);
output_c(0x00);
while(1)
{
}

Co
py

69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81: }
82:

You might also like