《lcd带温度显示万年历》

下载本书

添加书签

lcd带温度显示万年历- 第1部分


按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!

标签:1  
 #include 
#include 

#define uchar unsigned char
#define uint unsigned int
#define LCD_Data  P2
#define Busy     0x80 //用于检测LCD状态字中的Busy标识

sbit DQ = P1^3;
sbit lcdrs  =  P3^5;   //数据命令选择端 (H/L)
sbit lcdrw  =  P3^6;   //读写选择端 (H/L)
sbit lcde   =  P3^7;   //使能信号
sbit SCL2=P1^0;  //SCL2定义为P1口的第3位脚,连接DS1302SCL和ADC0831SCL脚
sbit SDA2=P1^1;  //SDA2定义为P1口的第4位脚,连接DS1302SCL和ADC0831SDA脚
sbit RST = P1^2;   // DS1302片选脚
sbit key0   =  P0^0; //定义三个按键
sbit key1   =  P0^1;    //加按键
sbit key2   =  P0^2;    //减按键
sbit H1     =  P0^3;
sbit L=P0^4;
bit presence  ;
uchar code  cdis2' ' = {〃  。  C 〃} ;

uchar buzyc;funtion_flag=0;temp_num;
char shi;fen;miao;nian;yue;ri;xin;
uchar beep;
unsigned char data  temp_data'2' = {0x00;0x00} ;
unsigned char data  display'5' =   {0x00;0x00;0x00;0x00;0x00} ;
unsigned char code  ditab'16' =    {0x00;0x01;0x01;0x02;0x03;0x03;0x04;0x04;
                                                        0x05;0x06;0x06;0x07;0x08;0x08;0x09;0x09} ;
unsigned char code  mytab'8' = {0x0C;0x12;0x12;0x0C;0x00;0x00;0x00;0x00} ;

unsigned char l_tmpdate'8'={0x00;59;12;19;2;8;2};//显示初值
unsigned char l_tmpdisplay'8'={0x40;0x40;0x40;0x40;0x40;0x40;0x40;0};//待显示的数
code unsigned char write_rtc_address'7'={0x80;0x82;0x84;0x86;0x88;0x8c;0x8a}; //1302写入地址
code unsigned char read_rtc_address'7'={0x81;0x83;0x85;0x87;0x89;0x8d;0x8b};//1302读出地址
code unsigned char table''= {0x3f;0x06;0x5b;0x4f;0x66;0x6d;0x7d;0x07;0x7f;0x6f;0x40;0x00};//共阴数码管 0…9  '…' '熄灭‘表
uchar date1''=〃MON〃;
uchar date2''=〃TUE〃;
uchar date3''=〃WED〃;
uchar date4''=〃THU〃;
uchar date5''=〃FRI〃;
uchar date6''=〃SAT〃;
uchar date7''=〃SUN〃;   
 #define delayNOP() ; {_nop_() ;_nop_() ;_nop_() ;_nop_() ;} ; 

 


 
 
/*****************************************************************************************************
字节写入子函数:
  将要写入的数字先右移一位,是最低位溢出,然后在scl2的一个上升沿数据被写入DS1302;注意
  数据的写入时从低位到高位
*****************************************************************************************************/

void Write_Ds1302_Byte(unsigned  char date) 

 uchar j;temp;
 temp=date;
 for(j=0;j》1; //将数据右移一位使最低位溢出
  SDA2=CY; //将待写入数据最低位写入数据缓冲
  SCL2=0;
  SCL2=1;  //在scl的上升延写入数据
 }
}  


/*****************************************************************************************************
字节读出子函数:
   分8次读出数据,将读出的数据存入temp:在时钟信号的下降沿读出一个字节的数据
   数据读出也是从低位到高位的
*****************************************************************************************************/
uchar Read_Ds1302_Byte()

 uchar j;temp;
 for(j=0;j》1; //将temp右移一位使最高位变为次高位,最高为为0
  SDA2=1;
  SCL2=1;
  SCL2=0; //在scl2的一个下降沿数据读出
  if(SDA21)//如果读出的数据为1,即在temp的最高位写入1,为0的时候则写入0
  temp=temp|0x80;
  temp=temp|0x00;  
 }
 return temp;



/***************************************************************************************************************
数据写入DS1302函数:
   在指定地址写入指定数据,在rst为低scl2为低的情况下将rst置高,即允许数据写入
   先写入地址
   然后写入数据
   最后将rst拉低结束数据写入
****************************************************************************************************************/
void Write_Ds1302( unsigned char address;unsigned char dat )     

  RST=0;
 _nop_();_nop_();_nop_();_nop_();_nop_();
 SCL2=0;
 _nop_();_nop_();_nop_();_nop_();_nop_();
  RST=1; 
    _nop_();_nop_();_nop_();_nop_();_nop_();   //开启,写入数据地址,这是本串口协议的开始,加入延时防止干扰
  Write_Ds1302_Byte(address); //发送地址
  Write_Ds1302_Byte(dat);  //发送数据
  RST=0;    //恢复



/************************************************************************************************************
从指定地址读取数据子函数:
                   在rst为低scl2为低的情况下将rst置高,即允许数据被读出(注意加入延时可以防止干扰) 
       先写入地址
       在分八次吧数据一位位读出,在scl2的一个下降沿数据被读出;数据位从0开始

***************************************************************************************************************/
unsigned char Read_Ds1302 ( unsigned char address )

  unsigned char  temp1;temp2;
  RST=0;     
 _nop_();_nop_();_nop_();_nop_();_nop_();
  SCL2=0;
 _nop_();_nop_();_nop_();_nop_();_nop_();
  RST=1;
 _nop_();_nop_();_nop_();_nop_();_nop_();    //开启,写入数据地址,这是本串口协议的开始,加入延时防止干扰
  Write_Ds1302_Byte(address);
 temp1=Read_Ds1302_Byte(); 
 temp2=temp1》》4;
 temp2=temp2*10;
 temp1=temp1&0x0f;
 temp1=temp1+temp2;//读出数据的时候要将BCD码转换成十进制
  RST=0;
  return (temp1);   //返回



/***************************************************************************************************
设定时间初值:
   在写入之前应当把要写入的数据转换成BCD码的形式
   每写入一次数据记得都要打开1302的写入允许
   
****************************************************************************************************/
void Set_RTC(void)  //设定 日历

 unsigned char i;*p;tmp;
 for(i=0;i
小提示:按 回车 [Enter] 键 返回书目,按 ← 键 返回上一页, 按 → 键 进入下一页。 赞一下 添加书签加入书架