|
基于51单片机和12864液晶的多功能万年历全套资料.
万年历实物图:
Altium Designer画的原理图和PCB图如下:(51hei附件中可下载工程文件):
单片机源程序如下:
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- /************************12864端口定义*******************************************/
- #define dataport P0 //12864数据口
- sbit rs=P2^0; //指令/数据端口
- sbit rw=P2^1; //读/写端口
- sbit en=P2^2; //使能端口
- sbit psb=P2^3; //并口/串口端口(本万年历采用并口)
- sbit rst=P2^5; //复位端口
- /********************************************************************************/
- /***********************DS1302端口定义*******************************************/
- sbit clock_rst=P3^7; //1302复位管脚定义
- sbit clock_dat=P2^6; //1302I/O管脚定义
- sbit clock_clk=P2^7; //1302时钟管脚定义
- /***************寄存器定义(用于记录1302IO的输入和输出)*************************/
- sbit a0=ACC^0;
- sbit a1=ACC^1;
- sbit a2=ACC^2;
- sbit a3=ACC^3;
- sbit a4=ACC^4;
- sbit a5=ACC^5;
- sbit a6=ACC^6;
- sbit a7=ACC^7;
- /********************DS18B20端口定义*********************************************/
- /********************************************************************************/
- sbit DQ=P3^4; //DS18B20数据端口
- /********************************************************************************/
- /******************18B20全局变量定义*********************************************/
- uchar temp; //温度全局变量(整数部分)
- uint xs; //温度全局变量(小数部分)
- /********************************************************************************/
-
- /**********************1302全局变量定义******************************************/
- uchar sec,min,hour,day,month,week,year1,year2=20;//秒,分,时,日,月,星期,年
- /************************蜂鸣器端口定义******************************************/
- sbit beep=P3^5;
- uchar num;
- /***********************按键定义*************************************************/
- sbit key1=P3^0;
- sbit key2=P3^1;
- sbit key3=P3^2;
- sbit key4=P3^3;
- uchar set=0; //set=0时显示首页,1时显示次页
- uchar status=0;//按键功能选择定义(年0,月1,日2,时3,分4 )
- /********************************************************************************/
- uchar code month_week[12]={6,2,3,6,1,4,6,2,5,7,3,5}; //2000年各月头天星期表
- uchar code year_code[300]={0x0C,0x96,0x45, /*2000*/ 0x4d,0x4A,0xB8, /*2001*/ //2002~2099年农历表
- 0x0d,0x4A,0x4C, /*2002*/ 0x0d,0xA5,0x41, /*2003*/ 0x25,0xAA,0xB6, /*2004*/
- 0x05,0x6A,0x49, /*2005*/ 0x7A,0xAd,0xBd, /*2006*/ 0x02,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, /*2029*/ 0x05,0xAA,0x43, /*2030*/ 0x36,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, /*2053*/ 0x06,0x4B,0x48, /*2054*/ 0x66,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, /*2077*/ 0x0A,0x5B,0x4C, /*2078*/ 0x05,0x2B,0x42, /*2079*/
- 0x3A,0x93,0xB6, /*2080*/ 0x06,0x93,0x49, /*2081*/ 0x77,0x29,0xBd, /*2082*/
- 0x06,0xAA,0x51, /*2083*/ 0x0A,0xd5,0x46, /*2084*/ 0x54,0xdA,0xBA, /*2085*/
- 0x04,0xB6,0x4e, /*2086*/ 0x0A,0x57,0x43, /*2087*/ 0x45,0x27,0x38, /*2088*/
- 0x0d,0x26,0x4A, /*2089*/ 0x8e,0x93,0x3e, /*2090*/ 0x0d,0x52,0x52, /*2091*/
- 0x0d,0xAA,0x47, /*2092*/ 0x66,0xB5,0x3B, /*2093*/ 0x05,0x6d,0x4f, /*2094*/
- 0x04,0xAe,0x45, /*2095*/ 0x4A,0x4e,0xB9, /*2096*/ 0x0A,0x4d,0x4C, /*2097*/
- 0x0d,0x15,0x41, /*2098*/ 0x2d,0x92,0xB5, /*2099*/
- };
- uint code month_day1[12]={0,31,59,90,120,151,181,212,243,273,304,334};//平年月份累计天数表
- uint code month_day2[12]={0,31,60,91,121,152,182,213,244,274,305,335};//闰年月份累计天数表
- uint table_addr; //查农历表的地址全局变量
- uchar year1_n,month_n,day_n; //农历年月日全局变量
- uchar month_r; //农历闰月全局变量,无时为0
- /**********************延时函数*************************************************/
- void delay(uint t)
- {
- uint b;
- for(;t;t--)
- for(b=0;b<121;b++);
- }
- /*******************************************************************************/
- /**************************12864子函数******************************************/
- /**********************检查忙信号子函数*****************************************/
- void busy()
- {
- rs=0; //指令操作
- rw=1; //读操作
- dataport=0xff; //数据端口置位
- en=1; //使能
- while(dataport&0x80); //等待数据端口位7为0
- en=0; //取消使能
- }
- /************************写指令函数*********************************************/
- void write_code(uchar c)
- {
- busy(); //检查忙标志
- rs=0; //指令操作
- rw=0; //写操作
- dataport=c; //送指令到端口
- en=1; //使能
- delay(1); //稍微延时
- en=0; //取消使能
- }
- /************************写数据函数*********************************************/
- void write_data(uchar d)
- {
- busy(); //检查忙标志
- rs=1; //数据操作
- rw=0; //写操作
- dataport=d; //送数据到端口
- en=1; //使能
- delay(1); //稍微延时
- en=0; //取消延时
- }
- /***********************写汉字**************************************************/
- void write_hz(uchar *hz)
- {
- while(*hz>0)
- {
- write_data(*hz); //写入汉字
- hz++;
- }
- }
-
- /***************************初始化12864*****************************************/
- void init_12864()
- {
- psb=1; //并口方式
- rst=1; //复位端置高
- write_code(0x30); //8位数据传送,基本指令操作
- delay(10);
- write_code(0x0c); //无光标,不反白
- delay(10);
- write_code(0x01); //清除显示
- delay(10);
- write_code(0x40); //光标左移,字符不动
- delay(10);
- }
- /*******************************************************************************/
- /*************************DS1302子函数******************************************/
- /************************1302写驱动函数*****************************************/
- void write_clock(uchar dat)
- {
- ACC=dat;
- clock_dat=a0; clock_clk=1; clock_clk=0; //数据在上升沿变化
- clock_dat=a1; clock_clk=1; clock_clk=0; //下降沿写入1302
- clock_dat=a2; clock_clk=1; clock_clk=0;
- clock_dat=a3; clock_clk=1; clock_clk=0;
- clock_dat=a4; clock_clk=1; clock_clk=0;
- clock_dat=a5; clock_clk=1; clock_clk=0;
- clock_dat=a6; clock_clk=1; clock_clk=0;
- clock_dat=a7; clock_clk=1; clock_clk=0;
- }
- /************************1302读驱动函数*****************************************/
- uchar read_clock()
- {
- clock_dat=1; //输出赋1
- a0=clock_dat;clock_clk=1; clock_clk=0; //位0为1,读1302
- a1=clock_dat;clock_clk=1; clock_clk=0; //下降沿读出有效
- a2=clock_dat;clock_clk=1; clock_clk=0;
- a3=clock_dat;clock_clk=1; clock_clk=0;
- a4=clock_dat;clock_clk=1; clock_clk=0;
- a5=clock_dat;clock_clk=1; clock_clk=0;
- a6=clock_dat;clock_clk=1; clock_clk=0;
- a7=clock_dat;clock_clk=1; clock_clk=0;
- return(ACC);
- }
- /***************************写数据入1302****************************************/
- void write_dat_clock(uchar add,uchar dat)
- {
- clock_clk=0;
- clock_rst=0; //时钟脉冲为低时
- clock_rst=1; //复位端才能置高
- write_clock(add); //写入地址(命令字节)
- write_clock(dat); //写入数据
- clock_rst=0; //终止数据传送
- clock_clk=1;
- }
- /***************************从1302读出数据**************************************/
- uchar read_dat_clock(uchar add)
- {
- uchar dat=0; //定义数据储存变量
- clock_clk=0;
- clock_rst=0;
- clock_rst=1;
- write_clock(add); //写入要读数据的地址
- dat=read_clock(); //读出数据
- clock_rst=0; //终止数据传送
- clock_clk=1;
- return dat; //返回数据
- }
- /**************************设置初始时间函数*************************************/
- void set_time()
- {
- write_dat_clock(0x8e,0x00); //允许写操作
- write_dat_clock(0x8c,0x09); //年
- write_dat_clock(0x8a,0x03); //星期
- write_dat_clock(0x88,0x10); //月
- write_dat_clock(0x86,0x14); //日
- write_dat_clock(0x84,0x21); //小时
- write_dat_clock(0x82,0x56); //分
- write_dat_clock(0x80,0x00); //秒,且振荡器工作
- //write_dat_clock(0x90,0xa5); //充电
- write_dat_clock(0x8e,0x80); //禁止写操作
- }
- /*****************************读取时间******************************************/
- void get_time()
- {
- sec=read_dat_clock(0x81); //读取秒
- sec=(sec>>4)*10+(sec&0x0f); //秒二进制转换
- min=read_dat_clock(0x83); //读取分钟
- min=(min>>4)*10+(min&0x0f); //分二进制转换
- hour=read_dat_clock(0x85); //读取小时
- hour=(hour>>4)*10+(hour&0x0f);//小时二进制转换
- day=read_dat_clock(0x87); //读取日期
- day=(day>>4)*10+(day&0x0f); //日期二进制转换
- month=read_dat_clock(0x89); //读取月份
- month=(month>>4)*10+(month&0x0f);//月二进制转换
- week=read_dat_clock(0x8b); //读取星期
- week=(week>>4)*10+(week&0x0f);//星期二进制转换
- year1=read_dat_clock(0x8d); //读取年份
- year1=(year1>>4)*10+(year1&0x0f); //年份二进制转换
- }
- /*************************DS18B20各子函数***************************************/
- /*************************DS18B20延时函数***************************************/
- void delay_DS18B20(uint i)
- {
- for(;i;i--);
- }
- /*************************DS18B20初始化函数*************************************/
- void init_DS18B20()
- {
- DQ=1; //DQ复位
- delay_DS18B20(1); //稍作延时
- DQ=0; //产生复位脉冲
- delay_DS18B20(160); //精确延时,大于480us
- DQ=1; //拉高总线
- delay_DS18B20(5); //等待20us左右
- while(DQ); //等待DS18B20发出存在脉冲
- delay_DS18B20(30); //脉冲持续100us左右
- }
- /*****************************写一个字节****************************************/
- void write_onechar(uchar dat)
- {
- uchar i;
- for(i=8;i>0;i--)
- {
- DQ=0;
- DQ=dat&0x01;
- delay_DS18B20(3);
- DQ=1;
- dat>>=1;
- }
- }
- /*****************************读一个字节****************************************/
- uchar read_onechar()
- {
- uchar i;
- uchar dat;
- for(i=8;i>0;i--)
- {
- DQ=0; //总线拉低
- dat>>=1; //维持一个指令时间
- DQ=1; //拉高总线
- if(DQ) //读数据
- dat|=0x80;
- delay_DS18B20(20); //维持60us
- }
- return dat;
- }
- /*************************读取温度数值******************************************/
- uchar read_tem()
- {
- uchar ltemp; //定义温度低字节
- uchar htemp; //定义温度高字节
- uchar t; //定义温度整数部分返回值
- init_DS18B20();
- write_onechar(0xcc); //跳过读序号列号的操作
- write_onechar(0x44); // 启动温度转换
- init_DS18B20();
- write_onechar(0xcc); //跳过读序号列号的操作
- write_onechar(0xbe); //读取温度寄存器
- ltemp=read_onechar(); //读取温度低字节
- htemp=read_onechar(); //读取温度高字节
- ltemp=ltemp>>4; //低字节右移4位,去掉小数位
- t=htemp<<4; //高字节左移4位,去掉符号位
- t|=ltemp; //合并整数部分
- xs=ltemp&0x0f; //小数部分赋予xs
- xs*=0.625; //计算小数部分的数值
- return t; //返回温度整数部分数值
- }
- /******************************************************************************/
- /*****************************按键功能函数*************************************/
- void key_1() //选择变量函数
- {
- key1=1;
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- if(++status>5)status=0; //1控制年的变化,2控制月的变化,3控制日的变化
- } //4控制时的变化,5控制分的变化
- while(key1==0);
- }
- }
- /******************************************************************************/
- void key_2() //加函数
- {
- key2=1;
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- switch(status)
- {
- case 1:if(++year1>99)year1=0;break;
- case 2:if(++month>12)month=1;break;
- case 3:if(++day>31)day=1;break;
- case 4:if(++hour>=24)hour=0;break;
- case 5:if(++min>=60)min=0;break;
- }
- }
- while(key2==0);
- }
- }
- /*****************************************************************************/
- void key_3()//减函数
- {
- key3=1;
- if(key3==0)
- {
- delay(10);
- if(key3==0)
- {
- switch(status)
- {
- case 1:if((year1--)<=0)year1=99;break;
- case 2:if((month--)<=1)month=12;break;
- case 3:if((day--)<=1)day=31;break;
- case 4:if((hour--)<=0)hour=23;break;
- case 5:if((min--)<=0)min=59;break;
- }
- }
- while(key3==0);
- }
- }
- /*****************************************************************************/
- void key_4() //选择变量函数
- {
- key4=1;
- if(key4==0)
- {
- delay(10);
- if(key4==0)
- {
- if(++set>1)set=0;//0显示首页,1显示次页
- }
- write_code(0x01); //清除一下显示屏
- while(key4==0);
- }
- }
- /*****************************************************************************/
- void key_time() //按键设置时间的处理
- {
- write_dat_clock(0x8e,0x00); //允许写操作
- write_dat_clock(0x8c,(year1/10)*16+year1%10); //年
- write_dat_clock(0x8a,(week/10)*16+week%10); //星期
- write_dat_clock(0x88,(month/10)*16+month%10); //月
- write_dat_clock(0x86,(day/10)*16+day%10); //日
- write_dat_clock(0x84,(hour/10)*16+hour%10); //小时
- write_dat_clock(0x82,(min/10)*16+min%10); //分
- write_dat_clock(0x8e,0x80); //禁止写操作
- }
- /*****************************************************************************/
- /***********************平闰年设定********************************************/
- bit prp(uchar y)
- {
- uint temp;
- temp=2000+y;
- if(((temp%4)==0)&&((temp%100)!=0)||((temp%400)==0))
- return 1;
- else
- return 0;
- }
- /***********************某年月日星期设定**************************************/
- void d_week()
- {
- uchar x,y;
- x=year1/4;
- y=year1%4;
- if(month<3)
- week=((x*5+2+(y-1)+(day-1))%7+month_week[month-1])%7;
- else
- week=((x*5+y+(day-1))%7+month_week[month-1])%7;
- }
- /***********************某年月日农历设定**************************************/
- uchar get_moon_day(uchar m,uint ta)//农历月天数判定函数
- {
- uchar temp;
- switch(m)
- {
- case 1:temp=year_code[ta]&0x08;break;
- case 2:temp=year_code[ta]&0x04;break;
- case 3:temp=year_code[ta]&0x02;break;
- case 4:temp=year_code[ta]&0x01;break;
- case 5:temp=year_code[ta+1]&0x80;break;
- case 6:temp=year_code[ta+1]&0x40;break;
- case 7:temp=year_code[ta+1]&0x20;break;
- case 8:temp=year_code[ta+1]&0x10;break;
- case 9:temp=year_code[ta+2]&0x08;break;
- case 10:temp=year_code[ta+2]&0x04;break;
- case 11:temp=year_code[ta+2]&0x02;break;
- case 12:temp=year_code[ta+2]&0x01;break;
- case 13:temp=year_code[ta+2]&0x80;break;
- }
- if(temp==0)
- return 29;
- else
- return 30;
- }
- /**********************某年农历闰月设定**************************************/
- uchar get_month_r(uchar y)
- {
- uchar temp,ta;
- ta=y*3;
- temp=(year_code[ta]&0xf0)>>4;
- return temp;
- }
- /*********************阳历转化农历*******************************************/
- void convert_yinyan(uchar year1,uchar month,uchar day)
- {
- uchar month_n1,day_n1;//春节公历月日
- uint temp1,temp2; //值转移变量
- table_addr=year1*3;
- month_n1=(year_code[table_addr+2]&0x60)>>5;//农历正月所在月数
- day_n1=year_code[table_addr+2]&0x1f; //农历正月所在当月日数
- month_r=get_month_r(year1); //计算当年闰月
- if(month_n1==1) //春节离当年元旦天数
- temp1=day_n1-1;
- else
- temp1=30+day_n1-1;
- if(prp(year1))//次年是否为闰年
- temp2=month_day2[month-1]+day-1;
- else
- temp2=month_day1[month-1]+day-1;
- if(temp2>=temp1)//次月日在春节后否
- {
- year1_n=year1;
- month_n=1;
- temp2=temp2-temp1;
- temp1=get_moon_day(month_n,table_addr); //当月天数计算
- while(temp2>=temp1)
- {
- month_n++;
- temp2=temp2-temp1;
- temp1=get_moon_day(month_n,table_addr);
- }
- day_n=temp2+1;
- }
- else
- {
- year1_n=year1-1;
- temp1=temp1-temp2;
- table_addr=table_addr-3;
- month_r=get_month_r(year1-1);
- if(month_r==0) //若当年没有闰月
- month_n=12;
- else
- month_n=13;
- temp2=get_moon_day(month_n,table_addr);
- while(temp1>=temp2)
- {
- month_n--;
- temp1=temp1-temp2;
- temp2=get_moon_day(month_n,table_addr);
- }
- }
-
- }
-
- /***********************特殊功能子函数***************************************/
- /**************************星期设定******************************************/
- void xingqi()
- {
- d_week();
- switch(week)
- {
- case 1:write_hz("一");break;
- case 2:write_hz("二");break;
- case 3:write_data(0xc8);write_data(0xfd);break;
- case 4:write_hz("四");break;
- case 5:write_hz("五");break;
- case 6:write_hz("六");break;
- case 0:write_hz("日");break;
- default:break;
- }
- }
- /*************************生肖年设定*****************************************/
- void shengxiao()
- {
- uchar sx=year1%12;
- switch(sx)
- {
- case 0:write_hz("龙");break;
- case 1:write_hz("蛇");break;
- case 2:write_hz("马");break;
- case 3:write_hz("羊");break;
- case 4:write_hz("猴");break;
- case 5:write_hz("鸡");break;
- case 6:write_hz("狗");break;
- case 7:write_hz("猪");break;
- case 8:write_hz("鼠");break;
- case 9:write_hz("牛");break;
- case 10:write_hz("虎");break;
- case 11:write_hz("兔");break;
- default:break;
- }
- }
- /************************天干地支设定****************************************/
- void tgdz()
- {
- uchar tiangan=year1_n%10;
- uchar dizhi=year1_n%12;
- switch(tiangan)
- {
- case 4:write_hz("甲");break;
- case 5:write_hz("乙");break;
- case 6:write_hz("丙");break;
- case 7:write_hz("丁");break;
- case 8:write_hz("戊");break;
- case 9:write_hz("己");break;
- case 0:write_data(0xb8);write_data(0xfd);break;
- case 1:write_hz("辛");break;
- case 2:write_hz("壬");break;
- case 3:write_hz("葵");break;
- default:break;
- }
- switch(dizhi)
- {
- case 8:write_hz("子");break;
- case 9:write_hz("丑");break;
- case 10:write_hz("寅");break;
- case 11:write_hz("卯");break;
- case 0:write_hz("辰");break;
- case 1:write_hz("巳");break;
- case 2:write_hz("午");break;
- case 3:write_hz("未");break;
- case 4:write_hz("申");break;
- case 5:write_hz("酉");break;
- case 6:write_hz("戌");break;
- case 7:write_hz("亥");break;
- default:break;
- }
- }
- /*******************农历月设定**********************************************/
- void nongli_m()
- {
- if(month_n==0)
- {
- switch(month_n)
- {
- case 1: write_hz(" ");write_data(0xd5);write_data(0xfd);break; //正
- case 2: write_hz(" 二");break;
- case 3: write_hz(" ");write_data(0xc8);write_data(0xfd);break; //三
- case 4: write_hz(" 四");break;
- case 5: write_hz(" 五");break;
- case 6: write_hz(" 六");break;
- case 7: write_hz(" 七");break;
- case 8: write_hz(" 八");break;
- case 9: write_hz(" 九");break;
- case 10:write_hz(" 十");break;
- case 11:write_hz(" 十一");break;
- case 12:write_hz(" 十二");break;
- }
- }
- else
- {
- if((month_n-1)==month_r)
- {
- switch(month_n-1)
- {
- case 1: write_hz(" 闰一");break;
- case 2: write_hz(" 闰二");break;
- case 3: write_hz(" 闰");write_data(0xc8);write_data(0xfd);break;
- case 4: write_hz(" 闰四");break;
- case 5: write_hz(" 闰五");break;
- case 6: write_hz(" 闰六");break;
- case 7: write_hz(" 闰七");break;
- case 8: write_hz(" 闰八");break;
- case 9: write_hz(" 闰九");break;
- case 10:write_hz(" 闰十");break;
- case 11:write_hz("闰十一");break;
- case 12:write_hz("闰十二");break;
- }
- }
- else if(month_n<=month_r)
- {
- switch(month_n)
- {
- case 1: write_hz(" ");write_data(0xd5);write_data(0xfd);break;
- case 2: write_hz(" 二");break;
- case 3: write_hz(" ");write_data(0xc8);write_data(0xfd);break;
- case 4: write_hz(" 四");break;
- case 5: write_hz(" 五");break;
- case 6: write_hz(" 六");break;
- case 7: write_hz(" 七");break;
- case 8: write_hz(" 八");break;
- case 9: write_hz(" 九");break;
- case 10:write_hz(" 十");break;
- case 11:write_hz(" 十一");break;
- case 12:write_hz(" 十二");break;
- }
- }
- else
- {
- switch(month_n-1)
- {
- case 2: write_hz(" 二");break;
- case 3: write_hz(" ");write_data(0xc8);write_data(0xfd);break;
- case 4: write_hz(" 四");break;
- case 5: write_hz(" 五");break;
- case 6: write_hz(" 六");break;
- case 7: write_hz(" 七");break;
- case 8: write_hz(" 八");break;
- case 9: write_hz(" 九");break;
- case 10:write_hz(" 十");break;
- case 11:write_hz(" 十一");break;
- case 12:write_hz(" 十二");break;
- }
- }
- }
- }
- /***********************农历日设定******************************************/
- void nongli_d()
- {
- switch(day_n)
- {
- case 1: write_hz("初一 ");break;
- case 2: write_hz("初二 ");break;
- case 3: write_hz("初");write_data(0xc8);write_data(0xfd);write_hz(" ");break;
- case 4: write_hz("初四 ");break;
- case 5: write_hz("初五 ");break;
- case 6: write_hz("初六 ");break;
- case 7: write_hz("初七 ");break;
- case 8: write_hz("初八 ");break;
- case 9: write_hz("初九 ");break;
- case 10:write_hz("初十 ");break;
- case 11:write_hz("十一 ");break;
- case 12:write_hz("十二 ");break;
- case 13:write_hz("十");write_data(0xc8);write_data(0xfd);write_hz(" ");break;
- case 14:write_hz("十四 ");break;
- case 15:write_hz("十五 ");break;
- case 16:write_hz("十六 ");break;
- case 17:write_hz("十七 ");break;
- case 18:write_hz("十八 ");break;
- case 19:write_hz("十九 ");break;
- case 20:write_hz("廿十 ");break;
- case 21:write_hz("廿十一");break;
- case 22:write_hz("廿十二");break;
- case 23:write_hz("廿十");write_data(0xc8);write_data(0xfd);break;
- case 24:write_hz("廿十四");break;
- case 25:write_hz("廿十五");break;
- case 26:write_hz("廿十六");break;
- case 27:write_hz("廿十七");break;
- case 28:write_hz("廿十八");break;
- case 29:write_hz("廿十九");break;
- case 30:write_data(0xc8);write_data(0xfd);write_hz("十");write_hz(" ");break;
- }
- }
-
- /************************节日函数*******************************************/
- void holiday()
- {
- while(1){
- if(status==1) {write_hz(" 调整年份 ");break;}
- if(status==2) {write_hz(" 调整月份 ");break;}
- if(status==3) {write_hz(" 调整日期 ");break;}
- if(status==4) {write_hz(" 调整小时 ");break;}
- if(status==5) {write_hz(" 调整分钟 ");break;}
- if(month==1&&day==1) {write_hz(" 新年元旦 ");break;}
- if(month==2&&day==14) {write_hz(" 今日情人节 ");break;}
- if(month==3&&day==8) {write_hz(" 国际妇女节 ");break;}
- if(month==3&&day==12) {write_hz(" 中国植树节 ");break;}
- if(month==3&&day==15) {write_hz("世界消费者权益日");break;}
- if(month==4&&day==1) {write_hz(" 愚人节 ");break;}
- if(month==5&&day==1) {write_hz(" 国际劳动节 ");break;}
- if(month==5&&day==4) {write_hz(" 中国青年节 ");break;}
- if(month==5&&day==8) {write_hz(" 世界红十字日 ");break;}
- if(month==5&&day==12) {write_hz(" 国际护士节 ");break;}
- if(month==6&&day==1) {write_hz(" 国际儿童节 ");break;}
- if(month==6&&day==26) {write_hz(" 国际禁毒日 ");break;}
- if(month==7&&day==1) {write_hz("中国共产党诞生日");break;}
- if(month==7&&day==7) {write_hz("抗日战争纪念日 ");break;}
- if(month==8&&day==1) {write_hz(" 中国建军节 ");break;}
- if(month==8&&day==12) {write_hz(" 国际青年节 ");break;}
- if(month==9&&day==10) {write_hz(" 中国教师节 ");break;}
- if(month==10&&day==1) {write_hz(" 国庆节 ");break;}
- if(month==10&&day==24) {write_hz(" 联合国日 ");break;}
- if(month==10&&day==31) {write_hz(" 万圣节 ");break;}
- if(month==12&&day==1) {write_hz(" 世界艾滋病日 ");break;}
- if(month==12&&day==25) {write_hz(" 圣诞节 ");break;}
- if(hour>=4&&hour<6) {write_hz("凌晨了,ZZZ~~~");break;}
- if(hour>=6&&hour<8) {write_hz("主人,早上好!");break;}
- if(hour>=8&&hour<12) {write_hz("__●__上午▲▲__");break;}
- if(hour==12) {write_hz("午休时间到咯~");break;}
- if(hour>=13&&hour<18) {write_hz("下午茶时间^_^");break;}
- if(hour>=18&&hour<22) {write_hz(" 晚上了额 ~");break;}
- if(hour>=22&&hour<=23) {write_hz("该准备睡咯~~~");break;}
- if(hour>=0&&hour<4) {write_hz("你,睡了吗?Z~");break;}
-
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
(015)基于51单片机和12864液晶的多功能万年历全套资料.rar
(706.53 KB, 下载次数: 264)
|
评分
-
查看全部评分
|