程序:
//************ccp************//
#include<reg51.h>
#include<AD0809.h>
void main() //主函數(shù)
{
init_timer0();
while(1)
{
handle_ad();
}
}
void init_timer0()
{
TMOD=0x02; //2
TH0=0x14;//TH0=256-236;
TL0=0x14; //TL0=256-236;
IE=0x82;
TR0=1;
}
void start()
{
ST=0;
ST=1;
ST=0;
}
void set_OE()
{
OE=1;
}
void clr_OE()
{
OE=0;
}
void delay(uint t) // delay
{
uchar i;
while(t--)
{
for(i=0;i<120;i++);
}
}
//*******數(shù)碼管顯示*******
void display()
{
unsigned char j;
for(j=0;j<=3;j++)
{
P2=ledwei[j];
if(j==1)
{
P0=display_c[count[j]];
delay(1);
}
P0=display_cc[count[j]];
delay(1);
}
}
void handle(uint num)
{
num=num*250;
num= num/256;
num=num*40;
count[0]= num %10;
count[1]= num %100/10;
count[2]= num %1000/100;
count[3]= num /1000;
}
void handle_ad()
{
start();
while(EOC==0);//等待轉(zhuǎn)換結(jié)束,轉(zhuǎn)換EOC=0
set_OE();
handle(P3);
display(); // OE=0; //高阻
clr_OE(); //高阻
}
void timer0() interrupt 1
{
CLK=~CLK;
}
//*************ccp*********************//
#ifndef _D0809_
#define _0809_
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar code display_cc[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//共陰
uchar code display_c[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//共陰
uchar code ledwei[]={0xf7,0xfb,0xfd,0xfe};
static uint count[]={0,0,0,0};
sbit CLK=P1^3;
sbit ST=P1^2;
sbit EOC=P1^1;
sbit OE=P1^0;
//定義函數(shù)
void init_timer0(); //初始化
void start();
void set_OE();
void clr_OE();
void delay(uint t);
void display();
void handle(uint num);
void handle_ad(); //處理
#endif