基于8950单片机和PCF8591转换器和LCD显示屏的实现代码问题
想把这里面的报警部分去掉和大概功能就是通过改变电压大小再通过A/D转换器把电压信号传到单片机再传到LCD显示屏(程序部分我不太明白)求大神帮忙,再有一个星期就要答辩了!就差程序实现!
下面是我在网上找的一个代码:
include"reg51.h"
include<intrins.h>
define DD P2
sbit CS=P1^0;
sbit CLK=P1^1;
sbit Do=P1^2;
sbit Di=P1^3;
sbit KEY=P1^7;
sbit buzzer=P0^0;
sbit Rs=P1^4;
sbit Rw=P1^5;
sbit E=P1^6;
sbit busy_p=ACC^7;
unsigned char CH=0x02,key_count=1;
unsigned char HC[6]={0};
unsigned char BZ=0;
void delay_1ms(unsigned char i)
{
unsigned char j;
while(i--)
for(j=0;j<125; j++);
}
void delay_10ns(unsigned char i)
{
unsigned char j;
while(i--)
for(j=0;j<10; j++);
}
void xiezhiling(unsigned char com,bit p)
{
if(p)
delay_10ns(5);
E=0;
Rs=0;
Rw=0;
DD=com;
delay_10ns(50);
E=1;
delay_1ms(2);
E=0;
delay_10ns(4);
}
void xieshuju(unsigned char DATA)
{
delay_10ns(50);
E=0;
Rs=1;
Rw=0;
DD=DATA;
delay_10ns(50);
E=1; 39
delay_10ns(50);
E=0;
delay_10ns(4);
}
void init(void)
{
delay_1ms(15);
xiezhiling(0x38,0);
delay_1ms(5);
xiezhiling(0x38,0);
delay_1ms(5);
xiezhiling(0x38,0);
delay_1ms(5);
xiezhiling(0x38,1);
xiezhiling(0x08,1);
xiezhiling(0x01,1);
xiezhiling(0x06,1);
xiezhiling(0x0c,1);
}
unsigned char ADconv(void)
{
unsigned char i;
unsigned intdata_f=0,data_c=0;
Di=1;
CS=1;
_nop_();
CS=0;
Di=1; ;
CLK=1;
_nop_();
_nop_();
CLK=0;
_nop_();
_nop_();
CLK=1;
Di=(bit)(0x02&CH);
_nop_();
CLK=0;
_nop_();
_nop_();
CLK=1;
Di=(bit)(0x01&CH);
_nop_();
_nop_();
CLK=0;
Di=1;
CLK=1;
_nop_();
_nop_();
CLK=0;
_nop_();
CLK=1;
for(i=8;i>0;i--)
{
data_f|=Do;
data_f<<=1;
CLK=1;
_nop_();
_nop_();
CLK=0;
_nop_();
}
for(i=8;i>0;i--)
{
data_c<<=1;
data_c|=Do;
_nop_();
CLK=1;
_nop_();
_nop_();
CLK=0;
_nop_();
}
CLK=0;
_nop_();
_nop_();
CLK=1;
_nop_();
_nop_();
CLK=0;
_nop_();
_nop_();
CLK=1;
_nop_();
CS=1;
_nop_();
_nop_();
return daa_f;
}
void xs_int(unsigned int shuju)
{
if(shuju < 10)
BZ = 1;
else if(shuju < 100) BZ =2;
else if(shuju < 1000) BZ =3;
else if(shuju < 10000) BZ= 4;
else if(shuju < 65535) BZ= 5;
switch(BZ)
{
case 5:HC[5] = shuju/10000;
case 4:HC[3] =shuju%10000/1000;
case 3:HC[2] =shuju%1000/100;
case 2:HC[1] =shuju%100/10;
case 1:HC[0] = shuju%10;
break;
default:break;
}
}
void main(void)
{
unsigned int data_temp=0;
init();
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
while(1)
{
data_temp=ADconv();
if(data_temp>128)
{
EA=1;
}
else
{
EA=0;
buzzer=0;
}
P3=~data_temp;
xs_int(196*data_temp);
if(KEY==0)
{
delay_1ms(10);
if(KEY==0)
while(!KEY);
key_count++;
if(key_count==3)
key_count=1;
xiezhiling(0x01,0);
}
if(key_count==1)
{
xiezhiling(0x80,1);
xieshuju('P');
xieshuju('R);
xieshuju('E');
xieshuju('S);
xieshuju('S');
xieshuju('U');
xieshuju('R);
xieshuju('E');
xieshuju('-');
xieshuju(HC[5]+0x30);
xieshuju(HC[3]+0x30);
xieshuju(HC[2]+0x30);
xieshuju('.');
xieshuju(HC[1]+0x30);
xieshuju('P');
xieshuju('a');
xiezhiling(0x80+0x40,1);
xieshuju('A');
xieshuju('l');
xieshuju('a');
xieshuju('r');
xieshuju('m');
xieshuju(' ');
xieshuju('S');
xieshuju('t');
xieshuju('a');
xieshuju('t');
xieshuju('u');
xieshuju('s');
xieshuju('-');
xieshuju('-');
xieshuju('O');
xieshuju('N');
}
if(key_count==2)
{
xiezhiling(0x80,1);
xieshuju('P');
xieshuju('r');
xieshuju('e');
xieshuju('s');
xieshuju('s');
xieshuju('u');
xieshuju('r');
xieshuju('e');
xieshuju(' ');
xieshuju('i');
xieshuju('s');
xieshuju(' ');
xieshuju('O');
xieshuju('K');
xieshuju(' ');
xieshuju(' ');
xiezhiling(0x80+0x40,1);
xieshuju('m ');
xieshuju('a');
xieshuju('d');
xieshuju('e');
xieshuju(' ');
xieshuju('B');
xieshuju('Y');
xieshuju(' ');
xieshuju('y');
xieshuju('u');
xieshuju('a');
xieshuju('n');
xieshuju('s');
xieshuju('h');
xieshuju('u');
xieshuju('o');
xieshuju(' ');
}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
buzzer=!buzzer;}
PCF8591是用来AD采集还有一路DA。你又加了显示模块,你的毕业设计具体做什么的。PCF591小弟我N年前就用烂了