📄 8路数字电压表的设计.c
字号:
#include <AT89X51.h>
#include <intrins.h>
#define ad_con P3
#define addata P0
#define Disdata P1
#define uchar unsigned char
#define uint unsigned int
sbit ALE=P3^5;
sbit START=P3^6;
sbit OE=P2^5;
sbit EOC=P3^2;
sbit DISX=Disdata^7;
uchar code dis_7[11]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff};
uchar code scan_con[4]={0xfe,0xfd,0xfb,0xf7};
uchar data ad_data[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
uint data dis[5]={0x00,0x00,0x00,0x00,0x00};
delay1ms(uint t)
{
uint i,j;
for(i=0;i<t;i++)
for(j=0;j<120;j++);
}
scan()
{
uchar k,n;
uint h;
dis[3]=0x00;
for(n=0;n<1;n++)
{
dis[2]=ad_data[n]/51;
dis[4]=ad_data[n]%51;
dis[4]=dis[4]*10;
dis[1]=dis[4]/51;
dis[4]=dis[4]%51;
dis[4]=dis[4]*10;
dis[0]=dis[4]/51;
for(h=0;h<500;h++)
{
for(k=0;k<4;k++)
{
Disdata=dis_7[dis[k]];
if(k==2){DISX=0;}
P2=scan_con[k];delay1ms(1);P2=0xff;
}
}
// dis[3]++;
}
}
test()
{
uchar m;
uchar s=0x00;
//ad_con=s;
for(m=0;m<1;m++)
{
ALE=1;_nop_();_nop_();ALE=0;
START=1;_nop_();_nop_();START=0;
_nop_();_nop_();_nop_();_nop_();
while(EOC==0);
OE=1;ad_data[m]=addata;OE=0;//s++;ad_con=s;
}
//ad_con=0x00;
}
main()
{
P0=0xff;
P2=0x00;
P1=0xff;
P3=0xff;
while(1)
{
test();
scan();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -