include ADuC812 include max include stdio include stdlib define SV 0x7

 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "ADuC812.h"
#include "max.h"
#include <stdio.h>
#include <stdlib.h>
#define SV 0x7
#define LOCK 0x40
unsigned char mTikPulse, T;
unsigned char mTikPer1s=125, mCountTik=0;
char cnt;
int bytes;
idata char buf[16];
void WriteMax(unsigned char xdata *regnum, unsigned char val){
unsigned char oldDPP=DPP;
DPP=8;
*regnum=val;
DPP=oldDPP;
}
//=====DELAY==========
void delay(long b){
long a;
for (a=0;a<b;a++);
}
//====================
//++++WRITE TEXT++++
void WriteSimvol(unsigned char c1){
WriteMax(DATA_IND,c1);
WriteMax(C_IND,0x05);
WriteMax(C_IND,0x04);
delay (100);
}
//++++++++++++++++++
//========Timer INTERRUPT=========
void t0ISR(void) interrupt 1
{
TR0=0;
TH0=0;
TL0=0;
TR0=1;
mCountTik++;
mTikPulse++;
if (mCountTik == mTikPer1s) {
bytes=sprintf(buf,"%s","T(ms)=");
bytes+=sprintf(buf+bytes,"%0.0f",T);
for (cnt=0;cnt<bytes;cnt++){
WriteMax(C_IND,0x01);
WriteMax(DATA_IND,0x81+cnt);
WriteMax(C_IND,0x00) ;
delay (100);
WriteSimvol(buf[cnt]);
}
WriteMax(SV,0xFF);
while(1); //Stop program
}
return;
}
void t2ISR(void) interrupt 5
{
if (EXF2 == 1){
EXF2 = 0;
T = 4*mTikPulse; //(ms)
mTikPulse = 0;
if ((T>=20)&(T<=60))
mCountTik = 0;
}
if (TF2 == 1){
TF0 = 0;
}
return;
}
//================================
void main(void){
PLLCON = 0; //16MHZ
while(!(PLLCON&LOCK));
EA=1;
//Timer0 and 2 On
TMOD|=0x01;
TR0=1;
ET0=1;
T2CON = 0x9;
ET2=1;
T2CON |= 0x4;
while(1){
}
}