📄 main.c
字号:
d = Read_One_Byte(0x02);//读取24的分的数值
Mcs=0;Scs=1;
Disp1_Digit(4,8,zero+(d/10)*16);
Disp1_Digit(4,16,zero+(d%10)*16);
}
if(Secb==1) //秒闪烁标志位
{
if(flag==1)
{
d = Read_One_Byte(0x03);//读取24的秒的数值
Mcs=0;Scs=1;
Disp1_Digit(4,32,zero+(d/10)*16);
Disp1_Digit(4,40,zero+(d%10)*16);
}
else
{
Mcs=0;Scs=1;
Disp1_Digit(4,32,space); //显示空格
Disp1_Digit(4,40,space);
}
}
else
{
d = Read_One_Byte(0x03);//读取24的秒的数值
Mcs=0;Scs=1;
Disp1_Digit(4,32,zero+(d/10)*16);
Disp1_Digit(4,40,zero+(d%10)*16);
}
}
/******************************************************************************/
void id_case1_key(void)//id为1时的下一级选择
{
if(Add_Key == 0) //增加
{
Delay(100);
if(Add_Key == 0)
Set_time(id,0); //调用Set_time函数
while(Add_Key ==0);
}
if (Dec_Key==0) //减少
{
Delay(100);
if(Dec_Key == 0)
Set_time(id,1);
while(Dec_Key ==0);
}
}
/******************************************************************************/
void Set_time(unsigned char sel, bit sel_1) //根据选择调整相应项目并写入DS8563
{
signed char address,item;
signed char max,mini;
if(sel==7)
{
address=0x02; max=0;mini=0;
}
//秒
if(sel==6)
{
address=0x03; max=59;mini=0;
}
//分钟
if(sel==5)
{
address=0x04; max=23;mini=0;
}
//小时
if(sel==3)
{
address=0x05; max=31;mini=1;
}
//日
if(sel==2)
{
address=0x07; max=12;mini=1;
}
//月
if(sel==1)
{
address=0x08; max=99; mini=0;
}
//年
if(sel==4)
{
address=0x16; max=7;mini=1;
}
//星期
//读取8563某地址上的数值转换成10进制赋给item
item=((read_clock(address))/16)*10 + (read_clock(address))%16;
if(sel_1==0)
item++;
else
item--;
if(item>max) item=mini;
if(item<mini) item=max;
write_clock(address,(item/10)*16+item%10);//转换成16进制写入8563
}
/******************************************************************************/
void id_case2_key(void)//id为1时的下一级选择
{
if(Add_Key == 0) //增加
{
Delay(100);
if(Add_Key == 0)
Set_Bell(id2,0); //调用Set_time函数
while(Add_Key ==0);
}
if (Dec_Key==0) //减少
{
Delay(100);
if(Dec_Key == 0)
Set_Bell(id2,1);
while(Dec_Key ==0);
}
}
/******************************************************************************/
void Set_Bell(unsigned char sel, bit sel_1)//根据选择调整相应项目并写入24
{
signed char address,item;
signed char max,mini;
if(sel==4)
{
address=0x03; max=59;mini=0;
}
//秒
if(sel==3)
{
address=0x02; max=59;mini=0;
}
//分
if(sel==2)
{
address=0x01; max=23; mini=0;
}
//时
if(sel==1)
{
address=0x04;
if(Add_Key ==0 || Dec_Key ==0)
Bell_Swh=~Bell_Swh;
Write_One_Byte(address,Bell_Swh);
}
//开关
item = Read_One_Byte(address);
if(sel_1==0)
item++;
else
item--;
if(item>max) item=mini;
if(item<mini) item=max;
Write_One_Byte(address,item);//写入24
}
/******************************************************************************/
void Timer0_Init(void)//定时器0初始化
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
/******************************************************************************/
void Timer0(void) interrupt 1 using 1//中断入口,冒号闪烁
{
static unsigned char timecount = 0;//
TH0=(65535-50000)/256; //50ms定时
TL0=(65535-50000)%256;
timecount++;
if(timecount > 9)//500MS
{
timecount = 0;
flag = ~flag;
}
}
/******************************************************************************/
void Lcd_Mark1(void)//在预定的位置上写入汉字)
{
Clr_Scr();//清屏
// frame();//显示边框
Mcs=1;Scs=0;
Disp_Chinese(6,8,shi);
Disp_Chinese(6,24,wen);
Disp_Chinese(2,8,xing);
Disp_Chinese(2,24,qi);
Disp_Chinese(0,32,nian);
Disp_Digit(6,56,point);
Mcs=0;Scs=1;
Disp1_Digit(0,56,m);
Disp1_Chinese(6,8,sheshidu);
if(Bell_Swh == 1)//闹钟为开
{
Mcs=0;Scs=1;
Disp1_Chinese(6,40,biaozhi);//显示闹钟图标
}
}
/******************************************************************************/
void Lcd_Mark2(void)
{
Clr_Scr();//清屏
// frame();//显示边框
Mcs=1;Scs=0;//显示闹钟设定等几个汉字
Disp_Chinese(2,16,nao);
Disp_Chinese(2,32,zhong);
Disp_Chinese(2,48,she);
Mcs=0;Scs=1;
Disp1_Chinese(2,0,ding);
Disp1_Digit(4,0,maohao);
Disp1_Digit(4,24,maohao);
}
/******************************************************************************/
void main(void)
{
unsigned char a;
Init_8563();
Timer0_Init();
Init_lcd();//设置液晶显示器
Delay(10);
Disp_Img(logo);
Delay(30000);
Clr_Scr();//清屏
Bell_Swh = Read_One_Byte(0x04);//读取开关的状态
Lcd_Mark1();
while(1)//主循环
{
if(Add_Key == 0 && Dec_Key == 0)
{
Delay(1000);
if(Add_Key == 0 && Dec_Key == 0)
{
Init_8563();
}
}
if(Add_Key == 0)
{
Delay(1000);
if(Add_Key ==0)
{
//写入闹钟初始值08:00:00
Write_One_Byte(0x01,8);
Write_One_Byte(0x02,0);
Write_One_Byte(0x03,0);
}
}
if(OK_Key == 0 && Dec_Key ==0 )//进入闹钟设置界面
{
Delay12864(100);
if(OK_Key == 0 && Dec_Key ==0 )
{
Lcd_Mark2();
if(Bell_Swh == 0)
{
Mcs=0;Scs=1;Disp1_Chinese(2,32,guan);
}
//关
else
{
Mcs=0;Scs=1;Disp1_Chinese(2,32,kai);
}
while(1)
{
if (OK_Key == 0) // 设置和选择项目键
{
Delay(1000);
if(OK_Key == 0)
{
id2++;if(id2>5) id2=0;
}
while(OK_Key == 0);//等待键松开
}
switch( id2 )
{
case 0:Disp2();break;//正常显示
case 1:Kgb = 1;id_case2_key();Disp2();break;//开关
case 2:Kgb= 0;Hourb=1;id_case2_key();Disp2();break;//
case 3:Hourb=0;Minb=1;id_case2_key();Disp2();break;
case 4:Minb=0;Secb=1;id_case2_key();Disp2();break;
case 5:Secb=0;id2 = 0;Lcd_Mark1();goto FF;break;//返回主界面
default:break;
}
}
//while(1)
}
//if
}
//if
/*****************************************/
FF: //返回主界面
/*****************************************/
if(flag == 0)
{
Mcs=0;Scs=1;
Disp1_Digit(2,8,maohao);// :闪烁
Disp1_Digit(2,32,maohao);
}
else
{
Mcs=0;Scs=1;
Disp1_Digit(2,8,space);//显示空格
Disp1_Digit(2,32,space);
}
if (OK_Key == 0) // 设置和选择项目键
{
Delay(1000);
if(OK_Key == 0)
{
id++;if(id>7)id=0;
}
while(OK_Key == 0);//等待键松开
}
switch( id )
{
case 0:sec = 0; Disp( );break;//正常显示
case 1:year = 1;id_case1_key();Disp();break;//年
case 2:year=0;mon=1;id_case1_key();Disp();break;//月
case 3:mon=0;day=1;id_case1_key();Disp();break; //日
case 4:day=0;weekk=1;id_case1_key();Disp();break;//星期
case 5:weekk=0;hour=1;id_case1_key();Disp();break; //小时
case 6:hour=0;min=1;id_case1_key();Disp();break; //分钟
case 7:min=0;sec=1;id_case1_key();Disp();break; //秒
default:break;
}
if(Bell_Swh == 1)//闹钟为开
{
H_2402=Read_One_Byte(0x01);//读取2408的
S_2402=Read_One_Byte(0x02);
d=read_clock(0x04);//读小时
e=d;
d=d>>4;
e=e&0x0f;
H_8563=10*d+e;
d=read_clock(0x03);//读分钟
e=d;
d=d>>4;
e=e&0x0f;
S_8563=10*d+e;
if(H_2402 == H_8563)
{
if(S_2402 == S_8563)
{
Clr_Scr();//清屏
// frame();//显示边框
Mcs=1;Scs=0;
Disp_Chinese(3,16,nao);//闹钟显示时间到!
Disp_Chinese(3,32,zhong);
Disp_Chinese(3,48,shit);
Mcs=0;Scs=1;
Disp1_Chinese(3,0,jian);
Disp1_Chinese(3,16,dao);
Disp_Digit(3,40,fh);
while(S_2402 == S_8563)//判断是否到闹钟设定时间
{
for(a=0; a<100; a++)//BELL脉冲输出,驱动蜂鸣器
{
if(a<50)
{
Bell_Out = 0;Delay(100);
}
else
{
Bell_Out = 1;Delay(100);
}
}
d=read_clock(0x03);//读分钟
e=d;
d=d>>4;
e=e&0x0f;
S_8563=10*d+e;
}
Lcd_Mark1();
}
//if
}
}
//if
}
//while
}
//main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -