LCD12864单片机电子万年历程序(27页).doc
《LCD12864单片机电子万年历程序(27页).doc》由会员分享,可在线阅读,更多相关《LCD12864单片机电子万年历程序(27页).doc(27页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-LCD12864单片机电子万年历程序-第 27 页#include#include#define LCD_Data P0#define uchar unsigned charunsigned charsec,min,hour,day,month,year,cen,week,next,aa,bb,cc,dd,mm,temp0,LunarMonth,LunarDay,LunarYear;int temp;uchar tt=1;bit c_moon;bit cenbit=1;bit w;sbit LCD_RS=P20;sbit LCD_RW=P21;sbit LCD_E=P22;sbit PSB=
2、P23;sbit DS1302_CLK=P37;sbit DS1302_IO=P36;sbit DS1302_RST=P35;sbit DS18B20=P25;sbit speak=P27;sbit SetKey=P14; / 按键功能:设置sbit SureKey=P15; / 按键功能:确认sbit PlusKey=P16; / 按键功能:加sbit ReduceKey=P17; / 按键功能:减sbit scl=P11;sbit sda=P10;void DisplayShengXiao(void);void delay(unsigned int a)/ 延时 1MS/ 次unsigne
3、d char i;while(-a)for(i=0;i125;i+) ;void delayb(unsigned int count)while(count-);void delays()void start()sda=1;scl=1;delays();sda=0;delays();void stop()sda=0;scl=1;delays();sda=1;delays();void response()uchar i;while(sda=1)&i255)i+; /给应答信号 sda=0 ; 错误 ( while ( ( sda=0 )|i255 ) i+ ; )程序进入 while 死循环s
4、cl=1;delays();scl=0; / 没有这一步出错 , 如果没有 sda 将保持 0 状态,一直处于应答中 。程序停止。delays();void write24c02(uchar date)uchar temp,i;temp=date;for(i=0;i8;i+)scl=0;sda=temp&0x80;delays();scl=1;delays();temp=temp1;scl=0;delays();sda=1;delays();uchar read24c02()uchar k,i;scl=0;delays();sda=1;/ 仅仅是释放数据线,可有可无for(i=0;i8;i+)
5、scl=1;delays();k=k1;if(sda)k+;scl=0;delays();return k;void write_24c02add(ucharaddress,uchar date)start();write24c02(0xa0);response();write24c02(address);response();write24c02(date);response();stop();uchar read_24c02add(uchar address)uchar a;start();write24c02(0xa0);response();write24c02(address);re
6、sponse();start();write24c02(0xa1);response();a=read24c02();stop();return a;unsigned char DS18B20Init() unsigned char x;DS18B20=1;delayb(2);DS18B20=0;delayb(80);DS18B20=1;delayb(5);x=DS18B20;delayb(20);return x;unsigned char TempRead(void)unsigned char i,dat;DS18B20=1;delayb(1);for(i=0;i1;DS18B20=1;i
7、f(DS18B20)dat=dat|0x80;delayb(4);return dat;void TempWriteByte(unsigned chardat)unsigned int i;DS18B20=1;delayb(2);for(i=0;i1;delayb(2);int GetTemp()float tt;unsigned char a,b;DS18B20Init();TempWriteByte(0xcc);TempWriteByte(0x44);delayb(100);DS18B20Init();TempWriteByte(0xcc);TempWriteByte(0xbe);dela
8、yb(200);a=TempRead();b=TempRead();temp=b;temp0;i-)DS1302_IO=temp&0x01;DS1302_CLK=0;DS1302_CLK=1;temp=1;void WriteDs1302( unsigned charaddress,unsigned char dat )DS1302_RST=0;DS1302_CLK=0;DS1302_RST=1;delay(1);WriteDs1302Byte(address);WriteDs1302Byte(dat);DS1302_RST=0;unsigned char read_byte() unsign
9、ed char i;for(i=8;i0;i-)if(DS1302_IO)temp0=temp0|0x80;DS1302_CLK=1;DS1302_CLK=0;temp0=temp01;return temp0;unsigned char ReadDs1302(unsignedchar address)unsigned char temp;DS1302_RST=0;DS1302_CLK=0;DS1302_RST=1;WriteDs1302Byte(address);temp=read_byte();DS1302_RST=0;DS1302_CLK=1;return temp;void InitD
10、S1302()/ unsigned charSecond=ReadDs1302(0x80);/ if(Second&0x80)WriteDs1302(0x8e,0x00);delay(5);WriteDs1302(0x8c,0x10);/ 写入年份 10 年delay(5);WriteDs1302(0x8a,0x06);/ 写入星期 6delay(5);WriteDs1302(0x88,0x11);/ 定入月分 11 月delay(5);WriteDs1302(0x86,0x6);/ 写入日期 6 日delay(5);WriteDs1302(0x84,0x17);/ 写入小时 17 点dela
11、y(5);WriteDs1302(0x82,0x43);delay(5);WriteDs1302(0x80,0x00);/ 写入秒 30 秒delay(5);WriteDs1302(0x8e,0x80);/ 控制命令, WP 为 1, 禁止写操作/* 阳历对应的阴历数据,每年三字节 ,格式第一字 节 BIT7- 4 位表示闰月月份 ,为 0, 则无闰月, BIT3-0 对应阴历第 1-4 月的大小,第二字 节 BIT7- 0 对应阴历 第 5-1 2 月大小,第三字节 BIT7 表示阴历第 13 月大小月分对应的位为 1, 表示农历月大( 3 0天)为 0 表示小( 29 天)第三字 节 BI
12、T6- 5 表示春节的公历月份 ,BIT4-0 表示春节公历日期code unsigned char YearCode597=0x04,0xAe,0x53, /1901 00x0A,0x57,0x48, /1902 30x55,0x26,0xBd, /1903 60x0d,0x26,0x50, /1904 90x0d,0x95,0x44, /1905 120x46,0xAA,0xB9, /1906 150x05,0x6A,0x4d, /1907 180x09,0xAd,0x42, /1908 210x24,0xAe,0xB6, /19090x04,0xAe,0x4A, /19100x6A,0x
13、4d,0xBe, /19110x0A,0x4d,0x52, /19120x0d,0x25,0x46, /19130x5d,0x52,0xBA, /19140x0B,0x54,0x4e, /19150x0d,0x6A,0x43, /19160x29,0x6d,0x37, /19170x09,0x5B,0x4B, /19180x74,0x9B,0xC1, /19190x04,0x97,0x54, /19200x0A,0x4B,0x48, /19210x5B,0x25,0xBC, /19220x06,0xA5,0x50, /19230x06,0xd4,0x45, /19240x4A,0xdA,0xB
14、8, /19250x02,0xB6,0x4d, /19260x09,0x57,0x42, /19270x24,0x97,0xB7, /19280x04,0x97,0x4A, /19290x66,0x4B,0x3e, /19300x0d,0x4A,0x51, /19310x0e,0xA5,0x46, /19320x56,0xd4,0xBA, /19330x05,0xAd,0x4e, /19340x02,0xB6,0x44, /19350x39,0x37,0x38, /19360x09,0x2e,0x4B, /19370x7C,0x96,0xBf, /19380x0C,0x95,0x53, /19
15、390x0d,0x4A,0x48, /19400x6d,0xA5,0x3B, /19410x0B,0x55,0x4f, /19420x05,0x6A,0x45, /19430x4A,0xAd,0xB9, /19440x02,0x5d,0x4d, /19450x09,0x2d,0x42, /19460x2C,0x95,0xB6, /19470x0A,0x95,0x4A, /19480x7B,0x4A,0xBd, /19490x06,0xCA,0x51, /19500x0B,0x55,0x46, /19510x55,0x5A,0xBB, /19520x04,0xdA,0x4e, /19530x0A
16、,0x5B,0x43, /19540x35,0x2B,0xB8, /19550x05,0x2B,0x4C, /19560x8A,0x95,0x3f, /19570x0e,0x95,0x52, /19580x06,0xAA,0x48, /19590x7A,0xd5,0x3C, /19600x0A,0xB5,0x4f, /19610x04,0xB6,0x45, /19620x4A,0x57,0x39, /19630x0A,0x57,0x4d, /19640x05,0x26,0x42, /19650x3e,0x93,0x35, /19660x0d,0x95,0x49, /19670x75,0xAA,
17、0xBe, /19680x05,0x6A,0x51, /19690x09,0x6d,0x46, /19700x54,0xAe,0xBB, /19710x04,0xAd,0x4f, /19720x0A,0x4d,0x43, /19730x4d,0x26,0xB7, /19740x0d,0x25,0x4B, /19750x8d,0x52,0xBf, /19760x0B,0x54,0x52, /19770x0B,0x6A,0x47, /19780x69,0x6d,0x3C, /19790x09,0x5B,0x50, /19800x04,0x9B,0x45, /19810x4A,0x4B,0xB9,
18、/19820x0A,0x4B,0x4d, /19830xAB,0x25,0xC2, /19840x06,0xA5,0x54, /19850x06,0xd4,0x49, /19860x6A,0xdA,0x3d, /19870x0A,0xB6,0x51, /19880x09,0x37,0x46, /19890x54,0x97,0xBB, /19900x04,0x97,0x4f, /19910x06,0x4B,0x44, /19920x36,0xA5,0x37, /19930x0e,0xA5,0x4A, /19940x86,0xB2,0xBf, /19950x05,0xAC,0x53, /19960
19、x0A,0xB6,0x47, /19970x59,0x36,0xBC, /19980x09,0x2e,0x50, /1999 2940x0C,0x96,0x45, /2000 2970x4d,0x4A,0xB8, /2001 3000x0d,0x4A,0x4C, /2002 3030x0d,0xA5,0x41, /2003 3060x25,0xAA,0xB6, /2004 3090x05,0x6A,0x49, /2005 3120x7A,0xAd,0xBd, /2006 3150x02,0x5d,0x52, /2007 3180x09,0x2d,0x47, /2008 3210x5C,0x95
20、,0xBA, /2009 3240x0A,0x95,0x4e, /2010 3270x0B,0x4A,0x43, /20110x4B,0x55,0x37, /20120x0A,0xd5,0x4A, /20130x95,0x5A,0xBf, /20140x04,0xBA,0x53, /20150x0A,0x5B,0x48, /20160x65,0x2B,0xBC, /20170x05,0x2B,0x50, /20180x0A,0x93,0x45, /20190x47,0x4A,0xB9, /20200x06,0xAA,0x4C, /20210x0A,0xd5,0x41, /20220x24,0x
21、dA,0xB6, /20230x04,0xB6,0x4A, /20240x69,0x57,0x3d, /20250x0A,0x4e,0x51, /20260x0d,0x26,0x46, /20270x5e,0x93,0x3A, /20280x0d,0x53,0x4d, /20290x05,0xAA,0x43, /20300x36,0xB5,0x37, /20310x09,0x6d,0x4B, /20320xB4,0xAe,0xBf, /20330x04,0xAd,0x53, /20340x0A,0x4d,0x48, /20350x6d,0x25,0xBC, /20360x0d,0x25,0x4
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- LCD12864 单片机 电子 万年历 程序 27
限制150内