📄 time.c
字号:
#include<iom128v.h>
unsigned char second;
unsigned char minute;
unsigned char hour;
unsigned char time[9];
unsigned char sound=0;
extern unsigned char keytime;
extern unsigned char keypad(void);
extern void cls(unsigned x,unsigned y,unsigned char high,unsigned char width);
extern void asc_tran(unsigned char x,unsigned char y,unsigned char *asc_p);
extern void ocmj_write(unsigned char data);
extern void hz_tran(unsigned char x,unsigned char y,unsigned char *hz_p);
void timer0_init(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x08; //set async mode
TCNT0 = 0x00; //set count
TCCR0 = 0x05; //start timer
}
#pragma interrupt_handler timer0_ovf_isr:17
void timer0_ovf_isr(void)
{
TCNT0 = 0x00; //reload counter value
keytime++;
if(second>=59)
{
second=0;
if(minute>=59)
{
minute=0;
if(hour>=23)
{
hour=0;
}
else
{
hour++;
}
}
else
{
minute++;
}
}
else
{
second++;
}
if((PIND&0b00100000)==0) sound=1;
if (minute==0)
{
if (sound==0)
TIMSK|=0x40;
else
TIMSK&=0xbf;
}
else
{
TIMSK&=0xbf;
sound=0;
}
}
void timetoasc(void)
{
unsigned char i;
unsigned char temp;
temp=hour;
for(i=0;i<2;i++)
{
time[1-i]=temp%10+0x30;
temp=temp/10;
}
time[2]=':';
temp=minute;
for(i=0;i<2;i++)
{
time[4-i]=temp%10+0x30;
temp=temp/10;
}
time[5]=':';
temp=second;
for(i=0;i<2;i++)
{
time[7-i]=temp%10+0x30;
temp=temp/10;
}
time[8]=0;
cls(0,3,1,8);
asc_tran(4,52,time);
}
void timer2_init(void)
{
TCCR2 = 0x00;
TCNT2 = 0xe1;
TCCR2 = 0x03;
}
#pragma interrupt_handler timer2_ovf_isr:11
void timer2_ovf_isr(void)
{
static unsigned int i;
TCNT2 = 0xe1; //reload counter value
i++;
if(i<800)
{
PORTB^=0x80;
}
if(i>1600)
i=0;
}
void timecal(void)
{
unsigned char temp,step;
ocmj_write(0xf4);
hz_tran(2,1,"输入时间");
hz_tran(1,2,"按");
asc_tran(4,36,"SHIFT");
hz_tran(5,2,"确定");
asc_tran(4,52,"__:__:__");
for(temp=0;temp<9;temp++)
{
time[temp]='_';
}
time[2]=':';
time[5]=':';
time[8]=0;
step=0;
do
{
temp=keypad();
if(((temp&0x7f)!=0x7f)&((temp&0x7f)<0x0a))
{
switch (step)
{
case 0:{
if (temp<3)
{
hour=temp*10;
time[0]=temp+0x30;
step++;
}
break;
}
case 1:{
if(hour<20)
{
hour+=temp;
time[1]=temp+0x30;
step++;
}
else
{
if(temp<4)
{
hour+=temp;
time[1]=temp+0x30;
step++;
}
}
break;
}
case 2:{
if (temp<6)
{
minute=temp*10;
time[3]=temp+0x30;
step++;
}
break;
}
case 3:{
minute+=temp;
time[4]=temp+0x30;
step++;
break;
}
case 4:{
if(temp<6)
{
second=second*10;
time[6]=temp+0x30;
step++;
}
break;
}
case 5:{
second+=temp;
time[7]=temp+0x30;
step++;
break;
}
default:
{
for(step=0;step<9;step++)
{
time[step]='_';
}
time[2]=':';
time[5]=':';
time[8]=0;
step=0;
}
}
cls(0,3,1,8);
asc_tran(4,52,time);
}
}
while((temp&0x80)!=0x80);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -