Assignment 6 part C

 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
#include <stdio.h>
#include <reg66x.h>
#include <DISPPORT.h>
sbit light=P2^0;
sbit switc=P2^1;
#define TH0_R 0xB7
#define TL0_R 0xFF
#define on 0
#define off 1
void tinit0(void); //timer 0 init function
void init_intt();
unsigned int tcounter=0;
void main()
{light=off;
init_display();
init_intt();
tinit0(); //init timer 0
while(1)
{
cursor(1,1);
printf("%d ",tcounter);
}}
void tinit0(void) //timer init fuction
{TMOD=0x01;
TH0=0xB7;
TL0=0xFF;
TR0=1;
}
void init_intt(void)
{
IT1=1;
EX1=1;
ET0=1;
EA=1;
}
void set_light (void) interrupt 2
{light=on;
tcounter=0;
}
void timer_int (void) interrupt 1
{
TH0=0xB7;
TL0=0xFF;
tcounter++;
if (tcounter>600){
light=off;
tcounter=0; }
}