《[信息与通信]万年历程序不要嫌程序长功能很齐全而且对初学者很有帮助》由会员分享,可在线阅读,更多相关《[信息与通信]万年历程序不要嫌程序长功能很齐全而且对初学者很有帮助(34页珍藏版)》请在金锄头文库上搜索。
1、#include #include #define uint unsigned int#define uchar unsigned charvoid Stopwatch(); /声明秒表函数void Clock(); /声明闹钟函数void Output(); /声明输出函数void important(); /声明重要函数(相当于mian()函数)void TLimit(); /声明调节温度上下限函数sbit DS1302_CLK = P17; /实时时钟时钟线引脚 sbit DS1302_IO = P16; /实时时钟数据线引脚 sbit DS1302_RST = P15; /实时时钟复位
2、线引脚sbit wireless_1 = P30; /温度过上限标志sbit wireless_2 = P31; /温度适中标志sbit wireless_3 = P32; /温度过下限标志sbit fan = P34; /开风扇标志sbit clock=P35; /开关闹钟sbit setclock = P36; /闹钟开启控制sbit stopwatch = P37; /秒表开启控制sbit ACC0 = ACC0;sbit ACC7 = ACC7;char hide_sec,hide_min,hide_hour,hide_day,hide_week,hide_month,hide_yea
3、r; /秒,分,时到日,月,年位闪的计数sbit Set = P20; /模式切换键sbit Up = P21; /加法按钮sbit Down = P22; /减法按钮sbit out = P23; /立刻跳出调整模式按钮sbit DQ = P10; /温度传送数据IO口char c3,c2=0;char c=0,LowerBonud=20,UpperLimit=30;char a1=0,a2=0,a3=0,a4=0;char k8=0,0,:,0,0,:,0,0;void InitTimer0(void)/产生10ms时间间隔 TMOD = (TMOD & 0XF0) | 0X01; /定时
4、器0工作在模式1,16Bit定时器模式 TH0 = (65536 - 8000)/256; TL0 = (65536 - 8000)%256; TR0 =1; ET0 =1;/开启定时器和中断 EA = 1;char done,count,temp,flag,up_flag,down_flag; /uchar temp_value; /温度值uchar TempBuffer5,week_value2,h8; /unsigned char NL5;void show_time(); /液晶显示程序/*1602液晶显示部分子程序*/Port Definitions*sbit LcdRs= P25;
5、sbit LcdRw= P26;sbit LcdEn = P27;sfr DBPort = 0x80;/P0=0x80,P1=0x90,P2=0xA0,P3=0xB0.数据端口/内部等待函数*unsigned char LCD_Wait(void)LcdRs=0;LcdRw=1;_nop_();LcdEn=1;_nop_(); LcdEn=0;return DBPort;/向LCD写入命令或数据*#define LCD_COMMAND0 / Command#define LCD_DATA1 / Data#define LCD_CLEAR_SCREEN0x01 / 清屏#define LCD_H
6、OMING 0x02 / 光标返回原点void LCD_Write(bit style, unsigned char input)LcdEn=0;LcdRs=style;LcdRw=0;_nop_();DBPort=input;_nop_();/注意顺序LcdEn=1;_nop_();/注意顺序LcdEn=0;_nop_();LCD_Wait();/设置显示模式*#define LCD_SHOW0x04 /显示开#define LCD_HIDE0x00 /显示关 #define LCD_CURSOR0x02 /显示光标#define LCD_NO_CURSOR0x00 /无光标 #define
7、 LCD_FLASH0x01 /光标闪动#define LCD_NO_FLASH0x00 /光标不闪动void LCD_SetDisplay(unsigned char DisplayMode)LCD_Write(LCD_COMMAND, 0x08|DisplayMode);/设置输入模式*#define LCD_AC_UP0x02#define LCD_AC_DOWN0x00 / default#define LCD_MOVE0x01 / 画面可平移#define LCD_NO_MOVE0x00 /defaultvoid LCD_SetInput(unsigned char InputMod
8、e)LCD_Write(LCD_COMMAND, 0x04|InputMode);/初始化LCD*void LCD_Initial()LcdEn=0;LCD_Write(LCD_COMMAND,0x38); /8位数据端口,2行显示,5*7点阵LCD_Write(LCD_COMMAND,0x38);LCD_SetDisplay(LCD_SHOW|LCD_NO_CURSOR); /开启显示, 无光标LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); /清屏LCD_SetInput(LCD_AC_UP|LCD_NO_MOVE); /AC递增, 画面不动/液晶字符输入的
9、位置*void GotoXY(unsigned char x, unsigned char y)if(y=0)LCD_Write(LCD_COMMAND,0x80|x);if(y=1)LCD_Write(LCD_COMMAND,0x80|(x-0x40);/将字符输出到液晶显示void Print(unsigned char *str)while(*str!=0)/while(*str!=0)LCD_Write(LCD_DATA,*str);str+;/*DS1302时钟部分子程序*/typedef struct SYSTEMTIMEunsigned char Second;unsigned
10、char Minute;unsigned char Hour;unsigned char Week;unsigned char Day;unsigned char Month;unsigned char Year;unsigned char YearH;unsigned char YearL;unsigned char day;unsigned char month;unsigned char year;unsigned char DateString11;unsigned char NLDateString12;unsigned char TimeString9;SYSTEMTIME;/定义
11、的时间类型SYSTEMTIME CurrentTime; /#define AM(X)X#define PM(X)(X+12) / 转成24小时制#define DS1302_SECOND0x80 /时钟芯片的寄存器位置,存放时间#define DS1302_MINUTE0x82#define DS1302_HOUR0x84 #define DS1302_WEEK0x8A#define DS1302_DAY0x86#define DS1302_MONTH0x88#define DS1302_YEAR0x8C #define DS1302_YEARH 0xC0 void DS1302InputByte(unsigned char d) /实时时钟写入一字节(内部函数) unsigned char i; ACC = d; for(i=8; i0; i-) DS1302_IO = ACC0; /相当于汇编中的 RRC DS1302_CLK = 1; DS1302_CLK = 0; ACC = ACC 1; unsigned char DS1302OutputByte(void) /实时时钟读取一字节(内部函数) unsigned char