📄 program.c
字号:
#include<at89x52.h>
unsigned char code dispbitcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
0x82,0xf8,0x80,0x90,0xff};
unsigned char dispbuf[6]; //dispbuf[6]必须大于dispbuf[3] 否则相等时,找到的是地址。//用dispbuf[3]不会显示
unsigned int i;
unsigned int j;
unsigned char getdata;
unsigned int temp;
unsigned int temp1;
unsigned char count;
unsigned char d;
sbit ST=P3^0;
sbit OE=P3^1;
sbit EOC=P3^2;
sbit CLK=P3^3;
sbit P10=P1^0;
sbit P11=P1^1;
sbit P12=P1^2;
sbit P13=P1^3;
sbit P27=P2^7;
void TimeInitial();
void Delay(unsigned int i);
void TimeInitial() //开中断
{ TMOD=0x10;
TH1=(65536-200)/256;
TL1=(65536-200)%256;
EA=1;
ET1=1;
TR1=1;
}
void Delay(unsigned int i) //延时程序
{
unsigned int j;
for(;i>0;i--)
{
for(j=0;j<125;j++)
{;}
}
}
void Display()
{
P2=dispbitcode[dispbuf[3]]; //如果P2=0xff; 第一位不显示,消隐 //显示第一位
P10=1;
P11=0;
P12=0;
P13=0;
Delay(10);
P2=0xff;
P2=dispbitcode[dispbuf[2]]; //显示第二位
P27=0;
P10=0;
P11=1;
P12=0;
P13=0;
Delay(10);
P2=0xff;
P2=dispbitcode[dispbuf[1]];//显示第三位
P10=0;
P11=0;
P12=1;
P13=0;
Delay(10);
P2=0xff;
P2=dispbitcode[dispbuf[0]];//显示第四位
P10=0;
P11=0;
P12=0;
P13=1;
Delay(10);
P2=0xff;
}
void main()
{
TimeInitial();
while(1)
{
ST=0;
OE=0;
ST=1;
ST=0;
while(EOC==0); //如果EOC等于0,一直循环,等待转换结束。转换结束EOC等于1,执行下一步。
OE=1;
getdata=P0;
OE=0;
temp=getdata*1.0/255*500;
dispbuf[0]=temp%10;
dispbuf[1]=temp/10%10;
dispbuf[2]=temp/100%10;
dispbuf[3]=temp/1000;
Display();
}
}
void t1(void) interrupt 3 using 0
{
TH1=(65536-200)/256;
TL1=(65536-200)%256;
CLK=~CLK;
}
/*temp==489
dispbuf[0]=489%10; 取余运算,结果为9 //个位数运算
dispbuf[1]=489/10%10; 489/10 取商运算,结果为48 ; 48%10=8 //十位数运算
dispbuf[2]=489/100%10; 489/100 取商运算,结果为4 4%10 取余运算。结果为4
dispbuf[3]=489/1000; 489/1000 取商运算,结果为0
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -