📄 dyb.c
字号:
#include<reg52.h>
unsigned char dispcount=0,getdata=255;
unsigned code seg[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //显示段位
unsigned dispbuf[3]={0,0,0}; //显示缓存
unsigned dispbit[]={0x0e,0x0d,0x0b,0x07}; //数位扫描
unsigned int i;
float temp,x;
sbit ST=P3^0;
sbit OE=P3^1;
sbit EOC=P3^2;
sbit CLK=P3^4;
void main()
{
int temp1;
ST=0; //清除寄存器
OE=0; //浮空数据位
TMOD=0x12; //定时器模式设置
TH0=216; //定时器0用来给ADC发时钟脉冲
TL0=216;
TR0=1;
TR0=0;
ET0=1;
EA=1;
ST=1; //清除芯片内部寄存器
ST=0; //启动AD转换
while(1)
{
if(EOC==1) //转换结束信号
{
TR0=0;
OE=1; //输出允许
getdata=P0; //从P0把数据读入
OE=0;
x=(float)getdata/51; //对数据进行转换,转换成0~5V值
temp=x*100.0;
temp1=(int)temp; //乘以100后强制转换
dispbuf[0]=temp1/100; //取个位数
dispbuf[1]=temp1/10%10; //取十分位数
dispbuf[2]=temp1%10; //取百分位数
ST=1;
ST=0;
TR0=1;
/*********************显示部分*********************/
P1=0x00;
P1=seg[dispbuf[dispcount]];
P2=dispbit[dispcount];
if(dispcount==0)
{
P1=P1|0x80;
}
dispcount++;
if(dispcount==3)
{
dispcount=0;
}
}
}
}
/*******************************************************************************
/*函数名称:clock
/*功能:为ADC芯片提供时钟脉冲
*******************************************************************************/
void clock(void) interrupt 1 using 0
{
CLK=~CLK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -