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
#include "ADuC812.h"
#include "max.h"
#include <stdio.h>
#include <stdlib.h>
#define SV 0x7
#define BUSY 0x80
unsigned char mCountTik;
unsigned char mTikPer1s=48;
double total=0;
int bytes;
idata char buf[16];
void send(char *str){
unsigned char i;
while(str[i]){
TI = 0;
SBUF = str[i];
while(!TI);
i++;
}
}
//========Timer INTERRUPT=========
void t0ISR(void) interrupt 1
{
TR0=0;
TH0=0;
TL0=0;
TR0=1;
mCountTik++;
if(mCountTik==mTikPer1s){
EA = 0;
bytes=sprintf(buf,"%s","U(B)=");
bytes+=sprintf(buf+bytes,"%0.3f",total);
send(buf);
while(1);
}
}
//================================
void main(void){
//=============
//Timer O
TMOD|=0x01;
ET0=1;
EA=1;
TR0=1;
//UART
TH1=0xF9; //Speed 9600
TMOD |= 0x20;
TCON = 0x40;
SCON = 0x50;
PCON &= 0x7F;
//ADC
ADCCON1=0xA0; //Vnytrenniy istochnik opornogo naprageniya
ADCCON2=0; //ADC: Channel 0
ADCCON2|=0x10;
ADCCON1|=0x80; //Start ADC
//=============
while(1){
while (ADCCON3&BUSY);
total=((unsigned short)(ADCDATAH&0xF)<<8)|ADCDATAL;
total=2.5/4096*total*2;
if (total<=3) mCountTik = 0;
ADCCON2|=0x10;
}
}