资源简介
51单片机ADC0832电压测量液晶1602显示的C程序与proteus仿真,所有资料。
代码片段和文件信息
#include
#include
#include
/**********************************8/
/**********LCD1602接口程序**********/
#define DD P2
sbit Rs=P3^0;
sbit Rw=P3^1;
sbit E=P3^2;
sbit busy_p=ACC^7;
/********************************/
void delay_1ms(unsigned char i) //最小延时1ms
{ unsigned char j;
while(i--)
for(j=0;j<125; j++);
}
void delay_10ns(unsigned char i) //最小延时10ns
{ unsigned char j;
while(i--)
for(j=0;j<10; j++);
}
void write_com(unsigned char combit p) //写指令
{if(p)
delay_10ns(5);
E=0;
Rs=0;
Rw=0;
DD=com;
delay_10ns(50); //>40ns
E=1;
delay_1ms(2); //>150ns
E=0;
delay_10ns(4); //>25+10ns
}
void write_date(unsigned char DATA) //写数据
{
delay_10ns(50);
E=0;
Rs=1;
Rw=0;
DD=DATA;
delay_10ns(50);
E=1;
delay_10ns(50);
E=0;
delay_10ns(4);
}
void addr_x_y(unsigned char xbit y) //写坐标,定位置
{ unsigned char temp=0x80;
if(y)
{temp|=0x40;}
temp|=x;
write_com(temp0);
}
void desplay_char(unsigned char xbit yunsigned char p)
//在指定位置显示一个字符。
{ addr_x_y(xy);
write_date(p);
}
void init(void)
{delay_1ms(15);
write_com(0x380);
delay_1ms(5);
write_com(0x380);
delay_1ms(5);
write_com(0x380);
delay_1ms(5);
write_com(0x381);
write_com(0x081);
write_com(0x011);
write_com(0x061);
write_com(0x0c1);
}
void xs_int(unsigned int shujubit t) //显示一个数字
{unsigned char huancun[6]={0};
unsigned char biaozhi=0i;
if (shuju < 10) biaozhi = 1;
else if(shuju < 100) biaozhi = 2;
else if(shuju < 1000) biaozhi = 3;
else if(shuju < 10000) biaozhi = 4;
else if(shuju < 65535) biaozhi = 5;
switch(biaozhi)
{case 5:huancun[5] = shuju/10000;
case 4:huancun[3] = shuju%10000/1000;
case 3:huancun[2] = shuju%1000/100;
case 2:huancun[1] = shuju%100/10;
case 1:huancun[0] = shuju%10;
break;
default:break;
}
for(i=6;i>1;i--)
{if(i==5)desplay_char(101‘.‘);
else desplay_char(15-it0x30+huancun[i-1]); }
desplay_char(15t‘V‘);
}
/************************************************************/
/**********ADC0832接口程序************************************/
sbit ADC_CS =P3^4;
sbit ADC_CLK=P3^5;
sbit ADC_DO =P3^6;
sbit ADC_DI =P3^7;
/*******************************************************************/
void Delay(unsigned char j)
{
unsigned char i;
for(i=0;i
}
unsigned char ADC0832(void) //把模拟电压值转换成8位二进制数并返回
{
unsigned char idata_c;
data_c=0;
ADC_CS=0;
ADC_DO=0;//片选,DO为高阻态
for(i=0;i<10;i++)
{;}
ADC_CLK=0;
Delay(2);
ADC_DI=1;
ADC_CLK=1;
Delay(2); //第一个脉冲,起始位
ADC_CLK=0;
Delay(2);
ADC_DI=1;
ADC_CLK=1;
Delay(2); //第二个脉冲,DI=1表示双通道单极性输入
ADC_CLK=0;
Delay(2);
ADC_DI=1;
ADC_CLK=1;
Delay(2); //第三个脉冲,DI=1表示选择通道1(CH2)
ADC_DI=0;
ADC_DO=1;//DI转为高阻态,DO脱离高阻态为输出数据作准备
ADC_CLK=1;
Delay(2);
ADC_CLK=0;
Delay(2);//经实验,这里加一个脉冲AD便能正确读出数据,
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4273 2010-06-16 22:25 ADC0832\ADC0832
文件 3638 2010-06-16 23:03 ADC0832\ADC0832.c
文件 3020 2010-06-16 22:25 ADC0832\ADC0832.hex
文件 31 2010-06-16 22:25 ADC0832\ADC0832.lnp
文件 7896 2010-06-16 22:25 ADC0832\ADC0832.LST
文件 15794 2010-06-16 22:25 ADC0832\ADC0832.M51
文件 5829 2010-06-16 22:25 ADC0832\ADC0832.OBJ
文件 1116 2010-06-16 23:03 ADC0832\ADC0832.Opt
文件 7933 2010-06-16 22:25 ADC0832\ADC0832.plg
文件 1659 2010-06-16 23:03 ADC0832\ADC0832.Uv2
....... 960 2010-06-16 22:25 ADC0832\ADC0832_Opt.Bak
....... 1659 2010-06-16 22:25 ADC0832\ADC0832_Uv2.Bak
文件 243682 2010-06-16 22:35 ADC0832\ADC0832_仿真.JPG
文件 2246 2010-06-16 20:11 ADC0832\LED.h
目录 0 2010-06-16 23:03 ADC0832
----------- --------- ---------- ----- ----
299736 15
评论
共有 条评论