基于12864显示的万年历程序参考
大学单片机毕业设计课程设计 - 12864液晶年历
信息与电子工程学院《单片机技术应用实训》报告题目:电子万年历材料包括仿真图、PCB、软件、制作图片等具体可咨询T B “黎明电子ST YLE”时间:目录摘要 (1)一设计要求 (1)二芯片说明 (1)(1)STC89C52 (1)(2)DS1302 (3)(3)LED12864 (4)三系统组成 (5)四硬件单元电路设计 (6)(1)主控制模块 (6)(2)时钟振荡电路 (6)(3)蜂鸣器电路 (7)(4)按键电路 (7)(5)显示电路 (8)五系统软件 (9)六调试过程 (9)七总结 (10)参考文献: (11)摘要随着科技的快速发展,时间的流逝,至从观太阳、摆钟到现在电子钟,人类不断研究,不断创新纪录。
美国DALLAS公司推出的具有涓细电流充电能的低功耗实时时钟电路DS1302。
它可以对年、月、日、周日、时、分、秒进行计时,还具有闰年补偿等多种功能,而且DS1302的使用寿命长,误差小。
对于数字电子万年历采用直观的数字显示,可以同时显示年、月、日、周日、时、分、秒和温度等信息,还具有时间校准等功能该电路采用STC89C51单片机作为核心,功耗小,能在5V的低压工作,电压可选用3~5V电压供电。
综上所述此万年历具有读取方便、显示直观、功能多样、电路简洁、成本低廉等诸多优点,符合电子仪器仪的发展趋势,具有广阔的市场前景。
本电路为实现电子万年历的功能,采用单片机STC89C51,辅助以必要的外围电路,用C语言编写程序,并进行模块化设计而成的电子万年历系统.它通过LCD能正确显示阳历星期和时分秒,温度等,具有功能稳定,精确度高和可调的特点。
关键词: 单片机;STC89C52;DS1302;1602LCD一设计要求利用STC89C52单片机设计一个具有如下功能的万年历:1、能够显示和更改年、月、日、时、分、秒、星期。
2、可设定指定日期、时间的闹钟。
3、可以显示和更改生肖。
4、能够显示温度。
二芯片说明(1)STC89C521.芯片介绍STC89C52RC单片机是宏晶科技推出的新一代高速/低功耗/超强抗干扰的单片机,指令代码完全兼容传统8051单片机,12时钟/机器周期和6时钟/机器周期可以任意选择。
51单片机12864万年历(图片+主要程序C语言)
51单片机做的12864万年历这是我花了一个星期时间做的万年历;一开始是一些图片,后面是这个制作的C语言源程序;希望大家稀饭:Main.c#include "reg52.h"#include "macroconst.h"#include "keyscan.h"#include "screen.h"#include "18b20.h"#include "ds1302.h"#include "atao_12864.h"#include "24c02.h"idata unsigned char state1[1];unsigned char screennum=1;//屏幕号#define time_task_sec 200 //节拍200Hz#define clock 24000000 //晶振#define max_task 4 //最大任务数idata unsigned char task_delay[4];#define task_delay0 time_task_sec/1 //2赫兹18b20 #define task_delay1 time_task_sec/5 //10赫兹屏幕#define task_delay2 time_task_sec/3 //4赫兹1302 #define task_delay3 time_task_sec/20 //20赫兹键盘void init(){unsigned char i;init18b20();ds1302_init();initina1(); //---------------------------LCD字库初始化程序RdFromROM(state1,8,1);state[0]=state1[0]; //-------界面RdFromROM(state1,15,1);state[1]=state1[0];//------- 闹钟RdFromROM(state1,11,1);key_sound=state1[0];//-------按键音// state[2]=state1[2];// state[3]=state1[3];screennum=1;//------默认一号屏for(i=0;i<max_task;i++)//清除任务延时{task_delay[i]=0;}TMOD=0x11;EA=1;TH0=255-clock/time_task_sec/12/526;TL0=255-clock/time_task_sec/12%526;ET0=1;TR0=1;}void main(){init();while(1){ if(task_delay[0]==0){readtemp(); task_delay[0]=task_delay0;} if(task_delay[3]==0){MenuCheckKey();task_delay[3]=task_delay1;}if(task_delay[1]==0){screen_select(screennum);task_delay[1]=task_delay1;} if(task_delay[2]==0){ds1302_read_time(); task_delay[2]=task_delay0;} }}void timer0() interrupt 1{uchar i=0;TH0=255-clock/time_task_sec/12/526;TH1=255-clock/time_task_sec/12%526;for(i=0;i<max_task;i++)if(task_delay[i]) task_delay[i]--; // miao=21,fen=33,xiaomiao=94;if(ma_start==1){tt++;if(tt==8){tt=0;xiaomiao++;if(xiaomiao==99){xiaomiao=0;miao++;if(miao==60){miao=0;fen++;if(fen==99){fen=0;}}}}}}Screen.c:#include "reg52.h"#include "macroconst.h"#include "delay.h"#include "18b20.h"#include "atao_12864.h"#include "ds1302.h"#include "24c02.h"#include "festival.h"#include "keyscan.h"idata unsigned char miao=0,fen=78,xiaomiao=0,tt=0;idata unsigned char bai,shi,ge,shinian,genian,shiyue,geyue,shiri,geri,shishi,geshi,shifen,gefen,shimi ao,gemiao;idata unsigned char Number[4];unsigned char code mainmenu[]={" 主菜单""3.查询 4.温度""1.调时 2.秒表""5.设置 6.返回"};unsigned char code setmenu[]={" 设置""3.查温 4.按键""1.界面 2.闹铃""5.报时 6.返回"};void gettime(){shinian=(time_buf1[1]%100)/10;genian=(time_buf1[1]%100)%10;shiyue=(time_buf1[2])/10;geyue=(time_buf1[2])%10;shiri=(time_buf1[3])/10;geri=(time_buf1[3])%10;shishi=(time_buf1[4])/10;geshi=(time_buf1[4])%10;shifen=(time_buf1[5])/10;gefen=(time_buf1[5])%10;shimiao=(time_buf1[6])/10;gemiao=(time_buf1[6])%10;}void screen_select(uchar num){// initina1();gettime() ;if(num==1) //----------主界面{Lcd_Set_Post(1,0);TransferData(shinian+48,1);//----------------------年TransferData(genian+48,1);TransferData('/',1);TransferData(shiyue+48,1);//----------------------月TransferData(geyue+48,1);TransferData('/',1);TransferData(shiri+48,1);//----------------------日TransferData(geri+48,1);Lcd_Set_Post(1,4);if(state[1]==1)//----------------闹铃的状态图标{TransferData(' ',1);TransferData(14,1);}Lcd_Set_Post(1,5);if(key_sound==1){TransferData(13,1);}if(state[0]==0){Lcd_Set_Post(1,7); //----------------农历年nian(0);Lcd_Set_Post(2,0);//----------------------- 农历日月LCD_WRITE_CHAR("农历");Conversion(0,time_buf[1],time_buf[2],time_buf[3]);TransferData(month_moon/16+'0',1);TransferData(month_moon%16+'0',1);TransferData('/',1);TransferData(day_moon/16+'0',1);TransferData(day_moon%16+'0',1);}if(state[0]==1){Lcd_Set_Post(3,5);}else {Lcd_Set_Post(2,5);}LCD_WRITE_CHAR("星期");//----------------------星期if(time_buf1[7]==7) {LCD_WRITE_CHAR("日");}if(time_buf1[7]==6) {LCD_WRITE_CHAR("六");}if(time_buf1[7]==5) {LCD_WRITE_CHAR("五");}if(time_buf1[7]==4) {LCD_WRITE_CHAR("四");}if(time_buf1[7]==3) {LCD_WRITE_CHAR("三");}if(time_buf1[7]==2) {LCD_WRITE_CHAR("二");}if(time_buf1[7]==1) {LCD_WRITE_CHAR("一");}Lcd_Set_Post(3,0);TransferData(shishi+48,1);//----------------------时TransferData(geshi+48,1);TransferData(58,1);TransferData(shifen+48,1);//----------------------分TransferData(gefen+48,1);TransferData(58,1);TransferData(shimiao+48,1);//----------------------秒TransferData(gemiao+48,1);if(state[0]==0){bai=(temph/100); //---------------------------------温度shi=(temph%100)/10;ge=(temph%100)%10;Lcd_Set_Post(3,4);if(zerotemp==0){TransferData(' ',1);TransferData(' ',1);} Lcd_Set_Post(3,5);TransferData(shi+48,1);TransferData(ge+48,1);TransferData('.',1);TransferData(templ+48,1);TransferData(0xa1,1);TransferData(0xe6,1);Lcd_Set_Post(4,0);festival(time_buf[2],time_buf[3],time_buf[4]);//农历}}if(num==3)//----------主菜单{Lcd_Set_Post(1,0);//--------设置显示位置LCD_WRITE_CHAR(mainmenu);}if(num==4)//----------设置菜单{Lcd_Set_Post(1,0);//--------设置显示位置LCD_WRITE_CHAR(setmenu);}if(num==5)//----------时间设置{Lcd_Set_Post(1,2);//--------设置显示位置LCD_WRITE_CHAR("时间设置");Lcd_Set_Post(2,1);TransferData(shinian+48,1);//----------------------年TransferData(genian+48,1);LCD_WRITE_CHAR("年");TransferData(shiyue+48,1);//----------------------月TransferData(geyue+48,1);LCD_WRITE_CHAR("月");TransferData(shiri+48,1);//----------------------日TransferData(geri+48,1);LCD_WRITE_CHAR("日");TransferData(time_buf1[7]+48,1);//---------------星期Lcd_Set_Post(3,2);TransferData(shishi+48,1);//--------------------时TransferData(geshi+48,1);LCD_WRITE_CHAR("时");TransferData(shifen+48,1);//---------------------分TransferData(gefen+48,1);LCD_WRITE_CHAR("分");TransferData(shimiao+48,1);//--------------------秒TransferData(gemiao+48,1);}if(num==6)//----------秒表{uchar shi1,shi2,shi3,ge1,ge2,ge3;Lcd_Set_Post(1,3);//--------设置显示位置LCD_WRITE_CHAR("秒表");Lcd_Set_Post(3,2);shi1=fen/10;ge1=fen%10;TransferData(shi1+48,1);TransferData(ge1+48,1);TransferData(':',1);shi2=miao/10;ge2=miao%10;TransferData(shi2+48,1);TransferData(ge2+48,1);TransferData(':',1);shi3=xiaomiao/10;ge3=xiaomiao%10;TransferData(shi3+48,1);TransferData(ge3+48,1);}if(num==8){Lcd_Set_Post(1,2);//--------农历查询LCD_WRITE_CHAR("温度查询");Lcd_Set_Post(3,0);//--------农历查询LCD_WRITE_CHAR("最高温度"); TransferData(':',1);RdFromROM(Number,0,4);if(Number[3]==0){TransferData('-',1);}Lcd_Set_Post(3,5);TransferData(Number[0]+48,1); TransferData(Number[1]+48,1); TransferData('.',1);TransferData(Number[2]+48,1); TransferData(0xa1,1);TransferData(0xe6,1); Lcd_Set_Post(4,0);//--------农历查询LCD_WRITE_CHAR("最低温度"); TransferData(':',1);RdFromROM(Number,4,4);if(Number[3]==0){TransferData('-',1);}Lcd_Set_Post(4,5);TransferData(Number[0]+48,1); TransferData(Number[1]+48,1); TransferData('.',1);TransferData(Number[2]+48,1); TransferData(0xa1,1);TransferData(0xe6,1); }if(num==9)//----------界面菜单{Lcd_Set_Post(1,2);//--------设置显示位置LCD_WRITE_CHAR("界面选择");Lcd_Set_Post(2,0);TransferData(1+48,1);TransferData('.',1);LCD_WRITE_CHAR("多功能界面");Lcd_Set_Post(3,0);TransferData(2+48,1);TransferData('.',1);LCD_WRITE_CHAR("简洁界面");}。
基于51单片机的12864万年历
#include <reg51.h> // 该程序具有显示日期、月份、日期和时间功能#include<stdio.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned int#define sint signed int#define disp_off 0x3e //显示关#define disp_on 0x3f //显示开#define disp_x 0xb8 //页地址为0页#define disp_z 0xc0 //行地址为0行#define disp_y 0x40 //列地址为0列#define comm 0 //命令标志位#define dat1 1 //数据标志位#define data_ora P0 //液晶12864的数据端与单片机的P0相连sbit di =P2^0; //Data or Instrument Select,H:写数据,L:写指令sbit rw =P2^1; //Write or Read,H:read,L:writesbit e =P2^4; //读写使能sbit cs1=P2^2; //cs1=H,选择左半屏sbit cs2=P2^3; //cs2=H,选择右半屏sbit clk=P1^0; //8563 clksbit dat=P1^1; //8563 datauchar fen=0x42,miao=0x38,shi=0x17,riqi=0x02,//设置时间用yuefen=0x09,xingqi=0x00,nian=0x07,zhongduan;//设置时间用uchar code tabma[10][16]=//阴码点阵格式、取模方式为列行式、逆向取模(低位在前),//十六进制输出,中文16*16,英文8*16 宋体{//0(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) 7(7) 8(8) 9(9){0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00}, /*"0",0*/{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00}, /*"1",1*/{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00}, /*"2",2*/{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00}, /*"3",3*/{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00}, /*"4",4*/{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00}, /*"5",5*/{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00}, /*"6",6*/{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00}, /*"7",7*/{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00}, /*"8",8*/{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00}, /*"9",9*/ };uchar code tab2ma[7][32]=// 日(0) 一(1) 二(2) 三(3) 四(4) 五(5) 六(6){{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}, /*"日",0*/{0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, /*"一",1*/{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}, /*"二",2*/{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}, /*"三",3*/{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}, /*"四",4*/{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}, /*"五",5*/{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}, /*"六",6*/ };uchar code nianma[]=//年(0) 月(1) 日(2) 星(3) 期(4){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}; /*"年",0*/ uchar code yuema[]={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}; /*"月",1*/ uchar code rima[]={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}; /*"日",2*/ uchar code xingqima[]={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, /*"星",3*/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}; /*"期",4*///时(0) 分(1) 秒(2)uchar code shima[]={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}; /*"时",0*/uchar code fenma[]={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}; /*"分",1*/uchar code miaoma[]={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}; /*"秒",2*/void delay(sint n); //延时程序void xie_start(); //开始条件void xie_stop(); //停止条件bit xie1(uchar shu); //向8563中写入1个字uchar du1(); //从8563中读出1个字uchar du(); //从8563中读出时间和日期uchar xie(); //向8563中设置时间和日期//uchar xie_dingshi(); //8563定时器设置//uchar xie_fangbo_dingshi(); //8563的方波设置void delay1 (uint ms); //延时void wr_lcd (uchar dat_comm,uchar content); //向12864中写命令//uchar rd_lcd (); //读12864数据void chk_busy (); //忙闲检测void lat_disp (uchar data1,uchar data2); //写点钟//void img_disp (uchar code *img) ; //显示图像void chn_disp (uchar x,uchar y,uchar xl,uchar yl,uchar row_xl,uchar row_yl,uchar code *chn);//显示汉字void init_lcd (); //12864初始化void disp(); //128显示程序//-------------主函数--------------------void main(){uchar ml=0;init_lcd (); //LCD初始化lat_disp(0x00,0x00);xie(); //预设时间用,设置好时间后可以屏蔽for(;;){du(); //读8563的时间lat_disp(0x00,0x00);disp(); //显示时间delay1(100);}}//-------------------延时---------------------------//void delay(sint n){for(n;n>0;n--);}/////////////////////以下是PCF8563读写/////////////////////以下是PCF8563读写/* I2C的起始条件,在时钟端SCK为高电平时,数据端SDA发生由高到低的变化,为起始条件,启动I2C总线。
12864LCD万年历
12864LCD+DS1302万年历设计proteus仿真(2011-05-18 23:09:40)标签:it原理图程序代码//DS1302与12864设计的可调式电子日历与时钟//#include<reg51.h>#include<intrins.h>#include<string.h>#define uchar unsigned char#define uint unsigned intextern void LCD_Initialize();extern void Display_A_Char_8x16(ucharP,ucharL,uchar *M)reentrant; extern void Display_A_WORD(ucharP,ucharL,uchar *M)reentrant;//在调整日期时间时,用该位决定是否反白显示//extern bit Reverse_Display;sbit SDA =P1^0; //DS1302数据线sbit CLK =P1^1; //DS1302时钟线sbit RST =P1^2; //DS1302复位线sbit K1 =P3^4; //选择sbit K2 =P3^5; //加sbit K3 =P3^6; //减sbit K4 =P3^7; //确定uchartCount =0;//一年中每月的天数,2月的天数由年份决定ucharMonthsDays[]={0,31,0,31,30,31,30,31,31,30,31,30,31};//所读取的日期时间ucharDateTime[7];//当前调整的时间对象:秒,分,时,日,月,年(0,1,2,3,4,6)//5对应星期,星期调节由年月日调整自动完成char Adjust_Index=-1;//水平与垂直偏移ucharH_Offset=10,V_Page_Offset=0;//年月日,星期,时分秒汉字点阵(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,//0x00,0x02,0x02,0xF2,0x12,0x12,0x12,0x12,0xF2,0x02,0x02,0x02,0xFE,0x02,0x02,0x00, 0x00,0x00,0x00,0x07,0x02,0x02,0x02,0x02,0x07,0x10,0x20,0x40,0x3F,0x00,0x00,0x00,//0x20,0x21,0xEE,0x04,0x00,0x00,0xFF,0x29,0xA9,0xBF,0xA9,0xA9,0x01,0xFF,0x00,0x00, 0x00,0x00,0x1F,0x88,0x44,0x30,0x0F,0x00,0x0F,0x04,0x04,0x4F,0x80,0x7F,0x00,0x00,//0x00,0x02,0x02,0x02,0x02,0x82,0x7E,0x22,0x22,0x22,0x22,0xF2,0x22,0x02,0x02,0x00,0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x20,0x60,0x20,0x1F,0x00,0x00,0x00,0x00,//0x00,0x00,0xFE,0x02,0x22,0x22,0x22,0x22,0xFA,0x22,0x22,0x22,0xE2,0x02,0x02,0x00, 0x40,0x30,0x0F,0x00,0x40,0x20,0x18,0x06,0x01,0x00,0x20,0x60,0x3F,0x00,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,//0x42,0x42,0xFE,0x42,0x42,0xE0,0x00,0xFF,0x00,0x42,0x42,0xFE,0x42,0x42,0x42,0x00, 0x10,0x10,0x0F,0x88,0x49,0x20,0x18,0x07,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x00,//0x00,0xFE,0x22,0x52,0x8E,0x00,0xC4,0xB4,0x8C,0xE7,0x84,0x84,0x84,0x84,0x04,0x00, 0x00,0xFF,0x02,0x04,0x23,0x10,0x0C,0x40,0x80,0x7F,0x00,0x02,0x04,0x18,0x30,0x00,/0x00,0x10,0x10,0x92,0x72,0xA2,0xA2,0xF2,0xAA,0xAA,0x66,0xA2,0x12,0x18,0x00,0x00, 0x10,0x08,0x06,0x01,0x04,0x44,0x84,0x7F,0x04,0x04,0x04,0x01,0x06,0x18,0x08,0x00,};//星期几的汉字点阵(16*16)uchar code WEEKDAY[]={//0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,///0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,///0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,///0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,};//半角数字点阵(8*16)uchar code DIGITS[]={////0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,///0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,///0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,///0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00, };//向DS1302写、读一字节--------//向DS1302写入一字节void Write_A_Byte_TO_DS1302(uchar x){uchar i;for (i=0;i<8;i++){SDA=x&1;CLK=1;CLK=0;x>>=1;}}//从DS1302读取一字节uchar Get_A_Byte_FROM_DS1302(){uchari,b,t;for(i=0;i<8;i++){b>>=1;t=SDA;b|=t<<7;CLK=1;CLK=0;}//BCD码转换return b/16*10+b;}//DS1302指定位置读数据ucharRead_Data(ucharaddr){uchardat;RST=0;CLK=0;RST=1;Write_A_Byte_TO_DS1302(addr);dat=Get_A_Byte_FROM_DS1302();CLK=1;RST=0;return dat;}//向DS1302某地址写入数据void Write_DS1302(ucharaddr,uchardat){CLK=0;RST=1;Write_A_Byte_TO_DS1302(addr);Write_A_Byte_TO_DS1302(dat);CLK=0;RST=0;}//设置时间void SET_DS1302(){uchar i;Write_DS1302(0x8E,0x00);//秒分时日月年依次写入for(i=0;i<7;i++){//秒的起始地址10000000(0x80),//后续依次是分,时,日,月,周,年,写入地址每次递增2 Write_DS1302(0x80+2*i,(DateTime[i]/10<<4)|(DateTime[i])); }Write_DS1302(0x8E,0x80);}//读取当前日期时间void GetTime(){uchar i;for(i=0;i<7;i++){DateTime[i]=Read_Data(0x81+2*i);}}//判断是否为闰年ucharisLeapYear(uint y){return(y%4==0&&y0!=0)||(y@0==0);}//----------------------------------------void RefreshWeekDay(){uinti,d,w=5;for(i=2000;i<2000+DateTime[6];i++){d=isLeapYear(i)?366:365;w=(w+d)%7;}d=0;for (i=1;i<DateTime[4];i++)d+=MonthsDays[i];d+=DateTime[3];DateTime[5]=(w+d)%7+1;}//年月日时分秒++--void DateTime_Adjust(char x){switch(Adjust_Index){case 6://年00-99if(x==1&&DateTime[6]<99) DateTime[6]++;if(x==-1&&DateTime[6]>0)DateTime[6]--;//获取2月天数MonthsDays[2]=isLeapYear(2000+DateTime[6])?29:28; //如果年份变化后当前月份的天数大于上限则设为上限if(DateTime[3]>MonthsDays[DateTime[4]])DateTime[3]=MonthsDays[DateTime[4]];RefreshWeekDay();//刷新星期break;case 4://月01-12if(x==1&&DateTime[4]<12)DateTime[4]++;if(x==-1&&DateTime[4]>1)DateTime[4]--;//获取2月天数MonthsDays[2]=isLeapYear(2000+DateTime[6])?29:28;//如果年份变化后当前月份的天数大于上限则设为上限if(DateTime[3]>MonthsDays[DateTime[4]])DateTime[3]=MonthsDays[DateTime[4]];RefreshWeekDay();//刷新星期break;case 3://日00-28/29/30/31;调节前首先根据年份得出该年中2月的天数MonthsDays[2]=isLeapYear(2000+DateTime[6])?29:28;//根据当前月份决定调节日期的上限if(x==1&&DateTime[3]<MonthsDays[DateTime[4]])DateTime[3]++;if(x==-1&&DateTime[3]>0)DateTime[3]--;RefreshWeekDay();//刷新星期break;case 2://时if(x==1&&DateTime[2]<23)DateTime[2]++;if(x==-1&&DateTime[2]>0)DateTime[2]--;break;case 1://分if(x==1&&DateTime[1]<59)DateTime[1]++;if(x==-1&&DateTime[1]>0)DateTime[1]--;break;case 0://秒if(x==1&&DateTime[0] <59) DateTime[0]++;if(x==-1&&DateTime[0] >0) DateTime[0]--;break;}}//定时器0每秒刷新LCD显示void T0_INT() interrupt 1{TH0=-50000/256;TL0=-50000%6;if(++tCount!=2)return;tCount=0;//年(后两位)Reverse_Display=Adjust_Index==6;Display_A_Char_8x16(V_Page_Offset,16+H_Offset,DIGITS+DateTime[6]/10*16); Display_A_Char_8x16(V_Page_Offset,24+H_Offset,DIGITS+DateTime[6]*16);//月Reverse_Display=Adjust_Index==4;Display_A_Char_8x16(V_Page_Offset,48+H_Offset,DIGITS+DateTime[4]/10*16); Display_A_Char_8x16(V_Page_Offset,56+H_Offset,DIGITS+DateTime[4]*16);//日Reverse_Display=Adjust_Index==3;Display_A_Char_8x16(V_Page_Offset,80+H_Offset,DIGITS+DateTime[3]/10*16); Display_A_Char_8x16(V_Page_Offset,88+H_Offset,DIGITS+DateTime[3]*16);//星期Reverse_Display=Adjust_Index==5;Display_A_Char_8x16(V_Page_Offset+3,104+H_Offset, WEEKDAY+DateTime[5]*16-16);//时Reverse_Display=Adjust_Index==2;Display_A_Char_8x16(V_Page_Offset+6,16+H_Offset,DIGITS+DateTime[2]/10*16); Display_A_Char_8x16(V_Page_Offset+6,24+H_Offset,DIGITS+DateTime[2]*16);//分Reverse_Display=Adjust_Index==1;Display_A_Char_8x16(V_Page_Offset+6,48+H_Offset,DIGITS+DateTime[1]/10*16); Display_A_Char_8x16(V_Page_Offset+6,56+H_Offset,DIGITS+DateTime[1]*16);//秒Reverse_Display=Adjust_Index==0;Display_A_Char_8x16(V_Page_Offset+6,80+H_Offset,DIGITS+DateTime[0]/10*16); Display_A_Char_8x16(V_Page_Offset+6,88+H_Offset,DIGITS+DateTime[0]*16);} //键盘中断(INT0)void EX_INT0() interrupt 0{if (K1 == 0) //选择调整对象{if (Adjust_Index == -1 || Adjust_Index == 0) Adjust_Index = 7;Adjust_Index--;if (Adjust_Index == 5) Adjust_Index = 4; //跳过对星期的调整}elseif (K2 == 0)DateTime_Adjust( 1); //加elseif (K3 == 0)DateTime_Adjust( -1 ); //减elseif (K4 == 0) //确定{SET_DS1302();Adjust_Index = -1;}}void main(){//液晶初始化LCD_Initialize();//显示年的固定前两位Display_A_Char_8x16(V_Page_Offset,0+H_Offset,DIGITS+2*16);Display_A_Char_8x16(V_Page_Offset,8+H_Offset,DIGITS);//显示固定汉字:年月日,星期,时分秒Display_A_WORD(V_Page_Offset,32+H_Offset,DATE_TIME_WORDS+0*32); Display_A_WORD(V_Page_Offset,64+H_Offset,DATE_TIME_WORDS+1*32); Display_A_WORD(V_Page_Offset,96+H_Offset,DATE_TIME_WORDS+2*32); Display_A_WORD(V_Page_Offset+3,72+H_Offset,DATE_TIME_WORDS+3*32); Display_A_WORD(V_Page_Offset+3,88+H_Offset,DATE_TIME_WORDS+4*32); Display_A_WORD(V_Page_Offset+6,32+H_Offset,DATE_TIME_WORDS+5*32); Display_A_WORD(V_Page_Offset+6,64+H_Offset,DATE_TIME_WORDS+6*32); Display_A_WORD(V_Page_Offset+6,96+H_Offset,DATE_TIME_WORDS+7*32); Display_A_WORD(V_Page_Offset+2,0+H_Offset,DATE_TIME_WORDS+8*32); Display_A_WORD(V_Page_Offset+2,16+H_Offset,DATE_TIME_WORDS+9*32); Display_A_WORD(V_Page_Offset+2,32+H_Offset,DATE_TIME_WORDS+10*32); Display_A_WORD(V_Page_Offset+2,48+H_Offset,DATE_TIME_WORDS+11*32); Display_A_WORD(V_Page_Offset+4,0+H_Offset,DATE_TIME_WORDS+12*32); Display_A_WORD(V_Page_Offset+4,16+H_Offset,DATE_TIME_WORDS+13*32); Display_A_WORD(V_Page_Offset+4,32+H_Offset,DATE_TIME_WORDS+14*32); Display_A_WORD(V_Page_Offset+4,48+H_Offset,DATE_TIME_WORDS+15*32);//允许INT0,T0中断IE=0x83;IP=0x01;IT0=0x01;TH0=-50000/256;TL0=-50000/256;TR0=1;while(1){//如果未执行调整操作则正常读取当前时间if(Adjust_Index==-1)GetTime();}}// 名称:12864LCD显示驱动程序(不带字库)//------------------------------------------------------------- #include <reg51.h>#include <intrins.h>#define unchar 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 //列指令//液晶引脚定义sbit DI =P2^0 ;sbit RW =P2^1 ;sbit E =P2^2 ;sbit CS1 =P2^3 ;sbit CS2 =P2^4 ;sbit rst =P2^5 ;bit Reverse_Display =0;//----------------------------------------------------------- //检查LCD是否忙//-----------------------------------------------------------bit LCD_Check_Busy (){LCD_DB_PORT =0xFF;RW =1; _nop_(); DI =0;E =1;_nop_(); E =0;return (bit) (P0 & 0x80);}//-----------------------------------------------------------// 向LCD发送命令//-----------------------------------------------------------void LCD_Write_Command( unchar c){while (LCD_Check_Busy ());LCD_DB_PORT =0xFF; RW =0; _nop_();DI =0;LCD_DB_PORT = c; E =1; _nop_();E =0;}//-----------------------------------------------------------//向LCD发送数据//-----------------------------------------------------------//向LCD发送数据void LCD_Write_Data(uchar d ){while(LCD_Check_Busy());LCD_DB_PORT = 0xFF;RW = 0; _nop_();DI = 1;//根据Reverse_Display决定是否反相显示if (! Reverse_Display) LCD_DB_PORT = d; else LCD_DB_PORT = ~d;E = 1 ;_nop_(); E = 0;}//初始化LCDvoid LCD_Initialize(){CS1 = 1; CS2 = 1;LCD_Write_Command(0x38);LCD_Write_Command(0x0F);LCD_Write_Command(0x01);LCD_Write_Command(0x06);LCD_Write_Command(LCD_START_ROW);}void Common_Show(ucharP,ucharL,ucharW,uchar *r)reentrant {uchar i;if(L<64)//显示在左半屏或左右半屏{CS1=1; CS2=0;LCD_Write_Command( LCD_PAGE+P);LCD_Write_Command(LCD_COL + L);if(L+W<64){for(i=0;i<W;i++) LCD_Write_Data(r[i]);}else//如果月结则跨越左右半屏显示{for(i=0;i<64-L;i++) LCD_Write_Data(r[i]);CS1=0;CS2=1;LCD_Write_Command(LCD_PAGE+P);LCD_Write_Command(LCD_COL);for(i=64-L;i<W;i++) LCD_Write_Data(r[i]);}}else // 全屏显示在右半屏{CS1=0;CS2=1;LCD_Write_Command(LCD_PAGE + P);LCD_Write_Command(LCD_COL+L-64);for (i=0;i<W;i++)LCD_Write_Data(r[i]);}}//显示一个8X16点阵字符//void Display_A_Char_8X16(ucharP,ucharL,uchar *M) reentrant {Common_Show( P, L, 8, M );Common_Show( P +1,L,8,M+8 );}//显示一个16x16点阵汉字void Display_A_WORD(ucharP,ucharL,uchar *M) reentrant {Common_Show( P, L, 16, M); //显示汉字上半部分Common_Show( P + 1,L, 16, M +16); //显示汉字下半部分}。
基于12864的万年历加温度显示设计
基于12864的万年历加温度显示设计摘要本设计将制作一种基于单片机控制的带实时温度显示、具有定时功能的电子万年历。
传统的电子日历大都体积大,功耗大,显示不准确等特点。
为了缩小体积,减小功耗,使其变得小巧灵敏,本设计加入了时钟芯片DS1302,可对时间进行准确记时,同时可设置定时时间,实现定时功能。
另外本设计具有显示实时温度的功能。
传统的温度传感器系统大都采用放大、调理、A/D转换,转换后的数字信号送入计算机处理,处理电路复杂、可靠性相对较差,占用计算机的资源比较多。
本设计将采用DS18B20一线制数字温度传感器,可将温度信号直接转换成数字信号送给微处理器,电路简单,成本低,实现了时间温度同时显示的效果。
最后,温度和时间都将通过12864液晶显示器进行显示。
测试表明系统达到了设计要求的各项功能,各部分工作正常。
关键词时钟/温度检测/单片机/温度MICROCONTROLLER-BASHED CALENDER AND TEMPERATURE DISPLAY DESIGNABSTRACTThis design creates an electronic calendar with real-time temperature display and timing function based on single chip control. Most of traditional calendars are characterized by large size, high power consumption and inaccurate display. In order to reduce volume and power consumption and make calendars become small and exquisite, the design adds a clock chip DS1302, which can accurately record the time and set a regular time to achieve timing function. In addition, this design displays real-time temperature function. Traditional temperature sensor system is mostly amplified, recuperated and A / D converted. The converted digital signal is input the computer to be processed, but the processing circuit is complicated with relatively poor reliability and occupies more resources of the computer. This design uses the DS18B20 first-line system digital temperature sensor to directly convert the temperature signal into digital signal and send it the microprocessor, whose circuit is simple and low cost, achieving the displayed effect of time and temperature simultaneously. Finally, the temperature and time will be displayed through the 12864 liquid crystal display. The test indicates that the system has reached various functions of the design requirements and each part operates smoothly.KEY WORDS clock, temperature detection, SCM, temperature目录中文摘要 (I)英文摘要.................................................................................................... I I 1概论. (1)1.1万年历发展背景 (1)1.2电子万年历的特点 (1)1.3国内外现状、发展 (1)2系统基本方案选择和论证 (2)2.1单片机芯片的选择方案和论证 (2)2.2显示模块的选择方案和论证 (3)2.3时钟芯片的选择方案和论证 (4)2.4温度传感器的选择方案和论证 (4)2.5电路设计最终方案确定 (5)3系统硬件电路设计 (6)3.1系统功能模块划分 (6)3.2各单元模块功能分析及模块电路设计 (6)3.2.1时钟模块 (6)3.2.2 温度模块 (7)3.2.3显示模块 (10)3.2.5 独立键盘模块 (18)3.2.6蜂鸣器模块 (19)3.2.7单片机模块 (20)3.3电路原理图的绘制和电路的焊接 (23)3.3.1原理图绘制软件PROTEL (23)3.3.2 PCB制作 (23)3.3.3 元器件的焊接 (24)4 系统软件设计 (26)4.1 万年历软件系统的流程图 (26)4.2温度信息的采集 (27)4.3时钟的读取 (30)4.3.1 DS1302控制字节的说明 (30)4.3.2 DS1302时间日期寄存器及相应位定义 (31)4.3.3 DS1302数据的输入和输出 (31)4.3.4 DS1302读写部分(程序)部分 (32)4.4温度的显示控制 (32)4.5键盘模块 (34)4.6蜂鸣器模块 (34)5设计总结 (35)致谢 (36)参考文献 (37)附录 (38)1 概论1.1 万年历发展背景随着电子技术的发展,人类不断研究,不断创新纪录。
万年历12864,键盘控制,新手
#include<reg52.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned intchar Adjust_Flag=0;uchar shi,fen,miao,nian,yue,ri,week,temp,s1num; sbit ACC0=ACC^0;sbit ACC7=ACC^7;sbit T_CLK = P3^6; /*实时时钟时钟线引脚*/ sbit T_IO = P3^4; /*实时时钟数据线引脚*/ sbit T_RST = P3^5; /*实时时钟复位线引脚*/ #define lcddate P0sbit lcdrs=P2^4;sbit lcdrw=P2^5;sbit lcden=P2^6;sbit lcdpsb=P2^1;sbit key1=P3^0;sbit key2=P3^1;sbit key3=P3^2;uchar code table1[]=" 20 -- -- "; uchar code table2[]=" :: :: "; uchar code table3[]=" "; uchar code table4[]="我爱中国!!!!";uchar shi,fen,miao,nian,yue,ri,week,temp,s1num; void delay(uint x){uint i,j;for(i=x;i>0;i--)for(j=110;j>0;j--);}/*bit lcd_busy(){bit result;lcdrs = 0;lcdrw = 1;lcden = 1;_nop_();_nop_();_nop_();_nop_();result = (bit)(P0&0x80);lcden = 0;return result;}*/void write_com(uchar com){//while(lcd_busy());lcden=0;lcdrs=0;lcdrw=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}void write_date(uchar dat){//while(lcd_busy());lcden=0;lcdrs=1;lcdrw=0;P0=dat;delay(5);lcden=1;delay(5);lcden=0;}void lcd_init(){lcdpsb=1;write_com(0x30); //基本指令操作delay(5);write_com(0x0c); // 显示开,关光标delay(5);write_com(0x01); //清屏delay(5);}//时分秒显示子函数void write_sfm(uchar add,uchar dat)//向LCD写时分秒,有显示位置加、现示数据,两个参数{uchar gw,sw;gw=dat%10;//取得个位数字sw=dat/10;//取得十位数字write_com(0x90+add);write_date(0x30+sw);//数字+30得到该数字的LCD1602显示码write_date(0x30+gw);//数字+30得到该数字的LCD1602显示码}//-------------------------------------//年月日显示子函数void write_nyr(uchar add,uchar dat)//向LCD写年月日,有显示位置加数、显示数据,两个参数{uchar gw,sw;gw=dat%10;//取得个位数字sw=dat/10;//取得十位数字write_com(0x80+add);//设定显示位置为第一个位置+addwrite_date(0x30+sw);//数字+30得到该数字的LCD1602显示码write_date(0x30+gw);//数字+30得到该数字的LCD1602显示码}//-------------------------------------------void write_week(uchar week)//写星期函数{write_com(0x88+3);//星期字符的显示位置switch(week){case 1:write_date('M');//delay(5);write_date('O');//delay(5);write_date('N');break;case 2:write_date('T');//delay(5);write_date('U');//delay(5);write_date('E');break;case 3:write_date('W');//delay(5);write_date('E');//delay(5);write_date('D');break;case 4:write_date('T');//delay(5);write_date('H');//delay(5);write_date('U');break;case 5:write_date('F');//delay(5);write_date('R');//delay(5);write_date('I');break;case 6:write_date('S');//delay(5);write_date('T');//delay(5);write_date('A');break;case 7:write_date('S');//delay(5);write_date('U');//delay(5);write_date('N');break;}}/******************************************************************** * 功能: 往DS1302写入1Byte数据********************************************************************* **/void write_byte(uchar dat){uchar i;ACC = dat;T_RST = 1;for(i=8; i>0; i--){T_IO = ACC0;T_CLK = 1;T_CLK = 0;ACC = ACC >> 1;}}/******************************************************************** * 功能: 从DS1302读取1Byte数据********************************************************************* **/uchar read_byte(void){uchar i;T_RST = 1;for(i=8; i>0; i--){ACC = ACC >>1;ACC7 = T_IO;T_CLK = 1;T_CLK = 0;}return(ACC);}/******************************************************************** * 名称: W1302(uchar Add, uchar dat)* 功能: 往DS1302写入数据********************************************************************* **/void W1302(uchar Add, uchar dat){T_RST = 0;T_CLK = 0;T_RST = 1;write_byte(Add); // 写地址_nop_();_nop_();write_byte(dat); // 写1Byte数据T_CLK = 1;T_RST = 0;}/******************************************************************** * 名称: R1302(uchar ucAddr)* 功能: 读取DS1302某地址的数据***********************************************************************/uchar R1302(uchar Add){int dat;T_RST = 0;T_CLK = 0;T_RST = 1;write_byte(Add); //写地址,命令_nop_();_nop_();dat = read_byte(); //读1Byte数据T_CLK = 1;T_RST = 0;return(dat);}/******************************************************************** * 名称: dectobcd(uchar dec)* 功能: DEC码转换为BCD码********************************************************************* **/uchar dectobcd(uchar dec){uchar bcd;bcd = 0;while(dec >= 10){dec -= 10;bcd++;}bcd <<= 4;bcd |= dec;return bcd;}/******************************************************************** * 功能: BCD码转换为DEC码********************************************************************* **/uchar bcdtodec(uchar bcd){uchar data1;data1 = bcd & 0x0f; //取BCD低4位bcd = bcd & 0x70; //剔除BCD的最高位和低4位。
基于51单片机的12864液晶显示的万年历
附录程序
/*****************说明*********************************** 基于 51 单片机的 12864 液晶显示的万年历
版权所有,如需转载请通知本人,不得用于商业用途 ,仅限学习交流之用
*****************************************************************/
3
图-1 主控制系统
2.3.2 时钟电路模块的设计 DS1302 是一种高性能、低功耗、带RAM的实时时钟电路,它可以对年、月、日、周日、
时、分、秒进行计时,具有闰年补偿功能,工作电压为2.5V~5.5V。采用三线接口与CPU进 行同步通信,并可采用突发方式一次传送多个字节的时钟信号或RAM数据。DS1302内部有一 个31×8的用于临时性存放数据的RAM寄存器。DS1302是DS1202的升级产品,与DS1202兼容, 但增加了主电源/后背电源双电源引脚,同时提供了对后背电源进行涓细电流充电的能力。
//延时 1MS/次
unsigned char
{
sec,min,hour,day,month,year,cen,week,
unsigned char i;
next,aa,bb,cc,dd,mm,temp0,LunarMonth,
while(--a)
LunarDay,LunarYear;
{
int temp;
9三三系统的软件设计系统的软件设计3131程序流程框图程序流程框图图图aa主程序流程图主程序流程图10图b计算阳历程序流程图计算阳历程序流程图1112图图cc时间调整程序流程图时间调整程序流程图yynnyynnyy图图dd设置温度报警闹钟的数据保存到设置温度报警闹钟的数据保存到at24c02at24c02中中是否进入温度报警上下限温度设置设置是否进入设置闹钟时间设置报警温度上下限开始设置闹钟的时间开始报警闹钟的开关是否开起at24c02存设置的功能保蜂鸣器开启闹钟报警功能开启结束设置13五五作品功能实现作品功能实现通过硬件的焊接与程序的编写本电子万年历终于完成了实现的功能如下
万年历初始源程序
12864、DS1302制作的电子万年历代码如下:/********************************************************************名称:电子万年历功能:自动计时100年,节日、时间提醒作者:甘春生实验板:KX-1N/******************************************************************** #include<reg52.h>#define uint unsigned int#define uchar unsigned charsbit RS=P2^0;sbit RW=P2^1;sbit EN=P2^2;sbit FUN=P1^0;sbit OK=P1^1;sbit INC=P1^2;sbit DEC=P1^3;sbit RST=P2^5;sbit IO=P2^6;sbit SCLK=P2^7;uchar hour=10;uchar min=18;uchar sec=30;uchar year=10;uchar mon=1;uchar date=20;uchar day=3;uchar count=0;uchar flag=0;uchar num=0;uchar i=6;void delay(uint i){uint j;for(;i>0;i--)for(j=0;j<125;j++);}void Write_Ds1302_Byte(uchar temp){uchar i;for(i=0;i<8;i++)SCLK=0;IO=temp&0x01;//只传最后一位temp>>=1;SCL=1;}}void Write_Ds1302(uchar address,uchar dat) {RST=0;SCLK=0;RST=1;Write_Ds1302_Byte(address);Write_Ds1302_Byte(dat);SCLK=1;RST=0;}uchar Read_Ds1302(uchar address){uchar i,temp=0x00;RST=0;SCLK=0;RST=1;Write_Ds1302_Byte(address);for(i=0;i<8;i++){temp>>=1;SCLK=0;if(IO)temp=temp|0x80;SCLK=1;}RST=0;IO=0;return temp;}void Check_Busy(void){RW=1;//RW=1为读RS=0;//RS=0为指令EN=1;while(P2&0X80);}void Write_com(uchar com)Check_Busy();RW=0;RS=0;P2=com;EN=1;delay(1);EN=0;}void Write_dat(uchar dat){Check_Busy();RW=0;RS=1;P2=dat;EN=1;delay(1);EN=0;}void Lcd_Pos(uchar Xpos,uchar Ypos){uchar tmp;Xpos&=0x0f;Ypos&=0x03;tmp=Xpos;if(Ypos==0)tmp|=0x80;if(Ypos==1)tmp|=0x90;if(Ypos==2)tmp|=0x88;if(Ypos==3)tmp|=0x98;Write_com(tmp);}void Write_LCD_String(uchar x,uchar y,uchar *s) {Lcd_Pos(x,y);Lcd_Pos(x,y);while (*s!='\0'){Write_dat(*s);s++;delay(1);}void LCD_Rst(void){Write_com(0x30);Check_Busy();Write_com(0x01);Write_com(0x06);Write_com(0x0c);delay(5);}void Write_day(uchar Sel){switch (Sel){case 1:Write_LCD_String(6,1,"一");break;case 2:Write_LCD_String(6,1,"二");break;case 3:Lcd_Pos(6,1);Write_dat(0xc8);Write_dat(0xfd);break;case 4:Write_LCD_String(6,1,"四");break;case 5:Write_LCD_String(6,1,"五");break;case 6:Write_LCD_String(6,1,"六");break;case 7:Write_LCD_String(6,1,"日");break;default :break;}}void Updat_Time(void){Lcd_Pos(3,0);Write_dat(0x30+(year/10));Write_dat(0x30+(year%10)); Lcd_Pos(0,1);Write_dat(0x30+(mon/10));Write_dat(0x30+(mon%10)); Lcd_Pos(2,1);Write_dat(0x30+(date/10));Write_dat(0x30+(date%10)); Lcd_Pos(0,2);Write_dat(0x30+(hour/10));Write_dat(0x30+(hour%10)); Lcd_Pos(2,2);Write_dat(0x30+(min/10));Write_dat(0x30+(min%10)); Lcd_Pos(4,2);Write_dat(0x30+(sec/10));Write_dat(0x30+(sec%10)); Write_day(day);}void Write_Time(void){Write_Ds1302(0x8e,0x00);Write_Ds1302(0x8c,(year/10)*16+year%10);Write_Ds1302(0x88,(mon/10)*16+mon%10);Write_Ds1302(0x86,(date/10)*16+date%10);Write_Ds1302(0x84,(hour/10)*16+hour%10);Write_Ds1302(0x82,(min/10)*16+min%10);Write_Ds1302(0x80,(sec/10)*16+sec%10);Write_Ds1302(0x8a,(day/10)*16+day%10);Write_Ds1302(0x8e,0x80);}void Read_Time(void){year=(Read_Ds1302(0x8d)>>4)*10+Read_Ds1302(0x8d)%16; mon=(Read_Ds1302(0x89)>>4)*10+Read_Ds1302(0x89)%16; date=(Read_Ds1302(0x87)>>4)*10+Read_Ds1302(0x87)%16; hour=(Read_Ds1302(0x85)>>4)*10+Read_Ds1302(0x85)%16; min=(Read_Ds1302(0x83)>>4)*10+Read_Ds1302(0x83)%16; sec=(Read_Ds1302(0x81)>>4)*10+Read_Ds1302(0x81)%16; day=(Read_Ds1302(0x8b)>>4)*10+Read_Ds1302(0x8b)%16; Updat_Time();}void Set_Time(void){if(FUN==0){delay(10);if(FUN==0){while(!FUN);flag=1;num++;if(num==8)num=1;}}if(flag){if(num==1){Lcd_Pos(0,2);Write_com(0x0d);if(INC==0){delay(10);if(INC==0){while(!INC);hour++;if(hour==24)hour=0;}}if(DEC==0){delay(10);if(DEC==0){while(!DEC);hour--;if(hour==-1)hour=23;Updat_Time();}}}if(num==2){Lcd_Pos(2,2);Write_com(0x0d);if(INC==0){delay(10);if(INC==0){while(!INC);min++;if(min==60)min=0;Updat_Time();}}if(DEC==0){delay(10);if(DEC==0){while(!DEC);min--;if(min==-1)min=59;}}}if(num==3){Lcd_Pos(4,2);Write_com(0x0d);if(INC==0){delay(10);if(INC==0){while(!INC);sec++;if(sec==60)sec=0;Updat_Time();}}if(DEC==0){delay(10);if(DEC==0){while(!DEC);sec--;if(sec==-1)sec=59;Updat_Time();}}}if(num==4){Lcd_Pos(3,0);Write_com(0x0d);if(INC==0){delay(10);if(INC==0){while(!INC);year++;year=0;Updat_Time();}}if(DEC==0){delay(10);if(DEC==0){while(!DEC);year--;if(year==-1)sec=99;Updat_Time();}}}if(num==5){Lcd_Pos(0,1);Write_com(0x0d); if(INC==0){delay(10);if(INC==0){while(!INC);mon++;if(mon==13)mon=1;Updat_Time();}}if(DEC==0){delay(10);if(DEC==0){while(!DEC);mon--;if(mon==0)mon=12;Updat_Time();}}}if(num==6){Lcd_Pos(2,1);Write_com(0x0d); if(INC==0){delay(10);if(INC==0){while(!INC);date++;if(date==32)date=1;Updat_Time();}}if(DEC==0){delay(10);if(DEC==0){while(!DEC);date--;if(date==0)date=31;Updat_Time();}}}if(num==7){Lcd_Pos(6,1);Write_com(0x0d); if(INC==0){delay(10);if(INC==0){while(!INC);day++;if(day==8)day=1;Updat_Time();}}if(DEC==0){delay(10);if(DEC==0){while(!DEC);day--;if(day==0)day=7;Updat_Time();}}}}if(OK==0){delay(10);if(OK==0){while(!OK);flag=0;num=0;Write_com(0x0c);Write_Time();}}}void Festival(void){if (mon == 1 && date== 1 ) { Write_LCD_String(0,3,"Happy New Year!!"); } elseif (mon == 1 && date== 28 ) { Write_LCD_String(0,3," 世界麻风日"); } elseif (mon == 2 && date== 2 ) { Write_LCD_String(0,3," 世界湿地日"); } elseif (mon == 2 && date== 13 ) { Write_LCD_String(0,3," 明天情人节了"); } elseif (mon == 2 && date== 14 ) { Write_LCD_String(0,3," 今天是情人节"); } elseif (mon == 3 && date== 1 ) { Write_LCD_String(0,3," 国际海豹日"); }elseif (mon == 3 && date== 3 ) { Write_LCD_String(0,3," 全国爱耳日"); } elseif (mon == 3 && date== 8 ) { Write_LCD_String(0,3," 3.8妇女节"); } elseif (mon == 3 && date== 12 ) { Write_LCD_String(0,3," 植树节"); } elseif (mon == 3 && date== 14 ) { Write_LCD_String(0,3," 国际警察日"); } elseif (mon == 3 && date== 15 ) { Write_LCD_String(0,3," 消费者权益日"); } elseif (mon == 3 && date== 17 ) { Write_LCD_String(0,3," 国际航海日"); } elseif (mon == 3 && date== 21 ) { Write_LCD_String(0,3," 世界森林日"); } elseif (mon == 3 && date== 22 ) { Write_LCD_String(0,3," 世界水日"); } elseif (mon == 3 && date== 23 ) { Write_LCD_String(0,3," 世界气象日"); } elseif (mon == 3 && date== 24 ) { Write_LCD_String(0,3,"世界防治结核病日"); } elseif (mon == 4 && date== 1 ) { Write_LCD_String(0,3,"愚人节小心上当"); } elseif (mon == 4 && date== 7 ) { Write_LCD_String(0,3," 世界卫生日"); } elseif (mon == 4 && date== 8 ) { Write_LCD_String(0,3," 复活节"); } elseif (mon == 4 && date== 13 ) { Write_LCD_String(0,3," 黑色星期五"); } elseif (mon == 5 && date== 1 ) { Write_LCD_String(0,3," 劳动节放假"); } elseif (mon == 5 && date== 4 ) { Write_LCD_String(0,3," 青年节"); } elseif (mon == 5 && date== 8 ) { Write_LCD_String(0,3," 世界红十字日"); } elseif (mon == 5 && date== 12 ) { Write_LCD_String(0,3," 国际护士节"); } elseif (mon == 5 && date== 5 ) { Write_LCD_String(0,3,"近日注意母亲节"); } // &nb, , , , , sp;elseif (mon == 5 && date== 15 ) { Write_LCD_String(0,3," 国际家庭日"); } elseif (mon == 5 && date== 31 ) { Write_LCD_String(0,3," 世界无烟日"); } elseelseif (mon == 6 && date== 5 ) { Write_LCD_String(0,3," 世界环境日"); } elseif (mon == 6 && date== 26 ) { Write_LCD_String(0,3," 国际禁毒日"); } elseif (mon == 6 && date== 6 ) { Write_LCD_String(0,3," 全国爱眼日"); } elseif (mon == 6 && date== 13 ) { Write_LCD_String(0,3,"近日注意父亲节"); } elseif (mon == 6 && date== 15 ) { Write_LCD_String(0,3,"近日注意父亲节"); } elseif (mon == 7 && date== 1 ) { Write_LCD_String(0,3,"香港回归记念日"); } elseif (mon == 7 && date== 7 ) { Write_LCD_String(0,3,"抗日战争记念日"); } elseif (mon == 7 && date== 11 ) { Write_LCD_String(0,3," 世界人口日"); } elseif (mon == 8 && date== 1 ) { Write_LCD_String(0,3," 八一建军节"); } elseif (mon == 8 && date== 8 ) { Write_LCD_String(0,3," 中国男子节"); } elseif (mon == 8 && date== 15 ) { Write_LCD_String(0,3,"抗战胜利记念日"); } elseif (mon == 9 && date== 10 ) { Write_LCD_String(0,3," 中国教师节"); } elseif (mon == 9 && date== 18 ) { Write_LCD_String(0,3,"九·一八事变记念"); } elseif (mon == 9 && date== 20 ) { Write_LCD_String(0,3," 国际爱牙日"); } elseif (mon == 9 && date== 27 ) { Write_LCD_String(0,3," 世界旅游日"); } elseif (mon == 10 && date== 1 ) { Write_LCD_String(0,3," 中国国庆节"); } elseif (mon == 10 && date== 4 ) { Write_LCD_String(0,3," 世界动物日"); } elseif (mon == 10 && date== 24 ){ Write_LCD_String(0,3," 联合国日"); } elseif (mon == 10 && date== 12 ){ Write_LCD_String(0,3,"明天国际教师节"); } elseif (mon == 10 && date== 13 ){ Write_LCD_String(0,3," 国际教师节"); } elseif (mon == 11 && date== 10 ){ Write_LCD_String(0,3," 世界青年节"); } elseelseif (mon == 12 && date== 1 ) { Write_LCD_String(0,3," 世界艾滋病日"); } elseif (mon == 12 && date== 23 ){ Write_LCD_String(0,3," 明晚平安夜"); }elseif (mon == 12 && date== 24 ){ Write_LCD_String(0,3," 今晚平安夜"); }elseif (mon == 12 && date== 25 ){ Write_LCD_String(0,3," 圣诞快乐"); }elseif (mon == 12 && date== 31 ){ Write_LCD_String(0,3," 明日新年"); }else{if(hour >= 4 && hour< 6 ) { Write_LCD_String(0,3,"★★__▲▲__凌晨"); } if(hour >= 6 && hour< 8 ) { Write_LCD_String(0,3,"☆○__▲△__早晨"); } if(hour >= 8 && hour< 12 ) { Write_LCD_String(0,3,"__●__▲▲__上午"); } if(hour == 12) { Write_LCD_String(0,3,"____▲●▲__中午"); }if(hour >= 13 && hour< 18 ){ Write_LCD_String(0,3,"__▲▲__●__下午"); } if(hour >= 18 && hour< 22 ){ Write_LCD_String(0,3,"△▲__●☆__晚上"); } if(hour >= 22 && hour<= 23 ){ Write_LCD_String(0,3,"△▲__★☆__夜里"); } if(hour >= 0 && hour< 4 ) { Write_LCD_String(0,3,"__★▲▲★__深夜"); } }}void System_Init(void){LCD_Rst();Write_LCD_String(0,1,"系统初始化");Lcd_Pos(5,1);while(i--){Write_dat(0x3e);delay(300);}Write_com(0x01);Write_LCD_String(0,1,"您好!欢迎使用!");delay(1500);Write_com(0x01);Write_LCD_String(2,0,"2010年");Write_LCD_String(0,1,"01月18日星期一");Write_LCD_String(0,2,"10时17分30秒");}void main(void){System_Init();Write_Time(); while(1){Set_Time();if(!flag){Read_Time();Festival();}}}。
12864 万年历设计报告
课程设计报告题目多功能数字钟课程名称电子系统设计与工程实践院部名称电子与信息工程学院专业电子信息工程班级电子1001班学生姓名李盖(1010910101)指导教师荣峰多功能数字钟完成人:李盖(电子1001)摘要:随着人类科技文明的发展,人们对于时钟的要求在不断地提高。
时钟已不仅仅被看成一种用来显示时间的工具,在很多实际应用中它还需要能够实现更多其它的功能。
高精度、多功能、小体积、低功耗,是现代时钟发展的趋势。
在此次设计中,电路具有显示时间的其本功能,还可以实现对时间的调整。
具有小巧,价格低廉,走时精度高,使用方便,功能多等特点。
本设计的控制核心是单片机(STC90C516RD+),采用蜂鸣器、液晶显示器(LCD12864)、及其他电路构成。
实现了时间设置、闹铃设置、闹铃开和关、显示节日、显示生日、显示农历、生日时播放音乐、整点报时以及温度采集等功能。
关键词:多功能时钟,温度采集,闹铃,农历,显示节日1、设计要求1.利用LCD显示“年、月、日、星期、时、分、秒”信息,并可通过键盘修改当前时间。
2.具有闹钟时间设置和闹铃功能,利用蜂鸣器进行闹铃。
当闹铃发生时,能够通过按键取消闹铃。
3.利用温度传感器检测环境温度,并显示在LCD上。
2、总体设计2.1系统组成系统由单片机主控模块、时钟模块、测温模块、报警模块、显示模块、键盘接口模块共6个模块组成,电路系统框图下图所示:图1 系统框图2.2工作原理本设计核心器件之一时钟芯片DS1302,其主要特点是采用串行数据传输,可为掉电保护电源提供可编程的充电功能,并且可以关闭充电功能。
采用普通32.768KHz晶振。
采用STC90C51作为主控芯片,利用它定期的读取时钟芯片DS1302中的时间并显示在LCD上;通过算法得出阴历日期并显示在LCD 上。
2.3用户至上的设计通过合理的布局,将键盘设置在LCD屏的下方,方便操作;其他的元路隐藏在LCD的后面使外观整洁简约。
12864万年历带闹钟和温度
基于51单片机的设计:源代码调试通过主函数部分:包含头文件,液晶18b20和DS1302的初始化#include<reg52.h>#include"12864.h"#include"ds1302.h"#include"18b20.h"#define uchar unsigned char#define uint unsigned intvoid main(){uchar i;lcd_init();b20_init();ds1302_init();ds1302_write_time();while(1){write_com(0x80);dis("★★mage心寒★★");get_temperature();b20_display();ds1302_read_time();for(i=1;i<8;i++)tempdata[i]=time_buf1[i];ds1302_display();}}12864控制部分:#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit rs=P2^4;sbit e=P2^6;sbit rw=P2^5;uchar i,j,num,aa;void delayms(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void write_com(uchar com) {rs=0;P0=com;delayms(5);e=1;delayms(5);e=0;}void write_data(uchar date) {rs=1;P0=date;delayms(5);e=1;delayms(5);e=0;}void dis(unsigned char code *s) { while(*s>0){ write_data(*s);s++;delayms(5);}}void lcd_init(){rw=0;e=0;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80);}/*lcd_display(){write_com(0x80);dis("12864 液晶,,,,");delayms(100);write_com(0x90);dis("安徽建筑工业学院");delayms(100);write_com(0x88);dis("电子创新实验室");delayms(100);write_com(0x98);dis("mage心寒");delayms(1000);write_com(0x01);}*/DS1302部分:#include<reg52.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned intuchar time_buf2[16];uchar tempdata[8];uchar num;sbit sck=P3^6;sbit sda=P3^4;sbit rst=P3^5;#define ds1302_sec_add 0x80 //秒数据地址#define ds1302_min_add 0x82 //分数据地址#define ds1302_hr_add 0x84 //时数据地址#define ds1302_date_add 0x86 //日数据地址#define ds1302_month_add 0x88 //月数据地址#define ds1302_day_add 0x8a //星期数据地址#define ds1302_year_add 0x8c //年数据地址#define ds1302_control_add 0x8e //控制数据地址#define ds1302_charger_add 0x90#define ds1302_clkburst_add 0xbeunsigned char time_buf1[] = {20,10,8,26,15,57,56,4};//年月日时分秒周unsigned char time_buf[16] ;//空年月日时分秒周/*向DS1302写入一字节数据*/void ds1302_write_byte(uchar add, uchar d) {uchar i;rst=1; /*启动DS1302总线*//*写入目标地址:addr*/add= add & 0xfe;/*最低位置零*/for (i = 0; i < 8; i ++) {if (add & 0x01) {sda=1;}else {sda=0;}sck=1;sck=0;add = add >> 1;}/*写入数据:d*/for (i = 0; i < 8; i ++) {if (d & 0x01) {sda=1;}else {sda=0;}sck=1;sck=0;d = d >> 1;}rst=0; /*停止DS1302总线*/ }/*从DS1302读出一字节数据*/uchar ds1302_read_byte(uchar add){uchar i;uchar temp;rst=1; /*启动DS1302总线*//*写入目标地址:addr*/add = add | 0x01;/*最低位置高*/for (i = 0; i < 8; i ++) {if (add & 0x01) {sda=1;;}else {sda=0;}sck=1;sck=0;add = add >> 1;}/*输出数据:temp*/for (i = 0; i < 8; i ++) {temp = temp >> 1;if (sda==1) {temp |= 0x80;}else {temp &= 0x7f;}sck=1;sck=0;}rst=0; /*停止DS1302总线*/return temp;}/*向DS302写入时钟数据*/void ds1302_write_time(){unsigned char i,tmp;for(i=1;i<8;i++){ //BCD处理tmp=time_buf1[i]/10;time_buf[i]=time_buf1[i]%10;time_buf[i]=time_buf[i]+tmp*16;}ds1302_write_byte(ds1302_control_add,0x00); //关闭写保护ds1302_write_byte(ds1302_sec_add,0x80); //暂停ds1302_write_byte(ds1302_charger_add,0xa9); //涓流充电ds1302_write_byte(ds1302_year_add,time_buf[1]); //年ds1302_write_byte(ds1302_month_add,time_buf[2]); //月ds1302_write_byte(ds1302_date_add,time_buf[3]); //日ds1302_write_byte(ds1302_hr_add,time_buf[4]); //时ds1302_write_byte(ds1302_min_add,time_buf[5]); //分ds1302_write_byte(ds1302_sec_add,time_buf[6]); //秒ds1302_write_byte(ds1302_day_add,time_buf[7]); //周ds1302_write_byte(ds1302_control_add,0x80); //打开写保护}/*从DS302读出时钟数据*/void ds1302_read_time(){uchar i,tmp;time_buf[1]=ds1302_read_byte(ds1302_year_add); //年time_buf[2]=ds1302_read_byte(ds1302_month_add); //月time_buf[3]=ds1302_read_byte(ds1302_date_add); //日time_buf[4]=ds1302_read_byte(ds1302_hr_add); //时time_buf[5]=ds1302_read_byte(ds1302_min_add); //分time_buf[6]=ds1302_read_byte(ds1302_sec_add); //秒time_buf[7]=ds1302_read_byte(ds1302_day_add); //周for(i=1;i<8;i++){ //BCD处理tmp=time_buf[i]/16;time_buf1[i]=time_buf[i]%16;time_buf1[i]=time_buf1[i]+tmp*10;}}/*DS302初始化函数*/void ds1302_init(){rst=0; /*RST脚置低*/sck=0; /*SCK脚置低*/}void write_sfm(uchar date){uchar shi,ge;shi=date/10;ge=date%10;//write_com(0x90+add);write_data(0x30+shi);write_data(0x30+ge);}void write_nyr(uchar date){uchar shi,ge;shi=date/10;ge=date%10;//write_com(0x90+add);write_data(0x30+shi);write_data(0x30+ge);}void write_xq(uchar date){//write_com(0x90+add);switch(date){case 1:write_data('M');break;case 2:write_data('T');break;case 3:write_data('W');break;case 4:write_data('T');break;case 5:write_data('F');break;case 6:write_data('S');break;case 7:write_data('s');break;}}void ds1302_display(){write_com(0x88);//write_nyr(tempdata[1]);write_nyr(tempdata[2]);write_data('-');write_nyr(tempdata[3]);write_data(' ');write_sfm(tempdata[4]);write_data(':');write_sfm(tempdata[5]);write_data(':');write_sfm(tempdata[6]);write_data(' ');write_xq(tempdata[7]);//if((tempdata[4]==0x13)&&(tempdata[5]==0x38)&&(tempdata[6]==0x00))//beez=1;//if((tempdata[4]==0x13)&&(tempdata[5]==0x38)&&(tempdata[6]==0x05))//beez=0;write_com(0x98);if ( tempdata[2] == 0x01 && tempdata[3] == 0x01 ){ dis("Happy New Y ear!!"); }//1月if ( tempdata[2] == 0x02 && tempdata[3] == 0x02 ){ dis(" 世界湿地日"); }//2月if ( tempdata[2] == 0x02 && tempdata[3] == 0x0d ){ dis(" 明天情人节了"); }if ( tempdata[2] == 0x02 && tempdata[3] == 0x0e ){ dis("今天是情人节"); }if ( tempdata[2] == 0x03 && tempdata[3] == 0x01 ){ dis(" 国际海豹日"); }//3月if ( tempdata[2] == 0x03 && tempdata[3] == 0x03 ){ dis(" 全国爱耳日"); }if ( tempdata[2] == 0x03 && tempdata[3] == 0x08 ){ dis(" 3.8妇女节"); }if ( tempdata[2] == 0x03 && tempdata[3] == 0x0c ){ dis("植树节"); }if ( tempdata[2] == 0x03 && tempdata[3] == 0x0e){ dis(" 国际警察日"); }if ( tempdata[2] == 0x03 && tempdata[3] == 0x0f ){ dis(" 消费者权益日"); }if ( tempdata[2] == 0x03 && tempdata[3] == 0x11 ){ dis(" 国际航海日"); }if ( tempdata[2] == 0x03 && tempdata[3] == 0x15 ){ dis(" 世界森林日"); }if ( tempdata[2] == 0x03 && tempdata[3] == 0x16 ){ dis(" 世界水日"); }if ( tempdata[2] == 0x03 && tempdata[3] == 0x17 ){ dis(" 世界气象日"); }if ( tempdata[2] == 0x03 && tempdata[3] == 0x18 ){ dis("世界防治结核病日"); }if ( tempdata[2] == 0x04 && tempdata[3] == 0x01 ){ dis("愚人节小心上当"); }//4if ( tempdata[2] == 0x04 && tempdata[3] == 0x07 ){ dis(" 世界卫生日"); }if ( tempdata[2] == 0x04 && tempdata[3] == 0x08 ){ dis(" 复活节"); }if ( tempdata[2] == 0x04 && tempdata[3] == 0x0d ){ dis(" 黑色星期五"); }if ( tempdata[2] == 0x05 && tempdata[3] == 0x01 ){ dis(" 劳动节放假"); }//5if ( tempdata[2] == 0x05 && tempdata[3] == 0x04 ){ dis(" 青年节"); }if ( tempdata[2] == 0x05 && tempdata[3] == 0x08 ){ dis(" 世界红十字日"); }if ( tempdata[2] == 0x05 && tempdata[3] == 0x05 ){ dis("近日注意母亲节"); }if ( tempdata[2] == 0x05 && tempdata[3] == 0x15 ){ dis(" 国际家庭日"); }if ( tempdata[2] == 0x05 && tempdata[3] == 0x1f ){ dis(" 世界无烟日"); }if ( tempdata[2] == 0x06 && tempdata[3] == 0x01 ){ dis(" 国际儿童节"); }//6 if ( tempdata[2] == 0x06 && tempdata[3] == 0x05 ){ dis(" 世界环境日"); }if ( tempdata[2] == 0x06 && tempdata[3] == 0x1a ){ dis("国际禁毒日"); }if ( tempdata[2] == 0x06 && tempdata[3] == 0x06 ){ dis(" 全国爱眼日"); }if ( tempdata[2] == 0x06 && tempdata[3] == 0x0d ){ dis("近日注意父亲节"); }if ( tempdata[2] == 0x06 && tempdata[3] == 0x0f ){ dis("近日注意父亲节"); }if ( tempdata[2] == 0x07 && tempdata[3] == 0x01 ){ dis("香港回归记念日"); }//7 if ( tempdata[2] == 0x07 && tempdata[3] == 0x07 ){ dis("抗日战争记念日"); }if ( tempdata[2] == 0x07 && tempdata[3] == 0x0b ){ dis(" 世界人口日"); }if ( tempdata[2] == 0x08 && tempdata[3] == 0x01 ){ dis(" 八一建军节"); }//8 if ( tempdata[2] == 0x08 && tempdata[3] == 0x08 ){ dis(" 中国男子节"); }if ( tempdata[2] == 0x08 && tempdata[3] == 0x0f ){ dis("抗战胜利记念日"); }if ( tempdata[2] == 0x09 && tempdata[3] == 0x10 ){ dis(" 中国教师节"); }//9 if ( tempdata[2] == 0x09 && tempdata[3] == 0x12 ){ dis("九·一八事变记念"); }if ( tempdata[2] == 0x09 && tempdata[3] == 0x14 ){ dis(" 国际爱牙日"); }if ( tempdata[2] == 0x09 && tempdata[3] == 0x1b ){ dis(" 世界旅游日"); }if ( tempdata[2] == 0x0a && tempdata[3] == 0x01 ){ dis("中国国庆节"); }//10 if ( tempdata[2] == 0x0a && tempdata[3] == 0x04 ){ dis("世界动物日"); }if ( tempdata[2] == 0x0a && tempdata[3] == 0x18 ){ dis("联合国日"); }if ( tempdata[2] == 0x0a && tempdata[3] == 0x0c ){ dis("明天国际教师节"); }if ( tempdata[2] == 0x0a && tempdata[3] == 0x0d ){ dis("国际教师节"); }if ( tempdata[2] == 0x0b && tempdata[3] == 0x0a ){ dis("世界青年节"); }//11 if ( tempdata[2] == 0x0b && tempdata[3] == 0x11 ){ dis(" 世界学生节"); }if ( tempdata[2] == 0x0c && tempdata[3] == 0x01 ){ dis("世界艾滋病日"); }//12 if ( tempdata[2] == 0x0c && tempdata[3] == 0x17 ){ dis("明晚平安夜"); }if ( tempdata[2] == 0x0c && tempdata[3] == 0x18 ){ dis("今晚平安夜"); }if ( tempdata[2] == 0x0c && tempdata[3] == 0x19 ){ dis("圣诞快乐"); }else{if ( tempdata[4] >= 0x04 && tempdata[4] <0x06 ){ dis("★★__▲▲__凌晨"); }if ( tempdata[4]>=0x06&&tempdata[4] <=0x08 ){ dis("☆○__▲△__早晨"); }if ( tempdata[4] >= 0x08 && tempdata[4] < 0x0c){ dis("__●__▲▲__上午"); }if ( tempdata[4] >= 0x0c&&tempdata[4]<=0x0d) { dis("____▲●▲__中午"); }if (tempdata[4] >= 0x0d&&tempdata[4] <0x12){ dis("__▲▲__●__下午"); }if (tempdata[4] >= 0x12&&tempdata[4] <0x16){ dis("△▲__●☆__晚上"); }if ( tempdata[4] >= 0x16&&tempdata[4] <=0x17){ dis("△▲__★☆__夜里"); }if ( tempdata[4] >= 0x00 && tempdata[4] <=0x04 ){ dis("__★▲▲★__深夜"); }}}DS18B20部分:#include<reg52.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义#include<math.h>#include<intrins.H>#define uchar unsigned char#define uint unsigned intsbit DQ=P1^3;//ds18b20 端口uint temp;uchar flag_get,count,num,minute,second,aa,bb,cc,dd,ee;uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //7段数码管段码表共阳void delay1(uchar MS);unsigned int ReadTemperature(void);void Init_DS18B20(void);unsigned char ReadOneChar(void);void WriteOneChar(unsigned char dat);void delay(unsigned int i);void b20_display(){write_com(0x90);dis("温度:");write_data(aa);//write_com(0x80+0x01);write_data(0x30+bb);//write_com(0x80+0x02);write_data(0x30+cc);//write_com(0x80+0x03);write_data(0x30+dd);//write_com(0x80+0x04);write_data('.');//write_com(0x80+0x05);write_data(0x30+ee);//write_com(0x80+0x06);write_data('C');//write_com(0x80+0x06);}void b20_init(){TMOD|=0x01;//定时器设置TH0=0xef;TL0=0xf0;IE=0x82;TR0=1;}void get_temperature(){unsigned char TempH,TempL;bb=TempH/100; //百位温度cc=(TempH%100)/10; //十位温度dd=(TempH%100)%10; //个位温度,带小数点ee=TempL;// display();if(flag_get==1) //定时读取当前温度{temp=ReadTemperature();if(temp&0x8000){aa='-';//负号标志temp=~temp; // 取反加1temp +=1;}elseaa='+';TempH=temp>>4;TempL=temp&0x0F;TempL=TempL*6/10;//小数近似处理flag_get=0;}}void tim(void) interrupt 1 using 1//中断,用于数码管扫描和温度检测间隔{TH0=0xef;//定时器重装值TL0=0xf0;num++;if (num==50){num=0;flag_get=1;//标志位有效second++;if(second>=60){second=0;minute++;}}}void delay(unsigned int i)//延时函数{while(i--); //延迟1us}void Init_DS18B20(void){unsigned char x=0;DQ = 1; //DQ复位delay(8); //稍做延时DQ = 0; //单片机将DQ拉低delay(80); //精确延时大于480usDQ = 1; //拉高总线delay(10);x=DQ; //稍做延时后如果x=0则初始化成功x=1则初始化失败delay(5);}/******************************************************************/ /* 读一个字节*/ /******************************************************************/ unsigned char ReadOneChar(void){unsigned char i=0;unsigned char dat = 0;for (i=8;i>0;i--){DQ = 0; // 给脉冲信号dat>>=1;DQ = 1; // 给脉冲信号if(DQ)dat|=0x80;delay(5);}return(dat);}/******************************************************************//* 写一个字节*//******************************************************************/ void WriteOneChar(unsigned char dat){unsigned char i=0;for (i=8; i>0; i--){DQ = 0;DQ = dat&0x01;delay(5);DQ = 1;dat>>=1;}delay(5);}/******************************************************************//* 读取温度*//******************************************************************/ unsigned int ReadTemperature(void){unsigned char a=0;unsigned int b=0;unsigned int t=0;Init_DS18B20();WriteOneChar(0xCC); // 跳过读序号列号的操作WriteOneChar(0x44); // 启动温度转换delay(200);Init_DS18B20();WriteOneChar(0xCC); //跳过读序号列号的操作WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器)前两个就是温度a=ReadOneChar(); //低位b=ReadOneChar(); //高位b<<=8; t=a+b;return(t); }。
项目五 12864液晶万年历制作
模块的驱动函数
任务一 12864液晶显示数字
3.12864液晶显示模块知识
(3)模块的使用——驱动函数
/******写命令到LCD函数 参数:cmd命令******/ void wcmd_12864(uchar cmd) //写命令到LCD函数 { check_busy_12864(); //忙状态检测 RS=0; //向LCD发送命令 RW=0; //写有效 E=1; //产生下降沿的高电平部分 DATAPORT=cmd; //命令字送LCD数据端口 E=1; //保持高电平短暂延时 E=0; //产生下降沿的低电平部分 }
任务二 12864液晶显示汉字和数字
2. C语言的指针知识
(4)使用指针的显示函数
/***参数:row起始页,col起始列,x水平像素,y纵向页数,s字模表****/
void disp_12864(uchar row,uchar { uchar i,j; if(col<64){CS1=1,CS2=0;} else{CS1=0,CS2=1;col-=64;} for(i=0;i<y;i++) { wcmd_12864(0xb8+row+i); wcmd_12864(0x40+col); for(j=0;j<x;j++) wdat_12864(s[i*x+j]); } }
1 0 0 0 0 1
0 0 0 0 0 0 0 0
模块带有显示缓存;单片机将代表点阵的亮或暗(1或0)的信息写入 到显示缓存中,LCD的行、列驱动器会自动扫描LCD点阵,保持用户期望的 显示效果。写入到显示缓存中的数据是按字节为单位来进行读写的。
任务一 12864液晶显示数字
LCD12864万年历主程序
tempL= read_byte();
tempH=read_byte();
return (tempH,tempL);
}
void display_ds18b20(void)
{
if(tempH>0x7f)
{tempL=~tempL+1;
tempH=~tempH;
fg=0;}
{k=0;z=0;}
}
if(s==0x31)
{
s=0x61;
if(k==1)
{
s=0x62;
year++;
if(year>99)
year=0;
}
}
if(s==0x32)
{
s=0x61;
if(k==1)
{
s=0x62;
month++;
if(month>12)
month=1;
}
}
if(s==0x33)
{
str4[10]=a[sdata%10];
str4[12]=a[xiaoshu1];
str4[13]=a[xiaoshu2];
str4[14]=0xA1;
str4[15]=0xE6;
}
/********ds1302********/
void read_rtc(void)
{
uchar i,*p;
p=read_rtc_address;
{
str1[13]=a[timedate[3]%16];
str1[12]=a[timedate[3]/16];
str1[9]=a[timedate[4]%16];
#51单片机12864万年历C语言
51单片机做的12864万年历Main.c#include "reg52.h"#include "macroconst.h"#include "keyscan.h"#include "screen.h"#include "18b20.h"#include "ds1302.h"#include "atao_12864.h"#include "24c02.h"idata unsigned char state1[1]。
unsigned char screennum=1。
//屏幕号#define time_task_sec 200 //节拍200Hz#define clock 24000000 //晶振#define max_task 4 //最大任务数idata unsigned char task_delay[4]。
#define task_delay0 time_task_sec/1 //2赫兹18b20 #define task_delay1 time_task_sec/5 //10赫兹屏幕#define task_delay2 time_task_sec/3 //4赫兹1302 #define task_delay3 time_task_sec/20 //20赫兹键盘void init(>{unsigned char i。
init18b20(>。
ds1302_init(>。
initina1(>。
//---------------------------LCD字库初始化程序 RdFromROM(state1,8,1>。
state[0]=state1[0]。
//-------界面RdFromROM(state1,15,1>。
基于单片机的12864显示万年历论文(带原理图和程序)
毕业设计(论文)论文题目:12864显示电子万年历系别:专业:班级:学号:学生姓名:指导教师:前言目录前言 (II)1绪论 (1)1.1 课题研究的背景 (1)1.2课题的研究目的与意义 (1)1.3课题解决的主要内容 (1)2系统的方案设计与论证 (4)2.1单片机芯片设计与论证 (4)方案1:采用51系列单片机作为系统控制器 (4)方案2:采用凌阳系列单片机作为系统的控制器 (4)2.2按键控制模块设计与论证 (4)2.3时钟模块设计与论证 (5)方案二:采用DS1302为计时时钟芯片 (5)方案三:采用DS12C887为计时时钟芯片 (5)2.4温度采集模块设计与论证 (5)2.5显示模块模块设计与论证 (5)3系统硬件的设计 (1)3.1 STC89C52单片机 (1)3.1.1 最小系统设计 (4)3.1.2 时钟电路 (4)3.1.3 复位电路 (5)3.2时钟芯片DS1302接口设计与性能分析 (5)3.2.1 DS1302性能简介 (5)3.2.2 DS1302接口电路设计 (1)3.3温度芯片DS18B20接口设计与性能分析 (3)3.3.1 DS18B20性能简介 (3)1.DS18B20的主要特性 (3)3.3.3 DS18B20的工作时序 (4)3.4 LCD显示模块 (1)3.4.1 液晶显示控制驱动器的特点 (1)3.4.2 液晶显示控制驱动器的引脚功能 (1)3.4.3 液晶显示控制驱动器的指令系统 (2)3.4.4 液晶显示控制驱动器的软件设计 (3)3.4.5 LCD12864的电路结构特点 (5)3.4.6 LCD12864的应用 (5)4系统软件的设计 (7)4.1主程序流程图的设计 (8)4.2程序设计 (1)4.2.1 DS1302读写程序设计 (1)4.2.2温度程序设计 (1)5系统的机体设计及调试 (2)5.1系统的模块组成 (2)5.2系统软件调试与仿真 (3)5.3系统硬件调试 (4)总结 (5)参考文献: (6)绪论摘要:本文介绍了基于STC89C52单片机的多功能电子万年历的硬件结构和软硬件设计方法。
带温度无字库12864的万年历程序之欧阳索引创编
SW08A15_带温度无字库12864的万年历程序欧阳家百(2021.03.07)文章来源:网络转载┊发布时间:2008-8-22 21:43:01 ┊浏览次数:283 本例程完成了万年历的显示,包括设置时间,农历,温度,1302的初始化以及帮助界面,采用不带字库的12864,所以整体程序比较大,编译完成后,不能在89C52中运行,建议使用89C54。
本程序还有很多冗杂之处,未做调整,全做抛砖引玉。
#include "reg52.h"#include "sw08a15.h"#include "1302.h"#include "12864.h"#include "intrins.h"uchar num,week;uchar timeNow[6];uint LunarCal;uchar SolarCalYear, SolarCalMonth, SolarCalDay;uchar times=0;uchar wendu=0;uchar code dian[32]={0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00,/*:*/};uchar code hz[][32]={{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},/*"年",0*/{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},/*"月",1*/{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},/*"日",2*/{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},/*"星",3*/{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},/*"期",4*/{0x00,0x20,0x18,0x08,0x88,0xE8,0x1F,0x6A,0x88,0x08,0x88,0xC8,0xA8,0x1C,0x08,0x00,0x08,0x04,0x02,0x41,0xFF,0x40,0x20,0x10,0x01,0x02,0x0D,0x18,0x70,0x20,0x20,0x00},/*"农",5*/{0x00,0x00,0xFE,0x02,0x22,0x22,0x22,0x22,0xFA,0x22,0x22,0x22,0xE2,0x02,0x02,0x00,0x40,0x30,0x0F,0x00,0x40,0x20,0x18,0x06,0x01,0x00,0x20,0x60,0x3F,0x00,0x00,0x00},/*"历",6*/{0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00, 0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00},/*"温",7*/{0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00, 0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00},/*"度",8*/{0x00,0x02,0x05,0xE2,0x18,0x04,0x02,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x40,0x40,0x40,0x40,0x40,0x20,0x18,0x00,0x00},/*"℃",9*/{0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00,0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00},/*"设",10*/{0x00,0x20,0x2F,0xA9,0xA9,0xAF,0xE9,0xB9,0xA9,0xAF,0xA9,0xA9,0x2F,0x20,0x00,0x00, 0x80,0x80,0x80,0xFF,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xFF,0x80,0x80,0x80,0x0 0},/*"置",11*/{0x00,0x20,0x2A,0x2A,0xAA,0x7F,0x2A,0x2A,0xAA,0x00,0xFE,0x42,0x9A,0xA6,0x42,0x00, 0x00,0x04,0x02,0x01,0x3E,0x02,0x02,0x02,0xFF,0x02,0x13,0x22,0x1E,0x00,0x00,0x00},/*"帮",12*/{0x00,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00,0x10,0x10,0x1F,0x11,0x11,0x09,0x4F,0x28,0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00},/*"助",13*/{0x40,0x40,0x42,0xCC,0x00,0x50,0x4E,0xC8,0x48,0x7F,0xC8,0x48,0x48,0x40,0x00,0x00,0x00,0x40,0x20,0x1F,0x20,0x48,0x46,0x41,0x40,0x40,0x47,0x48,0x48,0x4E,0x40,0x00},/*"选",14*/{0x08,0x08,0xFF,0x88,0x48,0x08,0x42,0x46,0x2A,0xD2,0x2A,0x46,0x42,0x80,0x80,0x00,0x42,0x81,0x7F,0x00,0x00,0x08,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x08,0x08,0x00},/*"择",15*/{0x20,0x21,0xEE,0x04,0x00,0x00,0xFF,0x29,0xA9,0xBF,0xA9,0xA9,0x01,0xFF,0x00,0x00, 0x00,0x00,0x1F,0x88,0x44,0x30,0x0F,0x00,0x0F,0x04,0x04,0x4F,0x80,0x7F,0x00,0x00},/*"调",16*/{0x00,0x04,0x74,0xD4,0xFF,0xD4,0x74,0x04,0x10,0x0C,0xB7,0x44,0xB4,0x0C,0x04,0x00, 0x00,0x42,0x43,0x7A,0x43,0x42,0x43,0x7E,0x4B,0x4B,0x4A,0x4A,0x42,0x43,0x01,0x00},/*"整",17*/{0x00,0x84,0xE4,0x5C,0x44,0xC4,0x10,0xF8,0x97,0x92,0xF2,0x9A,0x96,0xF2,0x00,0x00,0x01,0x00,0x3F,0x08,0x88,0x4F,0x30,0x0F,0x04,0x04,0x3F,0x44,0x84,0x7F,0x00,0x00},/*"确",18*/{0x40,0x41,0x42,0xCC,0x04,0x00,0x00,0x00,0x80,0x7F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x20,0x90,0x60,0x18,0x07,0x00,0x03,0x0C,0x30,0xC0,0x40,0x00},/*"认",19*/{0x40,0x42,0xDC,0x08,0x00,0x00,0xFE,0x52,0x92,0x12,0x12,0x92,0x73,0x02,0x00,0x00,0x40,0x20,0x1F,0x20,0x48,0x46,0x51,0x50,0x48,0x45,0x42,0x45,0x48,0x50,0x00,0x00},/*"返",20*/{0x00,0xFE,0x02,0x02,0xF2,0x12,0x12,0x12,0x12,0x12,0xF2,0x02,0x02,0xFE,0x00,0x00,0x00,0x7F,0x40,0x40,0x47,0x44,0x44,0x44,0x44,0x44,0x47,0x40,0x40,0x7F,0x00,0x00},/*"回",21*/{0x00,0x08,0x88,0xC9,0x2E,0x98,0x48,0x00,0x08,0x08,0xF8,0x08,0x08,0xFC,0x08,0x00,0x02,0x01,0x00,0x7F,0x01,0x02,0x44,0x20,0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00},/*"初",22*/{0x10,0x90,0x70,0x1F,0x12,0xF0,0x00,0x20,0x70,0x28,0x27,0x22,0x28,0x70,0x20,0x00,0x40,0x21,0x12,0x0C,0x06,0x09,0x30,0x00,0x7F,0x21,0x21,0x21,0x21,0x7F,0x00,0x00},/*"始",23*/{0x80,0x40,0x20,0xF8,0x07,0x02,0x00,0x00,0xFF,0xC0,0x60,0x30,0x1C,0x08,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x04,0x02,0x01,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,0x00},/*"化",24*/};uchar code weekCode[][32]={{0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"一",0*/{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},/*"二",1*/{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},/*"三",2*/{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},/*"四",3*/{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},/*"五",4*/{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},/*"六",5*/{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},/*"日",6*/};uchar code numberCode[][16]={{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",0*/{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"1",1*/ {0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",2*/ {0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},/*"3",3*/ {0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},/*"4",4*/ {0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},/*"5",5*/ {0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"6",6*/ {0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},/*"7",7*/ {0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",8*/ {0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00},/*"9",9*/ {0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20},/*"A",0*/ {0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00},/*"B",11*/ {0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00},/*"C",12*/ {0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00},/*"D",13*/ {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00},/*"E",14*/ {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00},/*"F",15*/ };/////////////////////农历数据/////////////////////////uchar code year_code[]={0x4d,0x4A,0xB8, //20010x0d,0x4A,0x4C, //20020x0d,0xA5,0x41, //20030x25,0xAA,0xB6, //20040x05,0x6A,0x49, //20050x02,0x5d,0x52, //2007 0x09,0x2d,0x47, //2008 0x5C,0x95,0xBA, //2009 0x0A,0x95,0x4e, //2010 0x0B,0x4A,0x43, //2011 0x4B,0x55,0x37, //2012 0x0A,0xd5,0x4A, //2013 0x95,0x5A,0xBf, //2014 0x04,0xBA,0x53, //2015 0x0A,0x5B,0x48, //2016 0x65,0x2B,0xBC, //2017 0x05,0x2B,0x50, //2018 0x0A,0x93,0x45, //2019 0x47,0x4A,0xB9, //2020 0x06,0xAA,0x4C, //2021 0x0A,0xd5,0x41, //2022 0x24,0xdA,0xB6, //2023 0x04,0xB6,0x4A, //2024 0x69,0x57,0x3d, //2025 0x0A,0x4e,0x51, //2026 0x0d,0x26,0x46, //2027 0x5e,0x93,0x3A, //2028 0x0d,0x53,0x4d, //20290x36,0xB5,0x37, //2031 0x09,0x6d,0x4B, //2032 0xB4,0xAe,0xBf, //2033 0x04,0xAd,0x53, //2034 0x0A,0x4d,0x48, //2035 0x6d,0x25,0xBC, //2036 0x0d,0x25,0x4f, //2037 0x0d,0x52,0x44, //2038 0x5d,0xAA,0x38, //2039 0x0B,0x5A,0x4C, //2040 0x05,0x6d,0x41, //2041 0x24,0xAd,0xB6, //2042 0x04,0x9B,0x4A, //2043 0x7A,0x4B,0xBe, //2044 0x0A,0x4B,0x51, //2045 0x0A,0xA5,0x46, //2046 0x5B,0x52,0xBA, //2047 0x06,0xd2,0x4e, //2048 0x0A,0xdA,0x42, //2049 0x35,0x5B,0x37, //2050 0x09,0x37,0x4B, //2051 0x84,0x97,0xC1, //2052 0x04,0x97,0x53, //20530x66,0xA5,0x3C, //2055 0x0e,0xA5,0x4f, //2056 0x06,0xB2,0x44, //2057 0x4A,0xB6,0x38, //2058 0x0A,0xAe,0x4C, //2059 0x09,0x2e,0x42, //2060 0x3C,0x97,0x35, //2061 0x0C,0x96,0x49, //2062 0x7d,0x4A,0xBd, //2063 0x0d,0x4A,0x51, //2064 0x0d,0xA5,0x45, //2065 0x55,0xAA,0xBA, //2066 0x05,0x6A,0x4e, //2067 0x0A,0x6d,0x43, //2068 0x45,0x2e,0xB7, //2069 0x05,0x2d,0x4B, //2070 0x8A,0x95,0xBf, //2071 0x0A,0x95,0x53, //2072 0x0B,0x4A,0x47, //2073 0x6B,0x55,0x3B, //2074 0x0A,0xd5,0x4f, //2075 0x05,0x5A,0x45, //2076 0x4A,0x5d,0x38, //20770x05,0x2B,0x42, //20790x3A,0x93,0xB6, //20800x06,0x93,0x49, //20810x77,0x29,0xBd, //20820x06,0xAA,0x51, //20830x0A,0xd5,0x46, //20840x54,0xdA,0xBA, //20850x04,0xB6,0x4e, //20860x0A,0x57,0x43, //20870x45,0x27,0x38, //20880x0d,0x26,0x4A, //20890x8e,0x93,0x3e, //20900x0d,0x52,0x52, //20910x0d,0xAA,0x47, //20920x66,0xB5,0x3B, //20930x05,0x6d,0x4f, //20940x04,0xAe,0x45, //20950x4A,0x4e,0xB9, //20960x0A,0x4d,0x4C, //20970x0d,0x15,0x41, //20980x2d,0x92,0xB5, //2099};uchar code day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};uint code day_code2[3]={0x111,0x130,0x14e};////////////////农历转换算法bit get_moon_day(uchar month_p,uint table_addr)//bit[15-9]--year,bit[8-5]--month,bit[4-0]--day {switch (month_p){case 1: {if((year_code[table_addr]&0x08)==0) return(0);else return(1);}case 2: {if((year_code[table_addr]&0x04)==0) return(0);else return(1);}case 3: {if((year_code[table_addr]&0x02)==0) return(0);else return(1);}case 4: {if((year_code[table_addr]&0x01)==0) return(0);else return(1);}case 5: {if((year_code[table_addr+1]&0x80)==0) return(0);else return(1);}case 6: {if((year_code[table_addr+1]&0x40)==0) return(0);else return(1);}case 7: {if((year_code[table_addr+1]&0x20)==0) return(0);else return(1);}case 8: {if((year_code[table_addr+1]&0x10)==0) return(0);else return(1);}case 9: {if((year_code[table_addr+1]&0x08)==0) return(0);else return(1);}case 10: {if((year_code[table_addr+1]&0x04)==0) return(0);else return(1);}case 11: {if((year_code[table_addr+1]&0x02)==0) return(0);else return(1);}case 12: {if((year_code[table_addr+1]&0x01)==0) return(0);else return(1);}case 13: {if((year_code[table_addr+2]&0x80)==0) return(0);else return(1);}}}uint Conversion(uchar year,uchar month,uchar day){uchar temp1,temp2,temp3,month_p;uint temp4,table_addr;uint dat_return,dat_buffer;bit flag_y;table_addr=(year-1)*3;temp1=year_code[table_addr+2]&0x60; temp1=_cror_(temp1,5);temp2=year_code[table_addr+2]&0x1f; if(temp1==0x1){temp3=temp2-1;}else{temp3=temp2+0x1f-1;}if (month<10){temp4=day_code1[month-1]+day-1;}else{temp4=day_code2[month-10]+day-1; }if ((month>0x2)&&(year%0x4==0)) {temp4+=1;}if (temp4>=temp3){temp4-=temp3;month=0x1;month_p=0x1;flag_y=0;if(get_moon_day(month_p,table_addr)==0)temp1=0x1d; else temp1=0x1e;temp2=year_code[table_addr]/16;while(temp4>=temp1){temp4-=temp1;month_p+=1;if(month==temp2){flag_y=~flag_y;if(flag_y==0)month+=1;}else month+=1;if(get_moon_day(month_p,table_addr)==0)temp1=0x1d;else temp1=0x1e;}day=temp4+1;}else{temp3-=temp4;year-=1;table_addr-=0x3;month=0xc;temp2=year_code[table_addr]/16;if (temp2==0)month_p=0xc;else month_p=0xd;flag_y=0;if(get_moon_day(month_p,table_addr)==0)temp1=0x1d; else temp1=0x1e;while(temp3>temp1){temp3-=temp1;month_p-=1;if(flag_y==0)month-=1;if(month==temp2)flag_y=~flag_y;if(get_moon_day(month_p,table_addr)==0)temp1=0x1d;else temp1=0x1e;}day=temp1-temp3+1;dat_buffer=0;dat_return=0;dat_buffer=(uint)year;dat_buffer<<=9;dat_return|=dat_buffer;dat_buffer=(uint)month;dat_buffer<<=5;dat_return|=dat_buffer;dat_return|=(uint)day;return dat_return;}/////////////////////////////////////温度函数///////////////////////////////////////////////////// Init_DS18B20(void){unsigned char x=0;DQ = 1; //DQ复位delay(8); //稍做延时DQ = 0; //单片机将DQ拉低delay(80); //精确延时大于480usDQ = 1; //拉高总线delay(14);x=DQ; //稍做延时后如果x=0则初始化成功x=1则初始化失败}//读一个字节ReadOneChar(void){unsigned char i=0;unsigned char dat = 0;for (i=8;i>0;i--){DQ = 0; // 给脉冲信号dat>>=1;DQ = 1; // 给脉冲信号if(DQ)dat|=0x80;delay(4);}return(dat);}//写一个字节WriteOneChar(unsigned char dat) {unsigned char i=0;for (i=8; i>0; i--){DQ = 0;DQ = dat&0x01;delay(5);DQ = 1;dat>>=1;}}//读取温度float ReadDQerature(void){unsigned char a=0;unsigned char b=0;unsigned int t=0;float tt=0;Init_DS18B20();WriteOneChar(0xCC); // 跳过读序号列号的操作WriteOneChar(0x44); // 启动温度转换Init_DS18B20();WriteOneChar(0xCC); //跳过读序号列号的操作WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器)前两个就是温度a=ReadOneChar();b=ReadOneChar();t=b;t<<=8;t=t|a;tt=t*0.0625;return(tt);}////////////////////////////////////////////////////////////////////////////////////////////////// void displayMessage(){hz_disp8(0,0,numberCode[2],0); //20hz_disp8(0,8,numberCode[0],0); //20hz_disp16(0,32,hz[0],0);//年hz_disp16(0,64,hz[1],0);//月hz_disp16(0,96,hz[2],0);//日hz_disp8(2,16,dian,0);//点hz_disp8(2,40,dian,0);//点hz_disp16(2,72,hz[3],0);//星hz_disp16(2,72+16,hz[4],0);//期hz_disp16(4,0,hz[5],0);//农hz_disp16(4,16,hz[6],0);//历hz_disp8(4,32,dian,0);//点hz_disp16(4,64,hz[1],0);//月hz_disp16(4,96,hz[2],0);//日hz_disp16(6,0,hz[7],0);//温hz_disp16(6,16,hz[8],0);//度hz_disp8(6,32,dian,0);//点hz_disp16(6,64,hz[9],0);//℃hz_disp16(6,80,hz[12],0);//帮hz_disp16(6,96,hz[13],0);//助hz_disp8(6,112,numberCode[15],0);//Fhz_disp8(6,120,numberCode[2],0);//2}////////////////////////////////////////////////////////////////////////////////////////////////// main(){int i=0;/*DsInit();*/delay(1000);init_lcd();Clr_Scr();EA=0;displayMessage();//定时器0设置TMOD=0x01;TH1=0x4c;TL1=0x00;EA=1;ET0=1;//允许计时器0TR0=1;//开始计时//外部中断0设置IT0=0;//低电平触发方式EX0=1;//允许中断0IT1=0;//低电平触发方式EX1=1;//允许中断1//本程序不使用点阵显示,所以关闭点阵显示,防止按键影响。
单片机制作的12864液晶万年历_C语言程序
#include<reg52.H>#include<intrins.h>#include<math.h>////////////////////////////////////////DS18B20#define uchar unsigned char#define uint unsigned intsbit DQ = P1 ^ 0; // 定义DS18B20的单总线#define Lcd_Bus P0sbit LCD_RS=P2^7; //数据/命令选择sbit LCD_RW=P2^6; //读写控制sbit LCD_EN=P2^5; //片选信号#define LCD_DA TA P0 //8 bit数据线#define LOW 0#define HIGH 1//初始化指令#define CLEAR_SCREEN 0x01 //清屏指令:清屏且AC值为00H#define AC_INIT 0x02 //将AC设置为00H。
且游标移到原点位置#define CURSE_ADD 0x06 //设定游标移到方向及图像整体移动方向(默认游标右移,图像整体不动)#define FUN_MODE 0x30 //工作模式:8位基本指令集#define DISPLAY_ON 0x0c //显示开,显示游标,且游标位置反白#define DISPLAY_OFF 0x08 //显示关#define CURSE_DIR 0x14 //游标向右移动:AC=AC+1#define SET_CG_AC 0x40 //设置AC,范围为:00H~3FH#define SET_DD_AC 0x80#define FUN_MODEK 0x36 //扩展指令集,8位指令#define X1address 0x80 //上半屏X轴起始地址#define X2address 0x88 //下半屏X轴起始地址#define Y address 0x80 //Y轴起始地址#define Set_Column 0x40#define Set_Page 0xB8uchar code shu[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};uchar code xingqi[]="星期";uchar code hanzishu[]="一二三四五六日";unsigned char TempData = 0;double DS18B20Data;uint jiemian=0;//////////////////////////////////////////DS1302sbit DS1302_RST = P1^4;sbit DS1302_IO = P1^3;sbit DS1302_SCK = P1^2;unsigned char table[]={0X00,0X18,0X0c,0X15,0X06,0X01,0X0a};//0s 24min 12hour 14ri 5yue 5zhou 2010nianunsigned char data table1[7];//uchar code table2[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};uchar code shuzi[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,};unsigned char aa,bb;uchar miaoge,miaoshi,fenge,fenshi,shige,shishi,rige,rishi,yuege,yueshi,zhou,niange,nianshi;uchar shezhinum=0;//unsigned char shi,ge;////////////////////////////////////////////////键盘扫描sbit key_mnue = P3^7;sbit key_jia = P2^0;sbit key_jian = P2^1;sbit key_enter= P2^2;uchar key_number=0;//int nian,yue,ri,shi,fen;/////////////////////////////////////////////////红外sbit HW_IRQ = P3 ^ 2; // 定义38KHz一体化红外接收头与CPU的连接unsigned char DT;static unsigned char data IRCode[3],IRCON,IRCON2;//////////////////////////////////////////////////蜂鸣器sbit BEEP =P1^1;/****************************************************************************** *************** 函数名称:DS18B20_Delay()* 功能:DS18B20软件延时专用* 入口参数:count 延时参数,值越大,延时越长* 出口参数:无******************************************************************************* **************/void DS18B20_Delay(uint count) //延时函数{while(count--);}/****************************************************************************** *************** 函数名称:DS18B20_Init()* 功能:DS18B20初始化* 入口参数:无* 出口参数:返回值为1则初始化成功* 返回值为0则初始化失败******************************************************************************* **************/uchar DS18B20_Init(void){uchar x = 0;DQ = 1; // DQ复位DS18B20_Delay(8); // 稍做延时DQ = 0; // 单片机将DQ拉低DS18B20_Delay(80); // 精确延时,大于480usDQ = 1; // 拉高总线DS18B20_Delay(14); // 稍做延时后x = DQ; // 若x=0则初始化成功,若x=1则初始化失败DS18B20_Delay(20);return (~x);}/****************************************************************************** *************** 函数名称:DS18B20_Read1Byte()* 功能:从DS18B20读一个字节* 入口参数:无* 出口参数:从DS18B20读出的一个字节******************************************************************************* **************/uchar DS18B20_Read1Byte(void){uchar i = 0;uchar dat = 0;for(i=8;i>0;i--){DQ = 0; // 给脉冲信号dat >>= 1;DQ = 1; // 给脉冲信号if(DQ) dat |= 0x80;DS18B20_Delay(4);}return (dat);}/****************************************************************************** *************** 函数名称:DS18B20_Write1Byte()* 功能:向DS18B20写一个字节* 入口参数:dat 要写入DS18B20的一字节数据* 出口参数:无******************************************************************************* **************/void DS18B20_Write1Byte(uchar dat){uchar i = 0;for(i=8;i>0;i--){DQ = 0;DQ = dat&0x01;DS18B20_Delay(5);DQ = 1;dat>>=1;}}/****************************************************************************** *************** 函数名称:Read_Disp_Temperature()* 功能:读取并显示温度* 入口参数:无* 出口参数:无******************************************************************************* **************/double Read_Disp_Temperature(void){uint a = 0, b = 0, c = 0,d = 0,e = 0, t = 0;double tt = 0;DS18B20_Init();DS18B20_Write1Byte(0xCC); // 跳过读序号列号的操作DS18B20_Write1Byte(0x44); // 启动温度转换DS18B20_Init();DS18B20_Write1Byte(0xCC); // 跳过读序号列号的操作DS18B20_Write1Byte(0xBE); // 读取温度寄存器a = DS18B20_Read1Byte();b = DS18B20_Read1Byte();t = b;t <<= 8;t = t | a;//tt = t * 0.0625;return t;}//***************************************************************** //函数名称:delay(uint t)延时函数。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
table_18b20[1]=shu_12864(b_18B20%10); //同上 ,个位
Write_Com_12864(0x8e);
Write_Dat_12864(table_18b20[0]);
Write_Dat_12864(table_18b20[1]);
Write_String_12864("℃");
}
}
}
uchar table_18b20[2];
uchar read_byte(void);
void write_byte(uchar dat);
void init_ds18b20(void);
uchar read_wendu(void);
//******************************************************
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define Writenian 0x8c
#define Writeyue 0x88
#define Writeri 0x86
IT1=1;
EA=1;
cs=0;
sclk=0;
sck_1302=0;
cs_1302=0;
P3=0xff;
Lcd_Init_12864();
WriteByte_1302(0x8e,0x00); //关闭写保护
WriteByte_1302(Writemiao,0x00);
case 4: Write_String_12864("校对时间: 时"); break;
case 5: Write_String_12864("校对时间: 分"); break;
case 6: Write_String_12864("校对时间: 秒"); break;
{
Write_Com_12864(0x99);
Write_String_12864(" ");
set_jia=0;
}
if(p30==0) //加
{
delay(1000);
if(p30==0)
{
table_1302[1]=ReadByte_1302(Writeyue+1); //读月
table_1302[0]=ReadByte_1302(Writenian+1);//读年
iii++;
if(iii==3)
{
iii=0;
b_18B20=read_wendu();
if(flag_set==1)
{
switch(set_jia)
{
case 1://设置年
table_1302[0]+=1;
if((table_1302[0]&0x0f)==10)
{
switch(set_jia)
{
case 1: Write_String_12864("校对时间: 年"); break;
case 2: Write_String_12864("校对时间: 月"); break;
case 3: Write_String_12864("校对时间: 日"); break;
//************************************************
//12864子程序,模拟串口发送
sbit cs=P2^3;
sbit sid=P2^4;
sbit sclk=P2^5;
sbit rest=P2^6;
uchar table_12864[14];//分别储存年月日时分秒周的十位和个位
WriteByte_1302(0x8e,0x80); //打开写保护
/*
WriteByte_1302(0x8e,0x00); //关闭写保护
WriteByte_1302(Writenian,0x11);
WriteByte_1302(Writeyue,0x08);
WriteByte_1302(Writeri,0x12);
//***************************************************
//***************************************************
main(void)
{
EX0=1;
IT0=1;
EX1=1;
uchar ii,iii; //主程序循环标志
void delay(uint t)
{
while(t--);
}
//******************************************************
//18B20子程序
uchar b_18B20;
sbit io_18b20=P3^4;
table_1302[0]&=0xf0;
table_1302[0]+=0x10;
}
if(table_1302[0]==0xa0)//年最大值为99
{
table_1302[0]=0x00;
}
WriteByte_1302(Writeshi,0x12);
WriteByte_1302(Writefen,0x11);
WriteByte_1302(Writemiao,0x00);
WriteByte_1302(WriteWeek,0x05);
WriteByte_1302(0x8e,0x80); */ //打开写保护
#define Writeshi 0x84
#define Writefen 0x82
#define Writemiao 0x80
#define WriteWeek 0x8a
#define nianshi 0
#define niange 1
#define yueshi 2
#define yuege 3
flag_set=0;
set_jia=0;
Write_Com_12864(0x99);
Write_String_12864(" ");
EA=1;
}
}
if(set_jia==9)//退出校对
void Write_String_12864(const uchar *p);//写字符串
uchar shu_12864(uchar dat);//转换ASCLL码
//*************************************************
//*************************************************
table_1302[4]=ReadByte_1302(Writefen+1); //读分
table_1302[3]=ReadByte_1302(Writeshi+1); //读时
table_1302[2]=ReadByte_1302(Writeri+1); //读日
#define rishi 4
#define rige 5
#define shishi 6
#define shige 7
#define fenshi 8
#define fenge 9
#define miaoshi 10
#define miaoge 11
#define week 12
case 7: Write_String_12864("校对时间: 周"); break;
default: Write_String_12864("校对完成! ");
EA=0;
WriteByte_1302(0x8e,0x00); //关闭写保护
WriteByte_1302(Writenian,table_1302[0]);
while(1)
{
ii++;
if(ii==3)
{
ii=0;
if(flag_set==0)
{
table_1302[6]=ReadByte_1302(WriteWeek+1);//读周
table_1302[5]=ReadByte_1302(Writemiao+1);//读秒
//1302时钟子程序
sbit io_1302=P2^0;
sbit cs_1302=P2^2;
sbit sck_1302=P2^1;
uchar table_1302[7];//分别存储年月日时分秒周
uchar ReadByte_1302(uchar addr);//读一个字节
void WriteByte_1302(uchar addr,uchar dat);//写一个节
break;
case 2: //设置月
table_1302[1]+=1;
if((table_1302[1]&0x0f)==10)