蓝桥杯
#include <STC15F2K60S2.H>
#include"seg.h"
#include"stdio.h"
#include"key.h"
unsigned key_mark=0,seg_mark=0;
unsigned int num=0;
unsigned int miao=50;
unsigned int fen=59;
unsigned int hour=23;
unsigned char seg_str[9];
unsigned char seg_buf[8];
unsigned char wei=0;
void seg_proc();
void key_proc();
void Timer0Init(void) //1毫秒@12.000MHz
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TMOD |= 0x01; //设置定时器模式
TL0 = 0x18; //设置定时初值
TH0 = 0xFC; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
EA=1;ET0=1;
P36=0;
}
void main(){
Timer0Init();
while(1){
void seg_proc();
void key_proc();
}
}
void t0() interrupt 1{
TL0 = 0x18;
TH0 = 0xFC;
num++;
if(num==1000){
if(miao) miao--;
num=0;
}
if(++seg_mark==100)
seg_mark=0;
if(++key_mark==500)
key_mark=0;
seg_dis(seg_buf,wei);//完成动态显示
if(++wei==8) wei=0;
}
void seg_proc(){
if(seg_mark) return;
sprintf(seg_str,"%02d-%02d-%02d",hour,fen,miao);//存入字符串
seg_tran(seg_str,seg_buf); //转换
}
void key_proc(){
if(key_mark) return;
}