📄 adc0809电压表.c
字号:
#include<reg52.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab0[]="AD0809数字电压表";
uchar code tab1[]="Vx = V";
sbit sid=P0^1;//12864数据输入
sbit sck=P0^0;//12864时钟输入
sbit st=P3^0;
sbit oe=P3^1;
sbit eoc=P3^2;
sbit clk=P3^3;
#define com 0 //指令标志
#define dat 1 //数据标志
//uint temp,a1,a2,a3,a;
uchar dis[16];
float ftemp;
//********12864相关函数*****************//
void w_12864byte(uchar byte)//写字节
{
uchar i;
for(i=0;i<8;i++)
{
sck=0;
byte<<=1;
sid=CY;
sck=1;
sck=0;
}
}
void w_12864(bit dat_com,uchar byt) //写入函数
{
uchar temp;
if(dat_com==0) //为零,写入指令
temp=0xf8; //11111,RS(0),RW(0),0
else //否则,写入数据
temp=0xfa; //11111,RS(1),RW(0),0
w_12864byte(temp);
w_12864byte(byt&0xf0); //写入高四位
w_12864byte(byt<<4); //写入低四位
}
void init_12864(void)//初始化12864
{
w_12864(com,0x30); //基本指令功能.
w_12864(com,0x0c); //显示打开,关光标,反白关.
w_12864(com,0x01); //清屏指令.
w_12864(com,0x06); //AC自动加一
}
void lcd_display()
{
uchar i;
w_12864(com,0x80);
for(i=0;i<16;i++)
{
w_12864(dat,tab0[i]);
}
w_12864(com,0x90);
for(i=0;i<10;i++)
{
w_12864(dat,tab1[i]);
}
}
uchar get_0809()
{ uint temp=0;
st=0;
st=1;
st=0;
while(eoc==0);//等待AD转换完毕
oe=1;
// P1++;
// if(P1==256)
// P1=0;
temp=P1;
oe=0;
return(temp);
}
void adc0809_data(uint temp)
{
uchar i;
w_12864(com,0x80);
for(i=0;i<16;i++)
{
w_12864(dat,tab0[i]);
}
ftemp = temp*0.0196*44;
sprintf(dis,"%f",ftemp);//把温度值写入数组内存
w_12864(com,0x90+2);
for(i=0;i<5;i++)
w_12864(dat,dis[i]);
}
/*
void delay(uint z)
{
uint x,y;
for(x=0;x<z;x++)
for(y=0;y<120;y++);
}
*/
void time0(void) interrupt 1
{
clk=~clk;
}
void main()
{
TMOD=0x02;
TR0=1;
EA=1;
ET0=1;
TH0=0xfe;
TL0=0xfe; //500KHz
P1=0xff;
init_12864();
lcd_display();
while(1)
{
adc0809_data(get_0809());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -