set_gz))
{
//亮处接近暗********************************/
if(ad_data2-set_gz>10)
{
if(renshu>0)
{
LED_1=1;
LED_2=0;
LED_3=0;
}
else
{
LED_1=0;
LED_2=0;
LED_3=0;
}
}
//暗处没有接近暗时******************************/
else
{
if(renshu>0 & renshu<=4)
{
LED_1=1;
LED_2=0;
LED_3=0;
}
else
{
if(renshu>4 & renshu<=8)
{
LED_1=1;
LED_2=1;
LED_3=0;
}
else
{
if(renshu>8 & renshu<=12)
{
LED_1=1;
LED_2=1;
LED_3=1;
}
else
{
LED_1=0;
LED_2=0;
LED_3=0;
}
}
}
}
}
if((ad_data1>set_gz) & (ad_data2>set_gz))
{
LED_1=0;
LED_2=0;
LED_3=0;
}
}
else
{
if(QK_QG==0)
{
LED_1=0;
LED_2=0;
LED_3=0;
}
else
{
LED_1=1;
LED_2=1;
LED_3=1;
}
}
}
//;***************************************************************
void ext1(void) interrupt 2
{
if(KEY1==0)
{
delay(10);
if(KEY1==0)
{
if(renshu==255)
{
baojing=1;
renshu=255;
}
else
{
baojing=0;
renshu++;
}
}
}
if(KEY2==0)
{
delay(10);
if(KEY2==0)
{
if(renshu==0)
{
renshu=0;
baojing=1;
}
else
{
renshu--;
baojing=0;
}
}
}
if(KEY3==0)
{
delay(10);
if(KEY3==0)
{
if(QK_QG==0)
QK_QG=1;
else
QK_QG=0;
}
}
if(KEY4==0)
{
delay(10);
if(KEY4==0)
{
if(A_M==0)
A_M=1;
else
A_M=0;
}
}
}
void write_com(uchar com)
{
P2=0xFF;
delay(5);
RS=0;
LCD_EN=0;
P2=com;
delay(5);
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void write_date(uchar dis_data)
{
P0=0xFF;
delay(5);
RS=1;
LCD_EN=0;
P2=dis_data;
delay(5);
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void lcd_init()
{
P0=0xFF;
delay(5);
P0=0x00;
LCD_EN=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
//;***************************************************************
void lcd_dis()
{
uchar num;
uchar bai,shi,ge;
bai=renshu/100;
shi=renshu%100/10;
ge=renshu%10;
//第一行显示
write_com(0x80);
for(num=0;num<7;num++)
{
write_date(table[num]);
}
write_date(bai+0x30);
write_date(shi+0x30);
write_date(ge+0x30);
//第二行显示
write_com(0xc0);
//;;LED1*************************************************
for(num=0;num<3;num++)
{
write_date(table1[num]);
}
if(LED_1==0)
write_date('C');
else
write_date('O');
write_date(' ');
//; ;LED2*****************************************************
for(num=0;num<3;num++)
{
write_date(table2[num]);
}
if(LED_2==0)
write_date('C');
else
write_date('O');
write_date(' ');
//; ;LED3*******************************************************************
for(num=0;num<3;num++)
{
write_date(table3[num]);
}
if(LED_3==0)
write_date('C');
else
write_date('O');
}
//;**************************************************************************
void main()
{
lcd_init();
EA=1;
EX0=1;
EX1=1;
IT0=1;
IT1=1;
while(1)
{
adc_0809();
kongzhi();
lcd_dis();
}
}
程序:
#include
#include
#define uchar unsigned char
#define uint unsigned int
***it RS=P2^0;
***it LCD_EN=P2^1;
***it EOC=P3^2;
***it ADDR=P2^5;
***it baojing=P2^6;
***it ST=P2^7;
bit flag=0;
***it LED_1=P2^2;
***it LED_2=P2^3;
***it LED_3=P2^4;
***it KEY1=P3^4;
***it KEY2=P3^5;
***it KEY3=P3^6;
***it KEY4=P3^7;
bit A_M;
bit QK_QG;
uchar renshu;
uchar set_gz=0x78;
uchar ad_data1,ad_data2;
uchar bai_1,shi_1,ge_1,bai_2,shi_2,ge_2;
uchar code table[]="renshu:";
uchar code table1[]="D1:";
uchar code table2[]="D2:";
uchar code table3[]="D3:";
//;**********************************************************************
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=1;y>0;y--);
}
//;***********************************************************************
void adc_0809()
{
EA=0;
if(flag==0)
ADDR=0;
else
ADDR=1;
ST=0;
ST=1;
ST=0;
delay(10);
EA=1;
}
void ext0(void) interrupt 0
{
if(flag==0)
{
flag=1;
ad_data1=P1;
bai_1=ad_data1/100;
shi_1=(ad_data1%100)/10;
ge_1=ad_data1%10;
}
else
{
flag=0;
ad_data2=P1;
bai_2=ad_data2/100;
shi_2=(ad_data2%100)/10;
ge_2=ad_data2%10;
}
}
//;******************************************************************
void kongzhi()
{
if(A_M==0)
{
if(((ad_data1
{
if(renshu>0 & renshu<=4)
{
LED_1=1;
LED_2=0;
LED_3=0;
}
else
if(renshu>4 & renshu<=8)
{
LED_1=1;
LED_2=1;
LED_3=0;
}
else
{
if(renshu>8 & renshu<=12)
{
LED_1=1;
LED_2=1;
LED_3=1;
}
else
{
LED_1=0;
LED_2=0;
LED_3=0;
}
}
}
if((ad_data1set_gz))
{
//亮处接近暗********************************/
if(ad_data2-set_gz>10)
{
if(renshu>0)
{
LED_1=1;
LED_2=0;
LED_3=0;
}
else
{
LED_1=0;
LED_2=0;
LED_3=0;
}
}
//暗处没有接近暗时******************************/
else
{
if(renshu>0 & renshu<=4)
{
LED_1=1;
LED_2=0;
LED_3=0;
}
else
{
if(renshu>4 & renshu<=8)
{
LED_1=1;
LED_2=1;
LED_3=0;
}
else
{
if(renshu>8 & renshu<=12)
{
LED_1=1;
LED_2=1;
LED_3=1;
}
else
{
LED_1=0;
LED_2=0;
LED_3=0;
}
}
}
}
}
if((ad_data1>set_gz) & (ad_data2>set_gz))
{
LED_1=0;
LED_2=0;
LED_3=0;
}
}
else
{
if(QK_QG==0)
{
LED_1=0;
LED_2=0;
LED_3=0;
}
else
{
LED_1=1;
LED_2=1;
LED_3=1;
}
}
}
//;***************************************************************
void ext1(void) interrupt 2
{
if(KEY1==0)
{
delay(10);
if(KEY1==0)
{
if(renshu==255)
{
baojing=1;
renshu=255;
}
else
{
baojing=0;
renshu++;
}
}
}
if(KEY2==0)
{
delay(10);
if(KEY2==0)
{
if(renshu==0)
{
renshu=0;
baojing=1;
}
else
{
renshu--;
baojing=0;
}
}
}
if(KEY3==0)
{
delay(10);
if(KEY3==0)
{
if(QK_QG==0)
QK_QG=1;
else
QK_QG=0;
}
}
if(KEY4==0)
{
delay(10);
if(KEY4==0)
{
if(A_M==0)
A_M=1;
else
A_M=0;
}
}
}
void write_com(uchar com)
{
P2=0xFF;
delay(5);
RS=0;
LCD_EN=0;
P2=com;
delay(5);
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void write_date(uchar dis_data)
{
P0=0xFF;
delay(5);
RS=1;
LCD_EN=0;
P2=dis_data;
delay(5);
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void lcd_init()
{
P0=0xFF;
delay(5);
P0=0x00;
LCD_EN=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
//;***************************************************************
void lcd_dis()
{
uchar num;
uchar bai,shi,ge;
bai=renshu/100;
shi=renshu%100/10;
ge=renshu%10;
//第一行显示
write_com(0x80);
for(num=0;num<7;num++)
{
write_date(table[num]);
}
write_date(bai+0x30);
write_date(shi+0x30);
write_date(ge+0x30);
//第二行显示
write_com(0xc0);
//;;LED1*************************************************
for(num=0;num<3;num++)
{
write_date(table1[num]);
}
if(LED_1==0)
write_date('C');
else
write_date('O');
write_date(' ');
//; ;LED2*****************************************************
for(num=0;num<3;num++)
{
write_date(table2[num]);
}
if(LED_2==0)
write_date('C');
else
write_date('O');
write_date(' ');
//; ;LED3*******************************************************************
for(num=0;num<3;num++)
{
write_date(table3[num]);
}
if(LED_3==0)
write_date('C');
else
write_date('O');
}
//;**************************************************************************
void main()
{
lcd_init();
EA=1;
EX0=1;
EX1=1;
IT0=1;
IT1=1;
while(1)
{
adc_0809();
kongzhi();
lcd_dis();
}
}
举报