51单片机12864万年历(图片+主要程序C语言)
发布时间:2024-11-25
发布时间:2024-11-25
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])
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;
}
}
}
}
}
}
task_delay[i]--; //
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,shimiao,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(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) TransferData('/',1);
{
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("五");}
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); //---------------------------------温度 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("一");} 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_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_WRITE_CHAR("秒表");
Lcd_Set_Post(3,2);
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); shi1=fen/10; ge1=fen%10; TransferData(shi1+48,1); TransferData(ge1+48,1); TransferData(':',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_Set_Post(2,0); LCD_WRITE_CHAR("界面选择"); TransferData(1+48,1); TransferData('.',1); LCD_WRITE_CHAR("多功能界面"); Lcd_Set_Post(3,0); TransferData(2+48,1); TransferData('.',1); LCD_WRITE_CHAR("简洁界面"); }