单片机电子时钟程序
} } } /***************************************************** scanf_dat_temp[0] = P_leab_led_7[scanf_dat[0]/10];
}
/************************************
按键二长按处理
*************************************/
void isr_button2_proces(void)
{
if(menu_button2_down==1)
{
if(button2==0)
{
time.delaycount--;
if(time.delaycount==length_whack_ms-2)//消抖部分 (10~20ms)
{
if(time.mode==1) start_stopwatch = ~start_stopwatch ;
if(time.mode==10)
{
cymometer_start_flag =~cymometer_start_flag;
TL1 = 0;
TH1 = 0;
cymometer1_start_flag=0;
}
time_add();
if(time.delaycount==0)
{
time.delaycount = auto_regulator_ms;
button2_length_whack_flag = 1;
// menu_button2_down = 0;
}
}
else
{
menu_button2_down = 0;
time.delaycount = auto_regulator_ms;
button2_length_whack_flag = 0;
}
}
if(button2_length_whack_flag)
{
if(time.mode>1)
{
button2_length_whack_flag = 0;
time_add();
TR1 =0;
time.cymometer[0]=0;
TH1=0;
time.cymometer[1]=0;
TL1=0;
cymometer_start_flag =0;
}
}
/************************************************
按键三处理函数
************************************************/
void button3_proces(void)
{
if((menu_button3_down==0)&&(button3==0))
{
menu_button3_down = 1;
time.delaycount =length_whack_ms;
}
}
/************************************
按键三长按处理
*************************************/
void isr_button3_proces(void)
{
if(menu_button3_down==1)
{
if(button3==0)
{
time.delaycount--;
if(time.delaycount==length_whack_ms-2) //消抖部分 (10~20ms)
{
if(time.mode==1) stopwatch_clear_flag = 1;
if(time.mode==10){cymometer1_start_flag=1;time.cymometer_count =cymometer_1s;
TL1 = 0;
TH1 = 0;
start_stopwatch = 0;
}
time_sub();
}
if(time.delaycount==0)
{
time.delaycount = auto_regulator_ms;
button3_length_whack_flag = 1;
// menu_button2_down = 0;
}
}
else
{
menu_button3_down = 0;
time.delaycount = auto_regulator_ms;
button3_length_whack_flag = 0;
}
}
if(button3_length_whack_flag)
{
if(time.mode>1)
{
button3_length_whack_flag = 0;
time_sub();
TR1 =0;
time.cymometer[0]=0;
TH1=0;
time.cymometer[1]=0;
TL1=0;
cymometer1_start_flag =0;
}
}
}
数码驱动部分
*****************************************************/
void delay(unsigned char z)
{
unsigned char x,y;
for(x=0;x
while(--y);}
}
/****************************************************
595 驱动
****************************************************/
void _74hc595(unsigned char dat)
{
unsigned char n;
sh=0;
st=0;
for(n=0;n<8;n++)
{
if(dat&0x80)ds=1;
else ds=0;
sh=1;
dat<=1;
sh=0;
}
st=1;
}
/******************************************************
扫描部分
******************************************************/
void sanf_display(void)
{
static unsigned char n;
unsigned char scanf_dat_temp[4];
if((menu_button2_down ==1)&&(time.mode==0))
{
if(button2_length_whack_flag)
{
Alarm_on_off = ~Alarm_on_off;
button2_length_whack_flag = 0;
time.delaycount = Alarm_switch_on_off_ms;
}
scanf_dat[0] = time.AlarmHou;
scanf_dat[1] = time.AlarmMin;
// Alarm_on_off_display = 1;
}
// else Alarm_on_off_display = 0;
if((menu_button3_down ==1)&&(time.mode==0))
{
scanf_dat[0] = time.mon;
scanf_dat[1] = time.day;
}
scanf_dat_temp[1] = P_leab_led_7[scanf_dat[0]%10];
scanf_dat_temp[2] = P_leab_led_7[scanf_dat[1]/10];
scanf_dat_temp[3] = P_leab_led_7[scanf_dat[1]%10];
// if(Alarm_on_off_display)
// {
if(Alarm_on_off)
{
//scanf_dat_temp[0] &= 0x7f;
//scanf_dat_temp[1] &= 0x7f;
//scanf_dat_temp[2] &= 0x7f;
scanf_dat_temp[3] &= 0xf7;
// }
}
if(time.count>=50&&time.mode==0&&menu_button3_down ==0&&menu_button2_down ==0)scanf_dat_temp[1] &= 0xf7;
if(menu_button2_down||menu_button3_down) flash_control = 0;
if(flash_control)
{
if(time.mode&0x01){scanf_dat_temp[0] = 0xff; scanf_dat_temp[1] = 0xff;}
else {scanf_dat_temp[2] = 0xff; scanf_dat_temp[3] = 0xff;}
}
for(n=0 ;n<4;n++)
{
_74hc595( scanf_dat_temp[n]);
switch(n)
{
case 0:led0=1;led1=0; led2=0; led3=0;break;
case 1:led0=0;led1=1; led2=0; led3=0;break;
case 2:led0=0;led1=0; led2=1; led3=0;break;
case 3:led0=0;led1=0; led2=0; led3=1;break;
default :led0=0;led1=0; led2=0; led3=0;break;
}
delay(5);
_74hc595(0xff);
led0 = 0; led1 = 0; led2 = 0; led3 = 0;
delay(1);
}
}
/**********************************************************
加载显存
**********************************************************/
void proces_start(void)
{
unsigned char temp[6];
unsigned int dattemp;
if(time.mode==0) //时间显示
{
scanf_dat[0] = time.hou;
scanf_dat[1] = time.min;
}
else if(time.mode==1)//秒表显示
{
if(time.stopwatch[2]>0)
{
scanf_dat[0] = time.stopwatch[2];
scanf_dat[1] = time.stopwatch[1];
}
else
{
scanf_dat[0] = time.stopwatch[1];
scanf_dat[1] = time.stopwatch[0];
}
}
else if(time.mode<4)//
{
scanf_dat[0] = time.hou;
scanf_dat[1] = time.min;
}
else if(time.mode<6)
{
scanf_dat[0] = time.mon;
scanf_dat[1] = time.day;
}
else if(time.mode<8)
{
scanf_dat[0] = time.year[1];
scanf_dat[1] = time.year[0];
}
else if(time.mode<10)
{
scanf_dat[0] = time.AlarmHou;
scanf_dat[1] = time.AlarmMin;
}
else
{
dattemp = time.cymometer[1];
dattemp = dattemp<8;
dattemp+=time.cymometer[0];
temp[1] = dattemp%10000/100;
temp[0] = dattemp%100;
scanf_dat[0] = temp[1];
scanf_dat[1] = temp[0];
}
if((time.AlarmHou==time.hou)&&(time.AlarmMin==time.min)&&(Alarm_on_off==1))
{
buzzer = 1;
}
else buzzer=0;
}
/*****************************************************************************
系统初始化
*****************************************************************************/
void syster_init(void)
{
time.sec = 0;
time.min = 59;
time.hou = 23;
time.day = 28;
time.mon = 2;
time.year[0] = 13;
time.year[1] = 20;
time.AlarmHou = 6;
time.AlarmMin = 30;
time.mode = 0;
time.stopwatch[0]=0;
time.stopwatch[1]=0;
time.stopwatch[2]=0;
Time_Count0_Init();
}
main()
{
syster_init();
while(1)
{
单片机电子时 相关文章:
- 51单片机电子时钟程序(12-01)
- 我用单片机写的电子时钟(11-29)
- 用单片机做的电子时钟(11-29)
- 51单片机电子时钟(11-29)
- 通过51单片机实现电子时钟功能并通过LCD1602显示(11-26)
- 用51单片机做的电子时钟(11-23)