
main.c
#include
#define uchar unsigned char
#define uint unsigned int
sbit Start = P3^0;
sbit EOC=P3^1; //
sbit OE=P3^2 ; //
uchar code table [] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};//段选
uchar code table_SMG [] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};//位选
//------------------------变量区------------------------
uint temp;
//------------------------函数区------------------------
void Init_A_D()
{
Start = 0;
OE = 0;
Start = 1;
Start = 0;
}
void Delay(uint t)//
{
while(t--);
}
void Display_SMG(uchar pos , uchar date)//
{
P2 = table_SMG [pos];//
P1 = date ;//
Delay(100);//
}
void Display_Time() //
{
Display_SMG(0 , table [temp/100%10]|0x80);//
Display_SMG(2 , table [temp%10]);
Display_SMG(1 , table [temp/10%10]);
}
void Read_U()
{
if(EOC==1)
{
OE=1; //
temp=P0; //
temp=temp*1.0/255*500; //
OE=0; //
Display_Time();//
Start=1; //
Start=0;
}
}
void main()
{
Init_A_D();
while(1)
{
Read_U();
}
}
仿真图如下:
注意:所使用的数码管为共阴数码管
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)