用12864液晶作了一个万年历

 

  /**************************************************************************
* 文 件 名:test.c

**************************************************************************/
/****************************文件包含*************************************/
#include < reg52.h >
#include < led5.h >
#include < led1.h >
#include < led4.h >
#include < led7.h>
#include < led6.h >
#include < led2.h >

/*****************************预定义**************************************/
#define uchar unsigned char
#define uint unsigned int
/****************************************************************************/
sbit bell = P2 ^ 0; //定义蜂鸣器端口
sbit in = P2 ^ 7;  //定义红外检测端口
/*****************************************************************************
* 名称: Timer0_Service() inturrupt 1
* 功能: 中断服务程序 整点报时 3声嘟嘟的声音
* 入口参数:
* 出口参数:
*****************************************************************************/
void Timer0_Service() interrupt 1
{
   static uchar count = 0;
   static uchar flag = 0; //记录鸣叫的次数
   count = 0;
   TR0 = 0;      //关闭Timer0
   TH0 = 0x3c;
   TL0 = 0XB0;   //延时 50 ms
   TR0 = 1 ;     //启动Timer0
   count ++;
   if( count == 100 ) //鸣叫 1 秒
   {
      bell = ~ bell;
      count = 0;
      flag ++;
   }
   if( flag == 6 )
   {
      flag = 0;
      TR0 = 0;   //关闭Timer0
   }

}
/*****************************************************************************
* 名称: Timer2_Servie() interrupt 5
* 功能: 中断服务程序  整点报时 一分钟
* 入口参数:
* 出口参数:
*****************************************************************************/
void Timer3_Service() interrupt 5
{
   static uchar count;
   TF2 = 0; //软件清除中断标志
   count ++;
   if( in == 1 )
   {
      count = 0; //计算清0
      TR2 = 0; //关闭Timer2
      bell = 1; //关闭蜂鸣器
   }
   if( count == 120 ) // 一分钟后 关闭报警
   {
      count = 0; //计算清0
      TR2 = 0; //关闭Timer2
      bell = 1; //关闭蜂鸣器
   }
}
/******************************************************************************
* 函数名称:main()
* 功    能:
* 入口参数:
* 出口参数:
********************************************************************************/
void main( void )
{
              
    uchar clock_time[7] = { 0x00, 0x30, 0x08, 0x10, 0x01,0x09  };        //定义时间变量 秒  分 时 日 月 年
    uchar alarm_time[2] = { 0, 0}; //闹钟设置  alarm_time[0]: 分钟  alarm_time[1] :小时
 uchar temperature[2];  //定义温度变量   temperature[0]  低8位   temperature[1]  高8位
    Lcd_Initial();     //LCD初始化
 Clock_Initial( clock_time ); //时钟初试化
   
 /***********************中断初始化***************************/
    EA = 1; //开总中断
    ET0 = 1;  //Timer0 开中断
 ET2 = 1; //Timer2 开中断
    TMOD = 0x01 ; //Timer0 工作方式 1
 RCAP2H = 0x3c;
    RCAP2L = 0xb0; //Timer2 延时 50 ms

    while( 1 )
 {
    switch( Key_Scan() )
       {
          case up_array: 
                 {
                          Key_Idle();
                       }
                 break;    
          case down_array:  
                   {
          Key_Idle();
       }
                   break;                 
    case clear_array:  
                    {   
           Key_Idle();
           }
        break;
    case function_array:{
                                 Key_Function( clock_time, alarm_time );
                        }
    case null:     
             {
          Clock_Fresh( clock_time ); //时间刷新
                Lcd_Clock( clock_time );   //时间显示
       //Delay(1000)
                     // Lcd_Clock( uchar temp)
                      Sensor_Fresh( temperature ); //温度更新
      // Lcd_Temperture( temperature ); //温度显示
              //  ershi(clock_time);

       Ershi( clock_time );
                      Calendar_Convert( 0 , clock_time );//调用阴历转换显示子程序
       Week_Convert( 0, clock_time );

       //整点报时
       if( ( * clock_time == 0x59 ) && ( * ( clock_time + 1 ) == 0x59 ) )
       {
          bell = 0;
       TR2 = 1; //启动Timer2
       }
                      //闹钟报警
                      if( * alarm_time == * ( clock_time + 1 ) ) //分钟相吻合
          if( * ( alarm_time + 1 ) == *( clock_time + 2 ) ) //小时相吻合
       {
          bell = 0;
       TR2 = 1; //启动Timer2
       }
                   }
        break;
         }
 }
}

    // (led1.h)

       #ifndef _LCD_12864
#define _LCD_12864
/*****************************预定义**************************************/
#define uchar unsigned char
#define uint unsigned int      /***************************12864管脚配置****************************/
#define port P1
sbit  rs=P3^0;
sbit  rw=P3^1;
sbit   e=P3^2;
sbit cs1=P3^6;
sbit cs2=P3^7;

uchar code ershi_logo[27][32] =
{
/*--  文字:  小 0 --*/ 
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0x00,0x80,0x60,0x00,0xFF,0x00,0x20,0x40,0x80,0x00,0x00,0x00,0x00,
0x00,0x08,0x04,0x02,0x01,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x01,0x06,0x00,0x00,

/*--  文字:  寒 1 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x10,0x0C,0x04,0x54,0x54,0xFC,0x55,0x56,0x54,0xFC,0x54,0x54,0x04,0x14,0x0C,0x00,
0x20,0x21,0x11,0x09,0x05,0x23,0x25,0x45,0x49,0x93,0x05,0x09,0x11,0x31,0x10,0x00,

/*--  文字:  大2  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x7F,0xA0,0x20,0x20,0x20,0x20,0x30,0x20,0x00,
0x00,0x40,0x40,0x20,0x10,0x0C,0x03,0x00,0x01,0x06,0x08,0x10,0x20,0x60,0x20,0x00,
/*--  文字:  立 3 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
 0x00,0x10,0x10,0x90,0x10,0x10,0x11,0x16,      0x10,0x10,0x10,0xD0,0x18,0x10,0x00,0x00,
      0x40,0x40,0x40,0x40,0x43,0x5C,0x40,0x40,      0x50,0x4C,0x43,0x40,0x40,0x60,0x40,0x00,
/*--  文字:  春 4 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
      0x20,0x22,0x2A,0x2A,0xAA,0x6A,0x3A,0x2F,      0x2A,0x6A,0xAA,0x2A,0x2A,0x22,0x20,0x00,
      0x04,0x04,0x02,0x01,0xFF,0x49,0x49,0x49,      0x49,0x49,0xFF,0x01,0x02,0x06,0x02,0x00,
 /*--  文字:  雨 5 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
      0x02,0x02,0xF2,0x12,0x92,0x12,0x12,0xFE,      0x12,0x92,0x12,0x12,0xFA,0x13,0x02,0x00,
      0x00,0x00,0xFF,0x00,0x08,0x11,0x00,0x7F,      0x00,0x08,0x51,0x80,0x7F,0x00,0x00,0x00,

/*--  文字:  水 6 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
      0x00,0x20,0x20,0x20,0x20,0xE0,0x00,0xFF,      0xC0,0x40,0x20,0x10,0x18,0x00,0x00,0x00,
      0x20,0x10,0x08,0x04,0x03,0x40,0x80,0x7F,      0x00,0x01,0x02,0x04,0x08,0x18,0x08,0x00,
/*--  文字:  惊 7 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
      0x80,0x70,0x00,0xFF,0x10,0x24,0xE4,0x24,      0x25,0x26,0x24,0x24,0xF4,0x26,0x04,0x00,
      0x00,0x00,0x00,0xFF,0x00,0x20,0x13,0x4A,      0x82,0x7E,0x02,0x0A,0x13,0x30,0x00,0x00,


/*--  文字:  蛰 8 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
      0x04,0x24,0xA4,0x24,0xFF,0x14,0x14,0x84,      0x94,0x7F,0x44,0x04,0xFE,0x04,0xC0,0x00,
      0x00,0x40,0x40,0x5F,0x52,0x52,0x52,0x7F,      0x52,0x52,0x52,0x5E,0x40,0xE1,0x01,0x00,

/*--  文字:  分 9 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
      0x00,0x80,0x40,0x20,0x98,0x86,0x80,0x80,      0x83,0x8C,0x90,0x20,0xC0,0x80,0x80,0x00,
      0x01,0x00,0x80,0x40,0x20,0x1F,0x00,0x40,      0x80,0x40,0x3F,0x00,0x00,0x01,0x00,0x00,
/*--  文字:  清 10 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
      0x10,0x22,0x64,0x0C,0xC0,0x44,0x54,0x54,       0x54,0x7F,0x54,0x54,0xD6,0x44,0x40,0x00,
      0x04,0x04,0xFE,0x01,0x00,0x00,0xFF,0x15,       0x15,0x15,0x55,0x95,0x7F,0x01,0x00,0x00, 

/*--  文字:  明11  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
      0x00,0xFC,0x44,0x44,0x44,0xFE,0x04,0x00,       0xFE,0x22,0x22,0x22,0x22,0xFF,0x02,0x00,
      0x00,0x0F,0x04,0x04,0x04,0x8F,0x40,0x30,       0x0F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,
 /*--  文字: 谷12  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
      0x00,0x10,0x08,0x04,0x83,0x40,0x20,0x18,      0x20,0x41,0x82,0x86,0x0C,0x00,0x00,0x00,
      0x02,0x02,0x01,0xFD,0x44,0x44,0x44,0x44,      0x44,0x44,0x44,0xFC,0x01,0x03,0x01,0x00,
 /*--  文字: 夏13 --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x01,0x01,0xFD,0x55,0x55,0x57,0x55,      0x55,0x55,0x55,0xFD,0x01,0x01,0x00,0x00,
      0x00,0x20,0x90,0x89,0x87,0x4D,0x55,0x25,       0x25,0x55,0x4D,0x85,0x80,0x80,0x00,0x00,
 /*--  文字: 满14  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x10,0x21,0x62,0x06,0x24,0x24,0x24,0xEF,        0x24,0x24,0xEF,0x24,0x34,0xA6,0x04,0x00,
      0x04,0x04,0xFE,0x01,0xFF,0x11,0x09,0x07,       0x09,0x09,0x07,0x49,0x91,0x7F,0x01,0x00,
 /*--  文字: 芒15  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x84,0x84,0x84,0x84,0x9F,0x84,0xA4,0xC4,       0x84,0x84,0x9F,0x84,0x84,0xC6,0x84,0x00,
      0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x40,      0x40,0x40,0x40,0x60,0x40,0x00,0x00,0x00,

 /*--  文字: 种16  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  0x24,0x24,0xA4,0xFE,0xA3,0x22,0x20,0xF0,         0x10,0x10,0xFF,0x10,0x10,0xF8,0x10,0x00,
      0x08,0x06,0x01,0xFF,0x00,0x03,0x00,0x07,       0x02,0x02,0xFF,0x02,0x02,0x07,0x00,0x00,
 /*--  文字: 至17  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x02,0x42,0x62,0x52,0x4A,0x46,0xC2,       0x42,0x42,0x52,0x62,0xC3,0x02,0x00,0x00,
      0x40,0x40,0x44,0x44,0x44,0x44,0x44,0x7F,       0x44,0x44,0x44,0x46,0x44,0x60,0x40,0x00,
 /*--  文字: 暑18  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x40,0x5F,0x55,0x55,0xF5,0x55,       0xD5,0x55,0x75,0x5F,0x10,0x88,0x00,0x00,
      0x11,0x11,0x09,0x09,0xFD,0x57,0x55,0x55,       0x55,0x55,0x55,0x55,0xFF,0x05,0x01,0x00,
 /*--  文字: 秋19  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x24,0x24,0xA4,0xFE,0x23,0x22,0x80,0x70,        0x00,0xFF,0x00,0x40,0x20,0x30,0x00,0x00,
      0x08,0x06,0x01,0xFF,0x81,0x42,0x20,0x18,       0x06,0x01,0x06,0x08,0x30,0x60,0x20,0x00,
 /*--  文字: 处20  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0xE0,0x1E,0x10,0x10,0xF0,0x00,      0x00,0xFF,0x20,0x40,0x80,0x80,0x00,0x00,
      0x82,0x41,0x20,0x1B,0x04,0x1B,0x20,0x40,       0x40,0x5F,0x40,0x40,0x40,0x61,0x20,0x00,
 /*--  文字: 白21  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
 0x00,0x00,0xF8,0x08,0x0C,0x0A,0x09,0x08,        0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,
      0x00,0x00,0x7F,0x21,0x21,0x21,0x21,0x21,       0x21,0x21,0x21,0x21,0x7F,0x00,0x00,0x00,
 /*--  文字: 露22  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
 0x10,0x0C,0xC5,0x45,0x6D,0x55,0xC5,0x3F,        0x05,0xD5,0xAD,0x85,0x85,0x14,0x0C,0x00,
      0x00,0x40,0xFB,0x42,0x3E,0x2A,0x2B,0x12,       0xF1,0x9A,0x94,0x9A,0xF1,0x10,0x10,0x00,
 /*--  文字: 霜23  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x10,0x0C,0x04,0x55,0xD5,0x55,0x05,0x7F,       0x05,0x55,0x55,0x55,0x04,0x94,0x0C,0x00,
      0x00,0x22,0x12,0x0A,0xFF,0x0A,0x12,0x00,       0xFF,0x55,0x55,0x55,0x55,0xFF,0x01,0x00,
 /*--  文字: 降24  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0xFE,0x02,0x22,0xDA,0x06,0x88,0x44,       0x57,0xA4,0x54,0x4C,0x84,0x80,0x80,0x00,
      0x00,0xFF,0x08,0x10,0x08,0x07,0x10,0x1E,       0x12,0xFF,0x12,0x12,0x18,0x11,0x00,0x00,
 /*--  文字: 冬25  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x20,0x10,0x08,0x17,0xA4,0x44,         0xA4,0x94,0x0C,0x04,0x00,0x00,0x00,0x00,
      0x04,0x04,0x02,0x02,0x01,0x25,0x24,0x48,       0x48,0x80,0x01,0x01,0x02,0x06,0x02,0x00,
 /*--  文字: 雪26  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
 0x10,0x0C,0x04,0x55,0x55,0x55,0x05,0xFF,       0x05,0x55,0x55,0x55,0x84,0x14,0x0C,0x00,
      0x00,0x00,0x41,0x49,0x49,0x49,0x49,0x49,       0x49,0x49,0x49,0x49,0xFF,0x01,0x00,0x00

};
/********************************************************************************************
* 函数名称:Delay()
* 功    能:延迟时间=a*1ms
* 入口参数:
* 出口参数:无
*********************************************************************************************/
void Delay(uint a)
{
   uchar  i;
   while(a--)
   for(i=0;i<125;i++);
}
/********************************************************************************************
* 函数名称:L

/*-----------------------------------------------------------*/ #define LCD_OFF 0x3E #define LCD_ON 0x3F #define Add_X 0xB8 //the start address of the page 0 ;(0~7) #define Add_Y 0x40 //the start address of the Y counter ; (0~64) #define Add_Z 0xC0 //the start address of the DDRAM ; (0~64) #define UPLINE 0x01 #define UNDERLINE 0x80 /*-----------------------------------------------------------*/ #define LCD12864_DATA_PORT P0 sbit LCD12864_EN =P1^4; sbit LCD12864_RW =P1^3; //0:write ; 1:read sbit LCD12864_RS =P1^2; //0:the command .1:the data sbit LCD12864_CS_L =P1^1; //select the left of the lcd when 1 sbit LCD12864_CS_R =P1^0; sbit LCD12864_RST =P1^5; /*------------------------------------------------------------*/ void delayus(unsigned int us) { while(us--); } void delayms(unsigned ms) { unsigned int i,j; for (i=0;i<ms;i++) { for (j=0;j<1000;j++) ; } } /*--------------------------select the LCD--------------------*/ void LCDSel(unsigned char sel) { switch(sel) { case 0: LCD12864_CS_L=0;LCD12864_CS_R=0;break; case 1: LCD12864_CS_L=1;LCD12864_CS_R=0;break; //left case 2: LCD12864_CS_L=0;LCD12864_CS_R=1;break; //right default:; }; } /*------------------------------------------------------------*/ void WaitLCD() { unsigned char flag; LCD12864_DATA_PORT=0xFF; LCD12864_RW=1; LCD12864_RS=0; LCD12864_EN=1; LCD12864_EN=1; LCD12864_EN=0; LCD12864_DATA_PORT=0xFF; //读有效数据 LCD12864_RW=1; LCD12864_RS=0; ; LCD12864_EN=1; do { flag=LCD12864_DATA_PORT; LCD12864_DATA_PORT=0xFF; }while(!((flag&0x80)==0x80)); LCD12864_EN=0; } //*/ /*-------------------------------------------------------------*/ void WriteDatToLCD12864(unsigned char dat) { WaitLCD(); LCD12864_RS=1; //the data LCD12864_RW=0; //write LCD12864_DATA_PORT=dat; LCD12864_EN=1; ; LCD12864_EN=0;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值