#include<reg52.h>
/*--------------------------------------------------------------------------------------------------------------------
-----------------±äÁ¿¶¨Òå----------------------
-------------------------------------------------------------------------------------------------------------------*/
#define uchar unsigned char
#define uint unsigned int
sbit key1=P1^0; //¶Ë¿Ú¶¨Òå,Ñ¡Ôñ¹â±êÔÚ¸öλ»òʮλ
sbit key2=P1^1; //¹â±ê´¦µçѹΪ1Êä³ö
sbit key3=P1^2; //¹â±ê´¦µçѹΪ2Êä³ö
sbit key4=P1^3; //È·¶¨Êä³öµçѹ
sbit key03=P2^0; //¹â±ê´¦µçѹΪ3Êä³ö
sbit key04=P2^1; //¹â±ê´¦µçѹΪ4Êä³ö
sbit key05=P2^2;
sbit key06=P2^3;
sbit key07=P2^4;
sbit key08=P2^5;
sbit key09=P2^6; //¹â±ê´¦µçѹΪ9Êä³ö
sbit rs=P1^4;
sbit en=P1^5;
sbit DAC_CS=P3^2;
sbit DAC_WR=P3^6;
sbit ADC_CS=P0^0;
sbit ADC_DI=P0^1;
sbit ADC_DO=P0^2;
uchar code table1[]=" liu do"; //³õʼ»¯ÏÔʾ
uchar code table2[]=" dianya :0.0V "; //³õʼ»¯µçÔ´
uchar s1,s2,keynum,volt;
/*--------------------------------------------------------------------------------------------------------------------
º¯ÊýÈ«³Æ: void delay(uint z)
º¯Êý¹¦ÄÜ: ÑÓʱº¯Êý £¨ºÁÃ뼶£©
Êä È룺unit z
·µ »Ø£º
µ÷Óú¯Êý:
×¢ÒâÊÂÏ
Ìáʾ˵Ã÷£º
-------------------------------------------------------------------------------------------------------------------*/
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
/*--------------------------------------------------------------------------------------------------------------------
º¯ÊýÈ«³Æ: void write_com()
º¯Êý¹¦ÄÜ: дָÁîµ½LCD1602
Êä È룺uchar com
·µ »Ø£º
µ÷Óú¯Êý:
×¢ÒâÊÂÏ
Ìáʾ˵Ã÷£º
-------------------------------------------------------------------------------------------------------------------*/
void write_com(uchar com)
{
rs=0;
en=0;
P0=com;
delay(5);
en=1;
delay(5);
en=0;
}
/*--------------------------------------------------------------------------------------------------------------------
º¯ÊýÈ«³Æ: void write_date()
º¯Êý¹¦ÄÜ: дÊý¾Ýµ½LCD1602
Êä È룺uchar data
·µ »Ø£ºÎÞ
µ÷Óú¯Êý: ÎÞ
×¢ÒâÊÂÏ
Ìáʾ˵Ã÷£º
-------------------------------------------------------------------------------------------------------------------*/
void write_date(uchar date)
{
rs=1;
en=0;
P0=date;
delay(5);
en=1;
delay(5);
en=0;
}
/*--------------------------------------------------------------------------------------------------------------------
º¯ÊýÈ«³Æ: void write_date()
º¯Êý¹¦ÄÜ: lCD1602³õʼ»¯×Ó³ÌÐò
Êä È룺ÎÞ
·µ »Ø£ºÎÞ
µ÷Óú¯Êý: ÎÞ
×¢ÒâÊÂÏ
Ìáʾ˵Ã÷£º
-------------------------------------------------------------------------------------------------------------------*/
void Init()
{
uchar num;
en=0;
write_com(0x38); //ÖõØÖ·
write_com(0x0c);
write_com(0x06); //¹â±êÓÒÒÆ
write_com(0x01); //ÇåÏÔʾ
write_com(0x80); //lcd DDRAMÉèÖÃ
for(num=0;num<16;num++)
{
write_date(table1[num]);
delay(50);
}
write_com(0x80+0x40); //lcdµÚ¶þÐÐ
for(num=0;num<14;num++)
{
write_date(table2[num]);
delay(50);
}
}
/*--------------------------------------------------------------------------------------------------------------------
º¯ÊýÈ«³Æ: void write_voltage()
º¯Êý¹¦ÄÜ: дµçѹµ½lCD1602
Êä È룺uchar add,uchar dat
·µ »Ø£ºÎÞ
µ÷Óú¯Êý: ÎÞ
×¢ÒâÊÂÏ
Ìáʾ˵Ã÷£º
-------------------------------------------------------------------------------------------------------------------*/
void write_voltage(uchar add,uchar dat)
{
write_com(0x80+0x40+add); //È·¶¨µÚ¶þÐÐλÖÃ
write_date(0x30+dat); //дÊý¾Ý
}
/*--------------------------------------------------------------------------------------------------------------------
º¯ÊýÈ«³Æ: void DA0832out()
º¯Êý¹¦ÄÜ: дµçѹÊý¾Ýµ½DAC0832
Êä Èë:char dadata
·µ »Ø£ºÎÞ
µ÷Óú¯Êý: ÎÞ
×¢ÒâÊÂÏ
Ìáʾ˵Ã÷£º
-------------------------------------------------------------------------------------------------------------------*/
void DA0832out(uchar dadata)
{
DAC_CS=0;
P0=dadata;
DAC_WR=0;
delay(5);
DAC_WR=1;
DAC_CS=1;
}
/*--------------------------------------------------------------------------------------------------------------------
º¯ÊýÈ«³Æ: void AD0832out()
º¯Êý¹¦ÄÜ: дµçѹÊý¾Ýµ½ADC0832
Êä Èë:char dadata
·µ »Ø£ºÎÞ
µ÷Óú¯Êý: ÎÞ
×¢ÒâÊÂÏ
Ìáʾ˵Ã÷£º
-------------------------------------------------------------------------------------------------------------------*/
void AD0832out(uchar dadata)
{
ADC_CS=0;
P0=dadata;
ADC_DI=0;
delay(5);
ADC_DO=1;
ADC_CS=1;
}
/*--------------------------------------------------------------------------------------------------------------------
º¯ÊýÈ«³Æ: void keyscan()
º¯Êý¹¦ÄÜ: ¼üÅÌɨÃè×Ó³ÌÐò
Êä Èë:char dadata
·µ »Ø£ºÎÞ
µ÷Óú¯Êý:write_com();write_voltage(); Da0832out();
×¢ÒâÊÂÏ
Ìáʾ˵Ã÷£º
-------------------------------------------------------------------------------------------------------------------*/
void keyscan()
{
if(key1==0)
{
delay(5);
if(key1==0)
{
keynum++;
while(!key1); //°´×¡ÖÃÒ»Ö±µ½·ÅÊÖ
if(keynum==1) //µÈÓÚ 1
{
write_com(0x80+0x40+12);
write_com(0x0f); //ÖÃÊý¾ÝÏÔʾµØÖ·
}
}
if(keynum==2) //deng=2,ce jia 1
{
write_com(0x80+0x40+10); //ÖÃÊý¾ÝÏÔʾµØÖ·
write_com(0x0f);
}
if(keynum==3) //ÈôµÈÓÚ 3,
{
keynum=0;
write_com(0x0c); //²âÎ޹رê
}
}
if(keynum!=0)
{
if(key2==0)
{
delay(5);
if(key2==0)
{
while(!key2);
if(keynum==1)
{