帮忙解读一下这个C程序,用单片机做电压表的

来源:百度知道 编辑:UC知道 时间:2024/05/26 11:26:03
#include <reg52.h>
unsigned char code dispbitcode[]={0xfe,0xfd,0xfb,0xf};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x00};
unsigned char dispbuf[8]={10,10,10,10,0,0,0,0};
unsigned char dispcount;
unsigned char getdata;
unsigned int temp;
unsigned char i;
sbit ST=P3^0;
sbit OE=P3^1;
sbit EOC=P3^2;
sbit CLK=P3^3;
void main(void)
{
ST=0;
OE=0;
ET0=1;
ET1=1;
EA=1;
TMOD=0x12;
TH0=216;
TL0=216;
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
TR1=1;
TR0=1;
ST=1;
ST=0;
while(1)
{
if(EOC==1)
{
OE=1;
getdata=P0;
OE=0;
temp=getdata*235;
temp=temp/128;
i=5;
dispbuf[0]=10;

temp=getdata*235;
temp=temp/128;
应该是修正数值所用的, x = x*235/128 = x * 1.8359375;
如果AD的参考电压为 1.089V (2V/(235/128))的话,
那乘上的因子可以使得

x 电压值
0 -- 0V
255 -- 2V

dispbuf[0]=10;等内容对应的是显示缓存数据的初始化,相应的值必须结合硬件连接电路图才可以确定是初始化为什么样的显示字形...