2019-07-15 15:19发布
风之追逐 发表于 2015-12-22 18:23 还有你说的时钟频率:11.953022M,是烧录软件显示的值吧?我的理解你的晶振应该是12M。
最多设置5个标签!
#include <reg51.h>
void delay10ms();
void init(void);
void writecom(unsigned char com);
void writedata(unsigned char dat);
void shezhicanshu();
void senddata(unsigned char sendat);
//--¶¨ÒåÈ«¾Ö±äÁ¿--//
unsigned char code DIG_CODE[17]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//0¡¢1¡¢2¡¢3¡¢4¡¢5¡¢6¡¢7¡¢8¡¢9¡¢A¡¢b¡¢C¡¢d¡¢E¡¢FµÄÏÔʾÂë
unsigned char DisplayData[8];
sbit RS=P2^6;
sbit RW=P2^5;
sbit E=P2^7;
unsigned char code str1[16]={"PM2.5="};
unsigned char buf;
unsigned char sum;
unsigned char cal[7]={0};
int i=0;
float v0;
float PM2_5;
int pm;
//ÑÓʱ10ms
void delay10ms()
{
unsigned char a,b;
for(b=19;b>0;b--)
for(a=130;a>0;a--);
}
void init(void) //³õʼ»¯LCD1602ÆÁ
{
delay10ms();
writecom(0x38);
delay10ms();
writecom(0x38);
delay10ms();
writecom(0x38);
writecom(0x38);
writecom(0x08);
writecom(0x01);
writecom(0x06);
writecom(0x0c);
}
void writecom(unsigned char com) //дָÁî
{
E=0;
RS=0;
RW=0;
P0=com;
delay10ms();
E=1;
delay10ms();
E=0;
}
void writedata(unsigned char dat) //дÊý¾Ý
{
E=0;
RS=1;
RW=0;
P0=dat;
delay10ms();
E=1;
delay10ms();
E=0;
}
void shezhicanshu()
{
SCON=0x50;
PCON=0x00;
TMOD=0x20;
EA=1;
ES=1;
TL1=0xfd;
TH1=0xfd;
TR1=1;
}
void main()
{
int e;
init();
shezhicanshu();
while(1)
{
writecom(0x80);
for(e=0;e<6;e++)
{
writedata(str1[e]);
}
}
}
void serial() interrupt 4
{
ES = 0; //¹Ø±Õ´®ÐÐÖжÏ
RI = 0; //Çå³ý´®ÐнÓÊܱê־λ
buf = SBUF; //´Ó´®¿Ú»º³åÇøÈ¡µÃÊý¾Ý
senddata(buf);
ES = 1; //ÔÊÐí´®¿ÚÖжÏ
}
void senddata(unsigned char sendat)
{
if(sendat==170)
{
i=0;
cal=sendat;
}
else
{
i=i+1;
cal=sendat;
if(i==6)
{
sum= cal[1]+cal[2]+cal[3]+cal[4];
if(sum == cal[5] && cal[6]==255)
{
// for(i=0;i<=6;i++)
// {
// SBUF =cal;
// while(!TI);
// TI = 0;
// }
// SBUF =cal[1]; //Êä³öVout(H)
// while(!TI);
// TI = 0;
// SBUF =cal[2]; //Êä³öVout(L)
// while(!TI);
// TI = 0;
//
// //¼ÆËãpm
// v0=(cal[1]*256+cal[2])/1024*5;//¼ÆËã
// PM2_5=v0*200;
// SBUF =CMD_WARE; //Êä³öpm
// while(!TI);
// TI = 0;
// SBUF =~CMD_WARE; //Êä³öpm
// while(!TI);
// TI = 0;
pm=(int)((cal[1]*256+cal[2])/(1.024));
DisplayData[4]=DIG_CODE[(pm/1000)];
DisplayData[5]=DIG_CODE[(pm/100%10)];
DisplayData[6]=DIG_CODE[(pm/10%10)];
DisplayData[7]=DIG_CODE[(pm%10)];
pm=(int)pm;
// SBUF =pm; //Êä³öpm
// while(!TI);
// TI = 0;
// SBUF =~CMD_WARE; //Êä³öpm
// while(!TI);
// TI = 0;
// SBUF =CMD_WARE; //Êä³öpm
// while(!TI);
// TI = 0;
}
}
}
}
数码管只能显示”PM2.5=“这个,后面的是空白
如何将
DisplayData[4]=DIG_CODE[(pm/1000)];
DisplayData[5]=DIG_CODE[(pm/100%10)];
DisplayData[6]=DIG_CODE[(pm/10%10)];
DisplayData[7]=DIG_CODE[(pm%10)];
这几位数字显示在其后面
一周热门 更多>