?? adc0809.txt
字號:
#include <AT89X52.H>
unsigned char code dispbitcode[4]={0x0f,0x1f,0x2f,0x3f}; //數(shù)碼管選擇代碼
unsigned char code dispcode[10]={0xf0,0xf1,0xf2,0xf3,0xf4, //字型代碼
0xf5,0xf6,0xf7,0xf8,0xf9};
unsigned char data buf[4]={0x00,0x00,0x00,0x08}; //數(shù)據(jù)存儲
unsigned char data Pcode,Pbit,data1;
char i,j;
unsigned int get=0;
sbit star=P3^6;
sbit oe=P3^7;
void delay(); //延時聲明
void delay1(); //延時聲明
void main(void) //主函數(shù)
{
while(1)
{
P1=0xff; //初始化
P0=0xff;
P2=0x00;
P3=0xff;
star=1; //驅(qū)動ad
star=0;
star=1;
delay1(); //延時給AD處理數(shù)據(jù)
EX1=1; //開INT1中斷
IT1=1; //INT1邊沿觸發(fā)
EA=1; //允許中斷
}
}
void int1(void) interrupt 2 //外部中斷1
{
EA=0; //關(guān)中斷
oe=0; //允許數(shù)據(jù)輸入
get=P0; //獲取數(shù)據(jù)
oe=1; //禁止數(shù)據(jù)輸入
data1=get*200/255; //數(shù)據(jù)處理
buf[2]=data1/100; //存百位
data1=data1%100;
buf[1]=data1/10; //存十位
buf[0]=data1%10; //存?zhèn)€位
for(j=0;j<=30;j++) //循環(huán)顯示30次
{
for(i=0;i<4;i++) //字形輸出
{
Pcode=dispcode[buf[i]];
Pbit=dispbitcode[i];
P1=Pcode&Pbit;
delay();
}
}
}
void delay() //延時子程序
{
unsigned char n, m;
for (n=3; n > 0; n--)
for (m = 200; m > 0; m--);
}
void delay1()
{
unsigned char k;
for(k=0;k<=50;k++);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -