?? 卡7萬年歷時鐘讀寫.c
字號:
void timer_1(void) interrupt 1 //中斷入口,閃爍
{
TH0=0x3c; //50ms定時
TL0=0xb0;
if(msec++==10) //500ms
{msec=0;a=~a; //閃爍標志反轉
if(a==0) //1秒后背光時間減一秒。
LedTime--;
}
}
//根據選擇調整相應項目并寫入DS1302
void Set(uchar sel,uchar sel_1)
{
uchar address,item;
uchar max,min;
if(sel==1) {address=0x8c; max=99;min=0;} //年
if(sel==2) {address=0x88; max=12;min=1;} //月
if(sel==3) {address=0x86; max=31;min=1;} //日
if(sel==4) {address=0x8a; max=7; min=1;} //星期
if(sel==6) {address=0x84; max=23;min=0;} //小時
if(sel==7) {address=0x82; max=59;min=0;} //分鐘
if(sel==8) {address=0x80; max=59;min=0;} //秒
if(sel==10) {address=0xc0; max=59;min=0;} //背光時間,最長1分鐘
if(sel==12) {address=0xc2; max=1;min=0;} //鬧鈴開關寄存器
if(sel==13) {address=0xc4; max=23;min=0;} //鬧鈴時寄存器
if(sel==14) {address=0xc6; max=59;min=0;} //鬧鈴分寄存器
item=R1302(address+1)/16*10+R1302(address+1)%16;
if (sel_1==0) item++; else item--;
if(item>max) item=min;
if(item<min) item=max;
W1302(0x8e,0x00); //允許寫操作
W1302(address,item/10*16+item%10); //寫入DS1302 //轉成BCD碼
W1302(0x8e,0x80); //寫保護,禁止寫操作
}
//屏幕顯示
void Out_LCM(void)
{ switch(model)
{
case 0: model0(); break;
case 1: model1(); break;
case 2: model2(); break; //在不同的條件下顯示不同的字符
case 3: model3(); break;
case 4: model4(); break;
case 5: model5(); break;
case 6: model6(); break;
}
}
/***********************model為零時第一行顯示時間,不為零時顯示system setup******/
void model0()
{
DisplayListChar(0,0,TIMER); //顯示固定字符串(Time)
OutputInformation(13,0,0x20); //不顯示
OutputInformation(4,0,0x20); //不顯示
OutputInformation(4,1,0x20); //不顯示
OutputInformation(15,1,0x20); //不顯示
OutputInformation(7,1,0x2f); //顯示固定字符 "/"
OutputInformation(10,1,0x2f); //顯示固定字符 "/"
OutputInformation(13,1,0x2f); //顯示固定字符 "/"
DisplayListChar(0,1,DATE); //顯示固定字符串Date(日期)
if(a==1) //冒號閃爍
{OutputInformation(7,0,0x3a); OutputInformation(10,0,0x3a);}
else
{OutputInformation(7,0,0x20); OutputInformation(10,0,0x20);}
/*******************model為零時第二行顯示日期,不為零顯示設置項目*******/
OutputInformation(5,1,R1302(0x8d)/16+0x30); //顯示年
OutputInformation(6,1,R1302(0x8d)%16+0x30);
OutputInformation(8,1,R1302(0x89)/16+0x30); //顯示月
OutputInformation(9,1,R1302(0x89)%16+0x30);
OutputInformation(11,1,R1302(0x87)/16+0x30); //顯示日
OutputInformation(12,1,R1302(0x87)%16+0x30);
OutputInformation(14,1,R1302(0x8b)%16+0x30); //顯示星期
OutputInformation(5,0,R1302(0x85)/16+0x30); //顯示小時
OutputInformation(6,0,R1302(0x85)%16+0x30);
OutputInformation(8,0,R1302(0x83)/16+0x30); //顯示分鐘
OutputInformation(9,0,R1302(0x83)%16+0x30);
OutputInformation(11,0,R1302(0x81)/16+0x30); //顯示秒
OutputInformation(12,0,R1302(0x81)%16+0x30);
}
/*************************model不為零時顯示系統設置***********************************/
//model為1時time閃爍,按下模式鍵后進入時間調整
void model1()
/*************************************判斷ID的值來顯示項目***********************/
{ OutputInformation(0,0,0x20); //不顯示
OutputInformation(1,0,0x20);
DisplayListChar(2,0,systemp); //第一行顯示system setup
if(id==0) //為0時顯示TIME date lalcak
{OutputInformation(9,1,0x20); //不顯示
OutputInformation(4,1,0x20); //不顯示
OutputInformation(15,1,0x20); //不顯示
DisplayListChar(5,1,DATE); //顯示date
DisplayListChar(10,1,alarmclock);//顯示lalcak
if(a==1)
{OutputInformation(0,1,0x20); //不顯示
OutputInformation(1,1,0x20); //不顯示
OutputInformation(2,1,0x20); //不顯示
OutputInformation(3,1,0x20); //不顯示
}
else
DisplayListChar(0,1,TIMER); //顯示time
}
else
{ //id不為零進入時間調整項目
OutputInformation(3,1,0x3a); //顯示固定字符 ":"
OutputInformation(6,1,0x3a); //顯示固定字符 ":"
OutputInformation(9,1,0x20); //不顯示
OutputInformation(10,1,0x20); //不顯示
OutputInformation(0,1,0x20); //不顯示
/****************************時顯示閃爍控制********************/
if((id==6)&&(a==1)) //id為5時時閃爍
{
OutputInformation(1,1,0x20); //不顯示
OutputInformation(2,1,0x20); //不顯示
}
else
{OutputInformation(1,1,R1302(0x85)/16+0x30); //顯示時
OutputInformation(2,1,R1302(0x85)%16+0x30);
}
/******************************分顯示閃爍控制********************/
if((id==7)&&(a==1)) //id為6時分閃爍
{
OutputInformation(4,1,0x20); //不顯示
OutputInformation(5,1,0x20); //不顯示
}
else
{OutputInformation(4,1,R1302(0x83)/16+0x30); //顯示分
OutputInformation(5,1,R1302(0x83)%16+0x30);
}
/******************************秒顯示閃爍控制********************/
if((id==8)&&(a==1)) //id為7時秒閃爍
{
OutputInformation(7,1,0x20); //不顯示
OutputInformation(8,1,0x20); //不顯示
}
else
{OutputInformation(7,1,R1302(0x81)/16+0x30); //顯示秒
OutputInformation(8,1,R1302(0x81)%16+0x30);
}
/*******************************Exit顯示閃爍控制********************/
if((id==9)&&(a==1)) //id為8時exit閃爍
{OutputInformation(11,1,0x20); //不顯示
OutputInformation(12,1,0x20); //不顯示
OutputInformation(13,1,0x20); //不顯示
OutputInformation(14,1,0x20); //不顯示
}
else
DisplayListChar(11,1,exit); //顯示exit
}
}
/***************************************modelo為2時date閃爍***********************************************/
void model2()
{
if(id==0)
{OutputInformation(9,1,0x20); //不顯示
OutputInformation(4,1,0x20); //不顯示
OutputInformation(15,1,0x20); //不顯示
DisplayListChar(0,1,TIMER); //顯示time
DisplayListChar(10,1,alarmclock); //顯示clock
if(a==1)
{OutputInformation(5,1,0x20); //不顯示
OutputInformation(6,1,0x20); //不顯示
OutputInformation(7,1,0x20); //不顯示
OutputInformation(8,1,0x20); //不顯示
}
else
DisplayListChar(5,1,DATE); //顯示date
}
/*****************************************************************************************************/
//id不為零時、進入日期調整
/*****************************************************************************************************/
else
{ OutputInformation(0,1,0x20); //不顯示
OutputInformation(11,1,0x20); //不顯示
OutputInformation(3,1,0x2f); //顯示固定字符 "/"
OutputInformation(6,1,0x2f); //顯示固定字符 "/"
OutputInformation(9,1,0x2f); //顯示固定字符 "/"
/****************************年顯示閃爍控制********************/
if((id==1)&&(a==1)) //id為1時年閃爍
{
OutputInformation(1,1,0x20); //不顯示
OutputInformation(2,1,0x20); //不顯示
}
else
{OutputInformation(1,1,R1302(0x8d)/16+0x30); //顯示年
OutputInformation(2,1,R1302(0x8d)%16+0x30);
}
/***************************月閃爍控制************************/
if((id==2)&&(a==1)) //id為2時月閃爍
{
OutputInformation(4,1,0x20); //不顯示
OutputInformation(5,1,0x20); //不顯示
}
else
{OutputInformation(4,1,R1302(0x89)/16+0x30); //顯示月
OutputInformation(5,1,R1302(0x89)%16+0x30);
}
/***************************日閃爍控制************************/
if((id==3)&&(a==1)) //id為2日閃爍
{
OutputInformation(7,1,0x20); //不顯示
OutputInformation(8,1,0x20); //不顯示
}
else
{OutputInformation(7,1,R1302(0x87)/16+0x30); //顯示日
OutputInformation(8,1,R1302(0x87)%16+0x30);
}
/***************************星期閃爍控制*********************************/
if((id==4)&&(a==1)) //id為2時星期閃爍
{
OutputInformation(10,1,0x20); //不顯示
}
else
{OutputInformation(10,1,R1302(0x8b)%16+0x30); //顯示星期
}
/**************************exit閃爍控制*********************************/
if((id==5)&&(a==1)) //id為5時exit閃爍
{ OutputInformation(12,1,0x20); //不顯示
OutputInformation(13,1,0x20); //不顯示
OutputInformation(14,1,0x20); //不顯示
OutputInformation(15,1,0x20); //不顯示
}
else
DisplayListChar(12,1,exit); //顯示exit
}
}
/*********************************************************************************/
/*model為3時進入鬧鈴項目
/**********************************************************************************/
void model3()
{
if(id==0)
{OutputInformation(9,1,0x20); //不顯示
OutputInformation(4,1,0x20); //不顯示
OutputInformation(15,1,0x20); //不顯示
DisplayListChar(0,1,TIMER); //顯示time
DisplayListChar(5,1,DATE); //顯示date
if(a==1)
{ OutputInformation(10,1,0x20); //不顯示
OutputInformation(11,1,0x20); //不顯示
OutputInformation(12,1,0x20); //不顯示
OutputInformation(13,1,0x20); //不顯示
OutputInformation(14,1,0x20);
}
else
DisplayListChar(10,1,alarmclock); //顯示cloak
}
/**************************id不為零進入鬧鈴設置顯示********************/
else
{if(id==12) //鬧鈴開關顯示
{DisplayListChar(0,1,ClockSet); //顯示ClockSet
OutputInformation(8,1,0x20);
OutputInformation(13,1,0x20);
OutputInformation(14,1,0x20);
/*****************************鬧鈴開關顯示********************************/
if(a==1) //A為閃爍標志
{OutputInformation(10,1,0x20); //不顯示
OutputInformation(11,1,0x20); //不顯示
OutputInformation(12,1,0x20); //不顯示
OutputInformation(13,1,0x20); //不顯示
}
else
{
if(R1302(0xc3)%16==0) //鬧鈴寄存器的值是否為零(關)
{DisplayListChar(10,1,ClockOff);}//顯示OFF
else
{OutputInformation(9,1,0x20); //不顯示
OutputInformation(12,1,0x20); //不顯示
OutputInformation(13,1,0x20); //不顯示
OutputInformation(14,1,0x20); //不顯示
OutputInformation(15,1,0x20); //不顯示
DisplayListChar(10,1,ClockOn); //顯示ON
}
}
}
else
{DisplayListChar(0,1,alarmclock); //顯示clock
OutputInformation(8,1,0x3a); //顯示固定字符 ":"
OutputInformation(5,1,0x20); //不顯示
OutputInformation(11,1,0x20); //不顯示
/**************************鬧鈴時閃爍顯示**********************/
if((id==13)&&(a==1)) //鬧鈴時閃爍
{
OutputInformation(6,1,0x20);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -