简易万年历在德飞莱开发板上
单片机源程序如下:
- #include <REGX52.H>
- #include "type.H"
- #include "OLEDDrive.H"
- #include"DS1302.h"
- #define FunKeyVal 1//按下功能键
- #define AddKeyVal 2//按下增加键
- #define SubKeyVal 3//按下减少键
- #define EscKeyVal 4//退出键
- //当前选中的时那个位置编号
- #define IDMax 9
- #define SelectYear 1
- #define SelectMonth 2
- #define SelectDate 3
- #define SelectDay 4
- #define SelectHour 5
- #define SelectMin 6
- #define SelectSec 7
- #define SelectClockHour 8
- #define SelectClockMin 9
-
- #define DIRUP 1
- #define DIRDOW 2
- extern uint16 ReadTemp(uint8 mode);
- uint8 buf[5];//显示缓存
- uint8 SelectState[]={0x00,0xff};
- bit ReadTemperatureFlag=0;//温度读取标志位
- uint16 Temperature;//DS18B20读取的16位温度数据
- code uint8 DecimalNum[16]={'0','1','1','2','3','3','4',
- '4','5','6','6','7','8','8','9','9'};//DS18B20读取的16bit数据最低4位对应的小数4舍5入取一位
- sfr IAP_CONTR = 0XE7;//特殊功能寄存器
- uint8 ClockHour=0;
- uint8 ClockMin=0;
- bit ClockFlag=0;
- sbit BEEP=P3^7;
- uint8 ID=0;//功能切换
- code uint8 weekstr[8][3]={
- " ","Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
- uint8 code Mon2[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,
- 0,31,29,31,30,31,30,31,31,30,31,30,31};
- uint8 code TempIco[]={
- /*-- 调入了一幅图像:这是您新建的图像 --*/
- /*-- 宽度x高度=8x16 --*/
- 0x00,0x00,0xFC,0x02,0xAA,0xFC,0x00,0x00,0x08,0x1C,0x3F,0x7E,0x7E,0x3F,0x1C,0x08,
- };
- uint8 code BEEPIco[]=
- {/*-- 调入了一幅图像:C:\Users\wise\Desktop\喇叭.bmp --*/
- /*-- 宽度x高度=16x16 --*/
- 0xF0,0x10,0x10,0xF0,0x18,0x0C,0x06,0x03,0xFF,0xFF,0xB0,0x98,0x8C,0x86,0x83,0x81,
- 0x0F,0x08,0x08,0x0F,0x08,0x30,0x20,0xC0,0xFF,0xFF,0x0D,0x19,0x31,0x61,0xC1,0x81};
- //温度单位符号℃
- uint8 code TempUint[]={
- /*-- 调入了一幅图像:这是您新建的图像 --*/
- /*-- 宽度x高度=6x8 --*/
- 0x02,0x05,0x72,0x88,0x88,0x00,
- };
- void UARTInit()
- {
- SCON = 0x50; //设定串口工作方式
- PCON = 0x00; //波特率不倍增
- TMOD = 0x20; //定时器1工作于8位自动重载模式, 用于产生波特率
- EA = 1;
- ES = 1; //允许串口中断
- TL1 = 0xfd;
- TH1 = 0xfd; //波特率9600
- TR1 = 1;
- }
- /**************************************************
- 将2位十进制数转为字符
- **************************************************/
- void Dec2ToStr(uint8 dec,uint8 *str)
- {
- *str++=dec/10+0x30;
- *str=dec%10+0x30;
- }
- /**************************************************
- 闰年判断2000-2099年能被4整除就时闰年
- **************************************************/
- uint8 IsLeapYear(uint8 year)
- {
- if((year%4)==0)
- {
- return 1;
- }
- return 0;
- }
- /**************************************************
- 显示年信息
- **************************************************/
- void ShowYear(void)
- {
- GUIShowString(2*6,0,"20",2,SelectState[SelectYear==ID]);
- Dec2ToStr(time.year,buf);
- GUIShowString(4*6,0,buf,2,SelectState[SelectYear==ID]);
- GUIShowString(6*6,0,"-",1,0);
- }
- /**************************************************
- 显示月信息
- **************************************************/
- void ShowMonth(void)
- {
- Dec2ToStr(time.month,buf);
- GUIShowString(7*6,0,buf,2,SelectState[SelectMonth==ID]);
- GUIShowString(9*6,0,"-",1,0);
- }
- /**************************************************
- 显示日期信息
- **************************************************/
- void ShowDate(void)
- {
- Dec2ToStr(time.date,buf);
- GUIShowString(10*6,0,buf,2,SelectState[SelectDate==ID]);
- }
- /**************************************************
- 显示星期信息
- **************************************************/
- void ShowDay(void)
- {
- GUIShowString(17*6,0,weekstr[time.day],3,SelectState[SelectDay==ID]);
- }
- /**************************************************
- 显示小时信息
- **************************************************/
- void ShowHour(void)
- {
- GUIShowChar15X24(0,2,time.hour/10,SelectState[SelectHour==ID]);
- GUIShowChar15X24(1*15,2,time.hour%10,SelectState[SelectHour==ID]);
- GUIShowChar15X24(2*15,2,10,0);
- }
- /**************************************************
- 显示分信息
- **************************************************/
- void ShowMin(void)
- {
- GUIShowChar15X24(3*15,2,time.min/10,SelectState[SelectMin==ID]);
- GUIShowChar15X24(4*15,2,time.min%10,SelectState[SelectMin==ID]);
- GUIShowChar15X24(5*15,2,10,0);
- }
- /**************************************************
- 显示秒信息
- **************************************************/
- void ShowSec(void)
- {
- GUIShowChar15X24(6*15,2,time.sec/10,SelectState[SelectSec==ID]);
- GUIShowChar15X24(7*15,2,time.sec%10,SelectState[SelectSec==ID]);
- }
- /**************************************************
- 显示闹铃时
- **************************************************/
- void ShowClockHour(void)
- {
- Dec2ToStr(ClockHour,buf);
- GUIShowString(11*6,7,buf,2,SelectState[SelectClockHour==ID]);
- GUIShowString(13*6,7,":",1,0);
- }
- /**************************************************
- 显示闹铃分
- **************************************************/
- void ShowClockMin(void)
- {
- Dec2ToStr(ClockMin,buf);
- GUIShowString(14*6,7,buf,2,SelectState[SelectClockMin==ID]);
- }
- void Dec1ToStr1(uint8 dec,uint8 *str)
- {
- str[0]=' ';
- str[1]=' ';
- str[2]=dec+0x30;
- }
- void Dec2ToStr1(uint8 dec,uint8 *str)
- {
- str[0]=' ';
- str[1]=dec/10+0x30;
- str[2]=dec%10+0x30;
- }
- void Dec3ToStr1(uint8 dec,uint8 *str)
- {
- str[0]=dec/100+0x30;
- str[1]=dec%100/10+0x30;
- str[2]=dec%10+0x30;
- }
- /**************************************************
- 显示温度信息
- **************************************************/
- void ShowTemperature(uint16 temperature,uint8* str)
- {
- str[3]='.';
- if(temperature&0x8000)//负温度
- {
- temperature=~temperature+1;
- str[4]=DecimalNum[temperature&0x0f];//计算小数部分
- temperature=temperature>>4;
- if(temperature>9)//负温度的时候最多只有2位整数部分
- {
- Dec3ToStr1(temperature,str);
- str[0]='-';
- }
- else
- {
- Dec2ToStr1(temperature,str);
- str[1]='-';
- }
- }
- else
- {
- str[4]=DecimalNum[temperature&0x0f];//计算小数部分
- temperature=temperature>>4;
- if(temperature>99)
- {
- Dec3ToStr1(temperature,str);
- }
- else if(temperature>9)
- {
- Dec2ToStr1(temperature,str);
- }
- else
- {
- Dec1ToStr1(temperature,str);
- }
- }
- GUIShowString(8,7,str,5,0);
- }
- /**************************************************
- 显示时间信息
- **************************************************/
- void ShowTime(void)
- {
- ShowYear();//显示时间
- ShowMonth();
-
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
B1.程序.zip
(102.25 KB, 下载次数: 74)
|