想1s采集一下adc的值,但是好像单片机程序无法进入中断
#include <reg51.h>
#include <ABSACC.H>
#define smg_seg P1
#define smg_com P2
#define ADC XBYTE[0xbff4]
#define uchar unsigned char
#define uint unsigned int
void SAM2();
void timer0init();uchar ADC_cvt;uchar ADC_flag=0;uchar code combit[]={0xb1,0xb2};uchar code segbit[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void main()
{
ADC=0;
timer0init();
while(1);
}
void timer0init()
{
TMOD |= 0x01;
TH0 = (65536-45872)/256;
TL0 =(65536-45872)%256;
TR0 = 1;
ET0 = 1;
EA = 1;
}
void Timer0() interrupt 1
{
TH0 = (65536-45872)/256;
TL0 =(65536-45872)%256;
ADC_flag++;
if(ADC_flag==20)
{
ADC_flag=0;
SAM2();
}
}
void SAM2()
{
ADC_cvt=ADC;
delay(5);
seg_display(ADC_cvt);//shumaguan xianshi
delay(5);
ADC=0;
}
void seg_display(uchar temp)
{
uchar loop,dispbuf[2];
dispbuf[1]=temp%16;
dispbuf[0]=temp/16;
for(loop=0;loop<2;loop++)
{
smg_seg=segbit[dispbuf[loop]];
smg_com=combit[loop];
delay(5);
smg_com=0xf0;
}
}
|