欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
這個單片機程序錯誤如何修改?128行K1num顯示錯誤
[打印本頁]
作者:
ovov
時間:
2020-4-25 22:29
標題:
這個單片機程序錯誤如何修改?128行K1num顯示錯誤
#include<reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit CS=P1^0;
sbit CLK=P1^2;
sbit DO=P1^1;
sbit Wat=P1^3;
sbit k1=P3^5;
sbit k2=P3^6;
sbit k3=P3^7;
sbit lcd_rw=P2^2;
sbit lcd_rs=P2^0;
sbit lcd_e=P2^1;
uchar adat; //讀出1302的數據
uint k1n;
uchar shiduH=70,shiduL=20; //濕度的上下限
void delay(uint time)
{
uint i,j;
for(i=0;i<time;i++)
for(j=0;j<100;j++);
}
uchar adc0832()
{
uchar i,temp,temp1,num;
CLK=0; DO=1;CS=0; CLK=1;
CLK=0; DO=1; CLK=1;
CLK=0; DO=0; CLK=1;
CLK=0; DO=1;
for(i=0;i<8;i++)
{
CLK=1;
CLK=0;
temp<<=1;
if(DO)temp++;
}
for(i=0;i<8;i++)
{
temp1>>=1;
if(DO)temp1+=0x80;
CLK=1;
CLK=0;
}
CLK=1;DO=1;
CS=1;
if(temp==temp1) num=100-temp*99/255; // adat=100-adat*99/255;
return num;
}
void Read_Busy() //忙檢測函數,判斷bit7是0,允許執行;1禁止
{
unsigned char sta; //
P0 = 0xff;
lcd_rs= 0;
lcd_rw = 1;
do
{
lcd_e= 1;
sta = P0;
lcd_e = 0; //使能,用完就拉低,釋放總線
}
while(sta & 0x80);
}
void Lcd1602_Write_Cmd(uchar cmd) //寫命令
{
Read_Busy();
lcd_rs = 0;
lcd_rw = 0;
P0= cmd;
lcd_e = 1;
lcd_e = 0;
}
void Lcd1602_Write_Data(uchar dat) //寫數據
{
Read_Busy();
lcd_rs = 1;
lcd_rw = 0;
P0 = dat;
lcd_e = 1;
lcd_e = 0;
}
void init_lcd()
{
uchar code D[]="RH: ";
uchar code T[]="RL: "; //顯示濕度下限
uchar code S[]="ShiDu: ";
uchar i;
Lcd1602_Write_Cmd(0x38); //打開,5*8,8位數據
Lcd1602_Write_Cmd(0x0c);
Lcd1602_Write_Cmd(0x06);
Lcd1602_Write_Cmd(0x01); //清屏
Lcd1602_Write_Cmd(0x80);
for(i=0;i<5;i++)
{
Lcd1602_Write_Data(D[ i]);
delay(5);
}
Lcd1602_Write_Cmd(0x87);
for(i=0;i<8;i++)
{
Lcd1602_Write_Data(S);
delay(5);
}
Lcd1602_Write_Cmd(0x80+0x40);
for(i=0;i<5;i++)
{
Lcd1602_Write_Data(T);
delay(5);
}
}
void key0()
{
if(k1==0)
{
delay(5);
if(k1==0)
{
while(!k1);
TR0=0;
Wat=1;
Lcd1602_Write_Cmd(0x0f);
k1n++;
if(k1n==4)
{
TR0=1;
k1num=0;
Lcd1602_Write_Cmd(0x0c);
Lcd1602_Write_Cmd(0x80+0x4a) ;
Lcd1602_Write_Data(0x10);
Lcd1602_Write_Data(0x10);
Lcd1602_Write_Data(0x10);
}
}
}
}
void key1()
{
if(k1n==1)
{
Lcd1602_Write_Cmd(0x84);
if(k2==0)
{
delay(5);
if(k2==0)
{
while(!k2);
shiduH++;
if(shiduH>99)shiduH=99;
Lcd1602_Write_Cmd(0x83);
Lcd1602_Write_Data(0x30+shiduH/10);
Lcd1602_Write_Data(0x30+shiduH%10);
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
while(!k3);
shiduH--;
if(shiduH<=shiduL)shiduH=shiduL+1;
Lcd1602_Write_Cmd(0x83);
Lcd1602_Write_Data(0x30+shiduH/10);
Lcd1602_Write_Data(0x30+shiduH%10);
}
}
Lcd1602_Write_Cmd(0x84);
}
if(k1n==2)
{
Lcd1602_Write_Cmd(0x80+0x44);
if(k2==0)
{
delay(5);
if(k2==0)
{
while(!k2);
shiduL++;
if(shiduL>shiduH)shiduL=shiduH-1;
Lcd1602_Write_Cmd(0x80+0x43);
Lcd1602_Write_Data(0x30+shiduL/10);
Lcd1602_Write_Data(0x30+shiduL%10);
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
while(!k3);
shiduL--;
if(shiduL<=1)shiduL=1;
Lcd1602_Write_Cmd(0x80+0x43);
Lcd1602_Write_Data(0x30+shiduL/10);
Lcd1602_Write_Data(0x30+shiduL%10);
}
}
Lcd1602_Write_Cmd(0x80+0x44);
}
if(k1n==3)
{
Lcd1602_Write_Cmd(0x80+0x4a) ;
Lcd1602_Write_Data(0x3e);
Lcd1602_Write_Data(0x3e);
Lcd1602_Write_Data(0x3e);
Lcd1602_Write_Cmd(0x0c) ;
if(k2==0)
{
delay(5);
if(k2==0)
{
while(!k2);
Wat=0;
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
while(!k3);
Wat=1;
}
}
}
}
void water()
{
if(adat<shiduL) TR0=1;
if(adat>shiduH)
{
TR0=0;
Wat=1;
}
}
void disp0()
{
adat=adc0832();
Lcd1602_Write_Cmd(0x83);
Lcd1602_Write_Data(0x30+shiduH/10);
Lcd1602_Write_Data(0x30+shiduH%10);
Lcd1602_Write_Cmd(0x8D);
Lcd1602_Write_Data(0x30+adat/10);
Lcd1602_Write_Data(0x30+adat%10);
Lcd1602_Write_Cmd(0x80+0x43);
Lcd1602_Write_Data(0x30+shiduL/10);
Lcd1602_Write_Data(0x30+shiduL%10);
}
void main()
{
TMOD=0x01;
TH0=(65536-50000)/256; //初值50ms
TL0=(65536-50000)%256;
EA=1; //開總中斷
ET0=1; //開定時器0中斷
// TR0=1; //啟動定時器0
k1n=0;
init_lcd();
while(1)
{
key0();
if(k1n==0)
{
adat=adc0832();
water();
disp0();
}
if(k1n!=0)
{
key1();
}
}
}
void t0()interrupt 1
{
uchar count;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count>0&&count<=60)
{
Wat=0;
}
if(count>60&&count<=120)
{
if(count==120)count=0;
Wat=1;
}
}
復制代碼
作者:
wulin
時間:
2020-4-26 06:05
k1num這個變量沒有定義,根據上下文判斷應該是樓主筆誤把k1n寫成k1num。
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1