pic16f877a万年历程序
扫描二维码
随时随地手机看文章
/***************************************************
*标题:万年历*
*说明:包含文件
***************************************************/
#include
#include"ziku.h"
#include"lcd_init.h"
#include"ds1302.h"
#include"ds18b20.h"
#include"keysCAN.h"
#include"yinli.h"
uchjj,ii;
//子程序
//LCD显示空白边框子程序
voidLCDShowTable()
{
uchi;
SlectScreen(1);//写左半屏
SetLine(0);//起使页
SetColumn(0);//起使列
for(i=0;i<64;i++)
{
if((i==0)||(i==63))WritEDAta(0xff);//第1、63列竖线
elseWriteData(0x01);//最上面一行线
}
for(i=1;i<7;i++)
{
SetLine(i);
SetColumn(0);
WriteData(0xff);//竖线
SetColumn(63);
WriteData(0xff);//竖线
}
SetLine(7);
SetColumn(0);
for(i=0;i<64;i++)
{
if((i==0)||(i==63))WriteData(0xff);
elseWriteData(0x80);//最下面的横线
}
SlectScreen(2);//写右半屏
SetLine(0);
SetColumn(0);
for(i=0;i<64;i++)
{
if(i==63)WriteData(0xff);
elseWriteData(0x01);
}
SetLine(4);
SetColumn(0);
for(i=0;i<64;i++)
{
if(i==63)WriteData(0xff);
elseWriteData(0x01);
}
for(i=1;i<7;i++)
{
SetLine(i);
SetColumn(63);
WriteData(0xff);
}
SetLine(7);
SetColumn(0);
for(i=0;i<64;i++)
{
if(i==63)WriteData(0xff);
elseWriteData(0x80);
}
}
/*----------------------------------------------------------*/
//显示固定字符子程序
voidLCDShowGudingWord()
{
Show8X16(0,80,maohao,1);
Show8X16(0,104,maohao,1);
Show16X16(6,80,yue,2);
Show16X16(0,40,nian,1);
Show16X16(4,2,yue,0);
Show16X16(6,8,xing,2);
Show16X16(6,24,qi,2);
Show16X16(2,96,danwei1,0);
Show8X16(0,8,s2,1);
Show8X16(0,16,s0,1);
}
/*----------------------------------------------------------*/
voidTMR0init()
{
T0CS=0;
PSA=0;
PS2=1;
PS1=1;
PS0=1;
TMR0=0x80;
T0IE=1;
T0IF=0;
}
//冒号闪烁子程序
voidFlashMaohao()
{
staticuchtimecount1;
staticinttimecount2;
if(TMR0IF==1)
{
TMR0=0x80;
TMR0IF=0;
timecount1++;
timecount2++;
if(timecount1==10)
{
flag++;
flag=flag%2;//闪烁标志在0-1间翻转
timecount1=0;
}
if(timecount2==1200)//1分钟采样一次温度
{
timecount2=0;
get_temp();//温度转换子程序
}
}
if(flag==0)
{
Show8X16(0,80,maohao,1);
Show8X16(0,104,maohao,1);
}
if(flag==1)
{
Show8X16(0,80,noshu,1);//清除
Show8X16(0,104,noshu,1);
}
}
voidNaoling()
{
if(kk==1)
{
if(RD3==0)
{
jj++;
jj=jj%4;
while(1)
{
if(RD3==1)break;
}
}
if(jj==1)
{
Naoling_hour_1=Naoling_hour;
Naoling_minute_1=Naoling_minute;
RC4=1;
RC6=0;
RC7=0;
}
if(jj==2)
{
Naoling_hour_2=Naoling_hour;
Naoling_minute_2=Naoling_minute;
RC4=0;
RC6=1;
RC7=0;
}
if(jj==3)
{
Naoling_hour_3=Naoling_hour;
Naoling_minute_3=Naoling_minute;
RC4=0;
RC6=0;
RC7=1;
}
}
}
voidNaolingXiang()
{
inti;
if((kk==1)&&(Naoling_hour_1==cLOCk[2])&&(Naoling_minute_1==clock[1]))
{
RC5=1;
for(i=0;i<100;i++);
RC5=0;
for(i=0;i<500;i++);
}
if((kk==1)&&(Naoling_hour_2==clock[2])&&(Naoling_minute_2==clock[1]))
{
RC5=1;
for(i=0;i<100;i++);
RC5=0;
for(i=0;i<200;i++);
}
if((kk==1)&&(Naoling_hour_3==clock[2])&&(Naoling_minute_3==clock[1]))
{
RC5=1;
for(i=0;i<200;i++);
RC5=0;
for(i=0;i<500;i++);
}
}
//查询子程序
voidchaxun()
{
if(RD3==0)
{
ii++;
ii=ii%2;
}
while(1)
{
if(RD3==1)break;
}
if(ii==1)
{
KeyScan();
}
}
//主程序
voidmain()
{
keyinit();//键盘初始化
LCDinit();//LCD操作初始化
LCDShowTable();//显示空白表格
LCDShowGudingWord();//显示固定字符
get_temp();//读取温度
TMR0init();
while(1)
{
v_Get1302(clock);//读取时间、日历
display();
FlashMaohao();//冒号闪烁
KeyScan();//键盘扫描
GetWeek(clock[6]+2000,clock[4],clock[3]);
GetChinaCalendar(clock[6]+2000,clock[4],clock[3]);
//Naoling();
//NaolingXiang();
chaxun();
}
}