内容如题,可以调节时间,没有闹钟之类的,程序其实也是拼凑出来的,有很多问题,之后我会重新理解,然后重新写过,再加些功能。 现在这个就当做是我开始学习的一个记录吧。
现在最主要的问题就是显示的时候字符相互之间有些冲突,导致有些地方显示不太全,还有大数字变化速度有点慢,以后可能会把秒针改小。
若是大家有解决方案的话,不妨帮帮我,多谢了。
单片机源程序如下:
- //-------------------------------------
- // 名称:用DS1302与12864LCD设计的可调电子日历与时钟
- //---------------------------------------
- // 说明:本例运行时会以PC时间表为默认时间开始,运行过程中可以通过K1键
- // 选择调节对象,所选中的调整对象会反白显示,用K2,K3键进行加减,用K4键保存。
- // 本例会自动将时间调节控制为合法日期时间,对于星期的调节会
- // 在调整年月日时自动完成,闰年问题也会自动判断。
- //-------------------------------------------
- #include <reg51.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define LCD_DB_PORT P0 // 液晶数据线端口DB0-DB7
- #define LCD_START_ROW 0xc0 //起始行命令
- #define LCD_PAGE 0xB8 //页指令
- #define LCD_COL 0x40 //列指令
- bit Reverse_Display=0;//是否反相显示(白底黑字/黑底白字)
- //液晶引脚定义
- sbit SDA=P1^0; //DS1302数据线
- sbit CLK=P1^1; //DS1302时钟线
- sbit RST=P1^2; //DS1302复位线
- sbit DI=P2^0;
- sbit RW=P2^1;
- sbit E=P2^2;
- sbit CS1=P2^3;
- sbit CS2=P2^4;
- sbit CS3=P2^2;
- char Adjust_Index=-1; //当前调节的时间对象:秒,分,时,日,月,年(0,1,2,3,4,6)
- uchar MonthsDays[]={0,31,0,31,30,31,30,31,31,30,31,30,31}; // 一年中每个月的天数,二月的天数由年份决定
- uchar DateTime[7];//所读取的日期时间
- //DS1302函数声明
- void Write_Byte_TO_DS1302(uchar X); // 向DS1302写入一个字节
- uchar Read_Byte_FROM_DS1302(); //从DS1302中读取一个字节
- uchar Read_Data_FROM_DS1302(uchar addr); //从DS1302指定位置读取数据 , 读数据
- void Write_Data_TO_DS1302(uchar addr,uchar dat); // 向DS1302指定位置写入数据, 写数据
- void SET_DS1302(); //设置时间
- void GetTime(); //读取当前时间
- uchar Is_Leapyear(uint year); //判断是否为闰年
- //12864LCD函数
- void dht11();
- extern void LCD12864_Initialization();
- extern void Display_char(uchar P1,uchar L1,uchar *M) reentrant;
- extern void Display_Word(uchar P2,uchar L2,uchar *M) reentrant;
- extern void Datetime_Adjust(char X);
- extern void SET_DS1302(); // 设置时间
- //函数声明
- void Initialization();//初始化函数
- extern bit Reverse_Display;//是否反相显示(白底黑字/黑底白字)
- extern uchar code Digits[];
- extern uchar code WEEK_WORDS[];
- extern uchar code Digits[];
- extern uchar code DATE_TIME_WORDS[];
- extern char Adjust_Index; //当前调节的时间对象:秒,分,时,日,月,年(0,1,2,3,4,6)
- extern uchar MonthsDays[]; // 一年中每个月的天数,二月的天数由年份决定
- extern uchar DateTime[7];//所读取的日期时间
- sbit k1=P3^4; //选择按键
- sbit k2=P3^5; //加
- sbit k3=P3^6; //减
- sbit k4=P3^7; //确定
- uchar tcount=0;
- //水平与垂直偏移
- uchar H_Offset=0;
- uchar V_page_Offset=0;
- //---------------------------------------------------------------
- // 检查LCD是否忙
- //--------------------------------------------------------------
- bit LCD_IS_BUSY()
- {
- LCD_DB_PORT=0xFF;
- RW=1;
- _nop_();
- DI=0;
- E=1;
- _nop_();
- E=0;
- return (bit)(P0&0x80);
- }
- //---------------------------------------------------------------
- // 向LCD写入一个字节(一般用于发送命令)
- //--------------------------------------------------------------
- void Write_Byte_To_LCD(uchar comand)
- {
- while(LCD_IS_BUSY());
- LCD_DB_PORT=0xFF;
- RW=0;
- _nop_();
- DI=0;
- LCD_DB_PORT=comand;
- E=1;
- _nop_();
- E=0;
- }
- //---------------------------------------------------------------
- // 向LCD写入数据
- //--------------------------------------------------------------
- void Write_Data_To_LCD(uchar dat)
- {
- while(LCD_IS_BUSY());
- LCD_DB_PORT=0xFF;
- RW=0;
- _nop_();
- DI=1;
- if(!Reverse_Display) //根据Reverse_Display决定是否反相显示
- LCD_DB_PORT=dat;
- else
- LCD_DB_PORT=~dat;
- E=1;
- _nop_();
- E=0;
- }
-
- //********************************************************************
- //1MS为单位的延时程序,不准确
- //********************************************************************
- void lcd_delay_ms(unsigned char m)
- {
- unsigned char n;
- while(m--){
- for(n=0;n<125;n++)
- {;}
- }
- }
- //---------------------------------------------------------------
- // 初始化LCD
- //--------------------------------------------------------------
- void LCD12864_Initialization()
- {
- CS1=1;
- CS2=1;
- Write_Byte_To_LCD(0x38);
- lcd_delay_ms(10);
- Write_Byte_To_LCD(0x0F);
- lcd_delay_ms(10);
- Write_Byte_To_LCD(0x06);
- lcd_delay_ms(10);
- // Write_Byte_To_LCD(LCD_START_ROW);
- Write_Byte_To_LCD(0x01);
- lcd_delay_ms(10);
- }
- //---------------------------------------------------------------
- // 通用显示函数 从第P页第L列显示W个字节数据,具体显示的数据在r所指的数组中
- //--------------------------------------------------------------
- void LCD_Show(uchar P,uchar L,uchar W,uchar *r) reentrant
- {
- uchar i;
- if(L<64)
- {
- CS1=1;
- CS2=0;
- Write_Byte_To_LCD(LCD_PAGE+P);
- Write_Byte_To_LCD(LCD_COL+L);
- if(L+W<64)
- {
- for(i=0;i<W;i++)
- Write_Data_To_LCD(r[i]);
- }
- else
- {
- for(i=0;i<64-L;i++)
- Write_Data_To_LCD(r[i]);
- CS1=0;
- CS2=1;
- Write_Byte_To_LCD(LCD_PAGE+P);
- Write_Byte_To_LCD(LCD_COL);
- for(i=64-L;i<W;i++)
- Write_Data_To_LCD(r[i]);
- }
- }
- else
- {
- CS1=0;
- CS2=1;
- Write_Byte_To_LCD(LCD_PAGE+P);
- Write_Byte_To_LCD(LCD_COL+L-64);
- for(i=0;i<W;i++)
- Write_Data_To_LCD(r[i]);
- }
- }
- //---------------------------------------------------------------
- // 显示一个8×16点阵字符
- //--------------------------------------------------------------
- void Display_char(uchar P1,uchar L1,uchar *M) reentrant
- {
- LCD_Show(P1,L1,8,M);
- LCD_Show(P1+1,L1,8,M+8);
- }
- //--------------------------------------------------------------------
- // 显示一个16×16点阵字符 (汉字上半部分与下半部分分别处在相邻两页中)
- //----------------------------------------------------------------------
- void Display_Word(uchar P2,uchar L2,uchar *M) reentrant
- {
- LCD_Show(P2,L2,16,M);
- LCD_Show(P2+1,L2,16,M+16);
- }
- //--------------------------------------------------------------------
- // 显示一个16×32点阵字符 (汉字上半部分与下半部分分别处在相邻两页中)
- //----------------------------------------------------------------------
- void Display_Word2(uchar P2,uchar L2,uchar *M) reentrant
- {
- LCD_Show(P2,L2,16,M);
- LCD_Show(P2+1,L2,16,M+16);
- LCD_Show(P2+2,L2,16,M+32);
- LCD_Show(P2+3,L2,16,M+48);
- }
- //*************************************************************************
- //***********************DHT11*************************
- //**************************************************************************
- //sbit DATA = P1^3; //定义数据引脚
- //bit flag_1s,flag_200ms,tmp;
- //----------------定义区--------------------//
- uchar s1,s2,w1,w2;
- sbit TRH = P1^3;//data数据端
- unsigned char i;
- typedef unsigned char unint8;
- typedef unsigned char unint16;
- unint8 TH_data,TL_data,RH_data,RL_data,CK_data;
- unint8 TH_temp,TL_temp,RH_temp,RL_temp,CK_temp;
- unint8 com_data,untemp,temp;
- unint8 respond;
- /*********************************************************************************/
- void delayNOP()
- {
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- }
- /*********************************************************************************/
- /*********************************************************************************/
- // 毫秒级延时子程序
- /*********************************************************************************/
- void delay_ms(unsigned char ms)
- {
- unsigned char i;
- while(ms--)
- {
- for(i = 0; i<250; i++)
- {
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- }
- }
- }
- /*********************************************************************************/
- /*********************************************************************************/
- //5us级延时程序
- /*********************************************************************************/
- void delay_us()
- {
- unint8 i;
- i--;
- i--;
- i--;
- i--;
- i--;
- i--;
- }
- /****************************************************************************/
- /****************************************************************************/
- //收发信号检测,数据读取
- /****************************************************************************/
- char receive()
- {
- unint8 i;
- // ST=0;
- com_data=0;
- for(i=0;i<=7;i++)
- {
- respond=2;
- while((!TRH)&&respond++);
- delay_us();
- delay_us();
- delay_us();
- if(TRH)
- {
- temp=1;
- respond=2;
- while((TRH)&&respond++);
- }
- else
- temp=0;
- com_data<<=1;
- com_data|=temp;
- }
- return(com_data);
- }
- /****************************************************************************/
- /****************************************************************************/
- //湿度读取子程序
- //温度高8位== TL_data
- //温度低8位== TH_data
- //湿度高8位== RH_data
- //湿度低8位== RH_data
- //校验 8位 == CK_data
- //调用的程序有 delay();, Delay_5us();,RECEIVE();
- /***************************************************************************/
- void read_TRH()
- {
- // int m;
- //主机拉低18ms
- TRH=0;
- delay_ms(18);
- TRH=1;
- //DATA总线由上拉电阻拉高 主机延时20us
- delay_us();
- delay_us();
- delay_us();
- delay_us();
- //主机设为输入 判断从机响应信号
- TRH=1;
- //判断DHT11是否有低电平响应信号 如不响应则跳出,响应则向下运行
- if(!TRH)
- {
- respond=2;
- //判断DHT11发出 80us 的低电平响应信号是否结束
- while((!TRH)&& respond++);
- respond=2;
- //判断从机是否发出 80us 的高电平,如发出则进入数据接收状态
- while(TRH && respond++);
- //数据接收状态
- RH_temp = receive();
- RL_temp = receive();
- TH_temp = receive();
- TL_temp = receive();
- CK_temp = receive();
- TRH=1;
- // ST=1;
- //数据校验
- untemp=(RH_temp+RL_temp+TH_temp+TL_temp);
- if(untemp==CK_temp)
- {
- RH_data = RH_temp;
- RL_data = RL_temp;
- TH_data = TH_temp;
- TL_data = TL_temp;
- CK_data = CK_temp;
- }
- }
- // if(RH_data>=60)
- // {
- // i=100;
- // while(i>0)
- // {
- // Beep=1;
- // delay_ms(1);
- // Beep=0;
- // i--;
- // }
- // Beep=1;
- // }
- // else if(RH_data<60)
- // {
- // Beep=0;
- // }
- //湿度整数部分
- // RH_data= htoi(str1);
- s1 = (char)(RH_data/10);
- s2 = (char)(RH_data%10);
- //温度整数部分
- // TH_data= htoi(str2);
- w1 = (char)(TH_data/10);
-
- w2 = (char)(TH_data%10);
- // m=(int)(RH_data);
- // if(m>=35)//可改变相应数值,以此控制其他设备
- // {
- // XS=0;
- // // Beep =1; //可适当加一个延迟
- // }
- // else
- // {
- // XS=1;
- // //Beep =0;
- // }
- }
-
- //*--------写字节函数,向DS1302写入一个字节--------*//
- void Write_Byte_TO_DS1302(uchar X) // 向DS1302写入一个字节
- {
- uchar i;
- for(i=0;i<8;i++)
- {
- SDA=X&1;
- CLK=1;
- CLK=0;
- X>>=1;
- }
- }
- //*--------读字节函数,从DS1302读取一个字节--------*//
- uchar Read_Byte_FROM_DS1302() //从DS1302中读取一个字节
- {
- uchar i,byte,t;
- for(i=0;i<8;i++)
- {
- byte>>=1;
- t=SDA;
- byte|=t<<7;
- CLK=1;
- CLK=0;
- }
- //BCD码转换
- return byte/16*10+byte%16;
- }
- //-------------------------------------------------------------
- //从DS1302指定位置读取数据 , 读数据
- //---------------------------------------------------------------
- uchar Read_Data_FROM_DS1302(uchar addr) //从DS1302指定位置读取数据 , 读数据
- {
- uchar dat;
- RST=0;
- CLK=0;
- RST=1;
- Write_Byte_TO_DS1302(addr); //向DS1302写入一个地址
- dat=Read_Byte_FROM_DS1302(); //在上面写入的地址中读取数据
- CLK=1;
- RST=0;
- return dat;
- }
- //-------------------------------------------------------------
- //向DS1302指定位置写入数据, 写数据
- //---------------------------------------------------------------
- void Write_Data_TO_DS1302(uchar addr,uchar dat) // 向DS1302指定位置写入数据, 写数据
- {
- CLK=0;
- RST=1;
- Write_Byte_TO_DS1302(addr);
- Write_Byte_TO_DS1302(dat);
- CLK=1;
- RST=0;
- }
- //-----------------------------------------------------------
- // 设置时间
- //---------------------------------------------------------
- void SET_DS1302() // 设置时间
- {
- uchar i;
- Write_Data_TO_DS1302(0x8E,0x00); //写控制字,取消写保护
- // 分,时,日,月,年依次写入
- for(i=0;i<7;i++)
- {
- // 分的起始地址是10000010(0x82),后面依次是时,日,月,周,年,写入地址每次递增2
- Write_Data_TO_DS1302(0x80+2*i,(DateTime[i]/10<<4)|(DateTime[i]%10));
- }
- Write_Data_TO_DS1302(0x8E,0x80); //写控制字,加写保护
- }
- //--------------------------------------------------------
- // 读取当前时间
- //-------------------------------------------------------
- void GetTime() // 读取当前时间
- {
- uchar i;
- for(i=0;i<7;i++)
- {
- DateTime[i]=Read_Data_FROM_DS1302(0x81+2*i);
- }
- }
- //-------------------------------------------------------------------
- // 判断是否为闰年
- //-------------------------------------------------------------------
- uchar Is_Leapyear(uint year)
- {
- return (year%4==0&&year%100!=0)||(year%400==0) ;
- }
- //------------------------------------------------------------------
- // 求自2000.1.1开始的任何一天是星期几?
- //----------------------------------------------------------------------
- void Refresh_Week_Day()
- {
- uint i,d,w=5; //已知1999年12.31是星期五
- for(i=2000;i<2000+DateTime[6];i++)
- {
- d=Is_Leapyear(i)?366:365;
- w=(w+d)%7;
- }
- d=0;
- for (i=1;i<DateTime[4];i++)
- {d+=MonthsDays[i];}
- d+=DateTime[3];
- //保存星期,0-6表示星期日,星期一至星期六,为了与DS1302的星期格式匹配,返回值需要加1
- DateTime[5]=(w+d)%7+1;
- }
- //-------------------------------------------------
- //年,月,日和时,分++/--
- //----------------------------------------------------
- void Datetime_Adjust(char X)
- {
- switch(Adjust_Index)
- {
- case 6: //年调整,00-99
- if(X==1&&DateTime[6]<99)
- {
- DateTime[6]++;
- }
- if(X==-1&&DateTime[6]>0)
- {
- DateTime[6]--;
- }
- //获取2月天数
- MonthsDays[2]=Is_Leapyear(2000+DateTime[6])?29:28;
- //如果年份变化后当前月份的天数大于上限则设为上限
- if(DateTime[3]>MonthsDays[DateTime[4]])
- {
- DateTime[3]=MonthsDays[DateTime[4]];
- }
- Refresh_Week_Day(); //刷新星期
- break;
- case 4: //月调整 01-12
- if(X==1&&DateTime[4]<12)
- {
- DateTime[4]++;
- }
- if(X==-1&&DateTime[4]>1)
- {
- DateTime[4]--;
- }
- //获取2月天数
- MonthsDays[2]=Is_Leapyear(2000+DateTime[6])?29:28;
- //如果年份变化后当前月份的天数大于上限则设为上限
- if(DateTime[3]>MonthsDays[DateTime[4]])
- {
- DateTime[3]=MonthsDays[DateTime[4]];
- }
- Refresh_Week_Day(); //刷新星期
- break;
- case 3: // 日调整00-28或00-29或00-30或00-31
- //调节之前首先根据当前年份得出该年中2月的天数
- MonthsDays[2]=Is_Leapyear(2000+DateTime[6])?29:28;
- //根据当前月份决定调节日期的上限
- if(X==1&&DateTime[3]<MonthsDays[DateTime[4]])
- {
- DateTime[3]++;
- }
- if(X==-1&&DateTime[3]>0)
- {
- DateTime[3]--;
- }
- Refresh_Week_Day(); //刷新星期
- break;
- case 2: // 时调整
- if(X==1&&DateTime[2]<23)
- {
- DateTime[2]++;
- }
- if(X==-1&&DateTime[4]>0)
- {
- DateTime[2]--;
- }
- break;
- case 1: // 分调整
- if(X==1&&DateTime[1]<59)
- {
- DateTime[1]++;
- }
- if(X==-1&&DateTime[4]>0)
- {
- DateTime[1]--;
- }
- break;
- case 0: // 秒调整
- if(X==1&&DateTime[1]<59)
- {
- DateTime[0]++;
- }
- if(X==-1&&DateTime[4]>0)
- {
- DateTime[0]--;
- }
- break;
- }
- }
- //-------------------------------------------------
- // 与本程序有关的数字和汉字的点阵编码 DotMatrix.c
- // -----------------------------------------------
- //中文提示(纵向取模,字节倒序)
- //年、月、日、星期、时、分、秒等汉字点阵(16×16)
- uchar code DATE_TIME_WORDS[]={
- 0x40,0x20,0x10,0x0C,0xE3,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0x02,0x00,0x00, //年
- 0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00,
- 0x00,0x00,0x00,0x00,0x00,0xFF,0x11,0x11,0x11,0x11,0x11,0xFF,0x00,0x00,0x00,0x00,//月
- 0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x01,0x01,0x21,0x41,0x3F,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,//日
- 0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,//星
- 0x00,0x48,0x46,0x41,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x49,0x41,0x40,0x00,
- 0x00,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,//期
- 0x42,0x22,0x1B,0x02,0x02,0x0A,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3F,0x00,0x00,
- 0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,//时
- 0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,
- 0x80,0x40,0x20,0x98,0x87,0x82,0x80,0x80,0x83,0x84,0x98,0x30,0x60,0xC0,0x40,0x00,//分
- 0x00,0x80,0x40,0x20,0x10,0x0F,0x00,0x00,0x20,0x40,0x3F,0x00,0x00,0x00,0x00,0x00,
- 0x12,0x12,0xD2,0xFE,0x91,0x11,0xC0,0x38,0x10,0x00,0xFF,0x00,0x08,0x10,0x60,0x00,//秒
- 0x04,0x03,0x00,0xFF,0x00,0x83,0x80,0x40,0x40,0x20,0x23,0x10,0x08,0x04,0x03,0x00
- };
- //一、二、三、四、五、六和天等汉字点阵(16×16)
- uchar code WEEK_WORDS[]={
- 0x00,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x00,//天
- 0x00,0x80,0x40,0x20,0x10,0x08,0x06,0x01,0x02,0x04,0x08,0x10,0x30,0x60,0x20,0x00,
- 0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,//一
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00,0x00,0x00,//二
- 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x18,0x10,0x00,
- 0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,//三
- 0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
- 0x00,0xFE,0x02,0x02,0x02,0xFE,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,//四
- 0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x22,0x7F,0x00,0x00,
- 0x00,0x02,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0xC2,0x82,0x02,0x00,0x00,0x00,//五
- 0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x30,0x20,0x00,
- 0x10,0x10,0x10,0x10,0x10,0x91,0x12,0x1E,0x94,0x10,0x10,0x10,0x10,0x10,0x10,0x00,//六
- 0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x00,0x00,0x01,0x02,0x0C,0x78,0x30,0x00,0x00,
- 0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,
- 0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00,/*"℃",0*/
- };
- //0-9等数字点阵(8×16)
- uchar code Digits[]={
- 0x00,0x00,0xF0,0xF8,0x08,0x68,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x0B,0x08,0x0F,0x07, //0
- 0x00,0x20,0x20,0x30,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00, //1
- 0x00,0x30,0x38,0x08,0x88,0xF8,0x70,0x00,0x00,0x0C,0x0E,0x0B,0x09,0x08,0x08,0x00, // 2
- 0x00,0x30,0x38,0x88,0x88,0xF8,0x70,0x00,0x00,0x06,0x0E,0x08,0x08,0x0F,0x07,0x00, //3
- 0x00,0x00,0xF8,0xF8,0x00,0xE0,0xE0,0x00,0x00,0x03,0x03,0x02,0x02,0x0F,0x0F,0x02,//4
- 0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x00,0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00,//5
- 0x00,0xC0,0xE0,0x78,0x58,0xC8,0x80,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00,//6
- 0x00,0x08,0x08,0x88,0xE8,0x78,0x18,0x00,0x00,0x00,0x0E,0x0F,0x01,0x00,0x00,0x00,//7
- 0x00,0x70,0xF8,0xC8,0x88,0xF8,0x70,0x00,0x00,0x07,0x0F,0x08,0x09,0x0F,0x07,0x00,//8
- 0x00,0xF0,0xF8,0x08,0x08,0xF8,0xF0,0x00,0x00,0x00,0x09,0x0D,0x0F,0x03,0x01,0x00,//9
- 0xF0,0x08,0xF0,0x80,0x60,0x18,0x00,0x00,0x00,0x31,0x0C,0x03,0x1E,0x21,0x1E,0x00,/*"%",0*/
- 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,/*"R",1*/
- 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,/*"H",2*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,/*".",0*/
- };
- uchar code fuhao[]=
- {
- 0x00,0x00,0x00,0x00,0x80,0xC0,0x40,0x40,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0xF0,0xFE,0x0F,0x01,0x00,0x00,0x00,0x00,0x01,0x07,0xFE,0xF0,0x00,0x00,0x00,
- 0x00,0x3F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0x3F,0x00,0x00,0x00,
- 0x00,0x00,0x01,0x03,0x06,0x0C,0x08,0x08,0x08,0x06,0x03,0x01,0x00,0x00,0x00,0x00,/*"0",0*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x01,0x01,0x01,0x01,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x08,0x08,0x08,0x0C,0x0F,0x0F,0x0C,0x08,0x08,0x08,0x00,0x00,0x00,0x00,/*"1",1*/
- 0x00,0x00,0x00,0x80,0x40,0x40,0x40,0x40,0x40,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,
- 0x00,0x1E,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0xFF,0x3E,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x80,0x40,0x30,0x18,0x0C,0x06,0x03,0x01,0x00,0xC0,0x00,0x00,0x00,
- 0x00,0x0E,0x0D,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0E,0x03,0x00,0x00,0x00,/*"2",2*/
- 0x00,0x00,0x80,0x80,0x40,0x40,0x40,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,0x80,0xC1,0x7F,0x3E,0x00,0x00,0x00,0x00,
- 0x00,0xC0,0xC0,0x00,0x00,0x01,0x01,0x01,0x03,0x02,0x06,0xFC,0xF0,0x00,0x00,0x00,
- 0x00,0x03,0x07,0x04,0x08,0x08,0x08,0x08,0x08,0x04,0x06,0x03,0x00,0x00,0x00,0x00,/*"3",3*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x80,0x60,0x10,0x0C,0x03,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x30,0x2C,0x26,0x21,0x20,0x20,0x20,0x20,0xFF,0xFF,0x20,0x20,0x20,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x0F,0x0F,0x08,0x08,0x08,0x00,0x00,0x00,/*"4",4*/
- 0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,
- 0x00,0x00,0xFF,0x00,0x80,0x40,0x40,0x40,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,
- 0x00,0xC0,0xC3,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFC,0x00,0x00,0x00,
- 0x00,0x03,0x04,0x04,0x08,0x08,0x08,0x08,0x08,0x04,0x07,0x03,0x00,0x00,0x00,0x00,/*"5",5*/
- 0x00,0x00,0x00,0x00,0x80,0x80,0x40,0x40,0x40,0x40,0x80,0x80,0x00,0x00,0x00,0x00,
- 0x00,0xE0,0xFC,0x07,0x81,0xC0,0x40,0x40,0x40,0xC0,0x83,0x03,0x00,0x00,0x00,0x00,
- 0x00,0x7F,0xFF,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFC,0x00,0x00,0x00,
- 0x00,0x00,0x01,0x07,0x06,0x0C,0x08,0x08,0x08,0x0C,0x06,0x03,0x00,0x00,0x00,0x00,/*"6",6*/
- 0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,
- 0x00,0x0E,0x03,0x00,0x00,0x00,0x00,0x00,0xE0,0x18,0x06,0x01,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0xC0,0xFC,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"7",7*/
- 0x00,0x00,0x00,0x80,0xC0,0x40,0x40,0x40,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x3E,0x7F,0xF1,0xC0,0xC0,0x80,0x00,0x00,0x80,0x41,0x7F,0x1E,0x00,0x00,0x00,
- 0xF0,0xFC,0x0E,0x02,0x01,0x01,0x01,0x03,0x07,0x0E,0x1E,0xFC,0xF0,0x00,0x00,0x00,
- 0x01,0x03,0x06,0x04,0x08,0x08,0x08,0x08,0x08,0x04,0x06,0x03,0x01,0x00,0x00,0x00,/*"8",8*/
- 0x00,0x00,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
- 0xFC,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFE,0xF8,0x00,0x00,0x00,
- 0x01,0x03,0x07,0x0C,0x08,0x08,0x08,0x08,0x04,0x06,0xE1,0x7F,0x1F,0x00,0x00,0x00,
- 0x00,0x07,0x07,0x08,0x08,0x08,0x08,0x0C,0x06,0x03,0x01,0x00,0x00,0x00,0x00,0x00,/*"9",9*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //:
- 0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x0F,0x0F,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,/*"-",0*/
- };
- //----------------------------------------------------
- // 主程序
- //----------------------------------------------------
- void main()
- {
- Initialization();
- while(1)
- {
- if(Adjust_Index==-1)
- GetTime();
- read_TRH();
- // CS2=0; //左屏开显示
- // CS1=1;
- Display_char(6,0,Digits+s1*16);// Hz_Wo为某个汉字的首地址
- Display_char(6,16,Digits+s2*16);
- // CS2=1; //右屏开显示
- // CS1=0;
- Display_char(6,64,Digits+w1*16);
- Display_char(6,80,Digits+w2*16);
- }
- }
- void Initialization()//初始化函数
- {
- IE=0x83;
- IP=0x01;
- IT0=0X01;
- TH0=-50000/256; // 写入初值
- TL0=-50000%256; // 写入初值
- TR0=1;
- LCD12864_Initialization();//液晶初始化函数
- //显示年的前面固定的两位
- Display_char(V_page_Offset,0+H_Offset,Digits+2*16);//显示2
- Display_char(V_page_Offset,8+H_Offset,Digits); //显示0
- //-----------------------------------------------
- //在12864屏幕上固定显示汉字:年月日,星期,时分秒
- //---------------------------------------------------
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
89c52 ds1302 dht11 12864.rar
(161.11 KB, 下载次数: 278)
|