前言
近期比较紧张,努力了一段时间,反而更害怕一些偶然因素导致不能达到自己预期的奖项,但毕竟纠结这种无用,还是记录一下自己的备赛过程,继续好好努力吧。这套题,以为很简单,一顿敲很快就做完。但上4t一测,被扣了20分。。。。难崩啊,主要有2个坑点,一个是对初始输入时间的理解,我刚开始是将切到输入界面的时间定为初始时间,但最正确的应该是输入第一个数的时间,且s5清零后这个时间要重新来记。第二个坑点就是,将时间写入e2prom的时候,要写入的是十进制的,我把没处理的bcd直接传进去了。题目没要求读出来,所以错了这个也是没现象的,只能当作经验下次碰到注意一下。
代码
main文件
#include <STC15F2K60S2.H>
#include "ds1302.h"
#include "iic.h"
#define control(x,y) P0=y;P2=x;P2=0
typedef unsigned char uchar ;
typedef unsigned int uint ;
code unsigned char Seg_Code[] =
{
0xc0, //0
0xf9, //1
0xa4, //2
0xb0, //3
0x99, //4
0x92, //5
0x82, //6
0xf8, //7
0x80, //8
0x90, //9
0xff, //Ãð
0xbf, //- 11
0xc6, //C12
0xa1, //d13
0x86, //E14
0x8e //F
};
uchar Seg_Bit[9]={10,10,10,10,10,10,10,10,10};
uchar interface;
uchar count_key;
uchar hour=0x23,sec=0x09,min=0x59;
uchar hour_save;
uchar min_save;
uchar count_time;
uint input;
uchar input_value;
uint input_save=65522;
bit flag_input;
uchar count_input;
uchar value1;
uchar value2;
bit flag_save;
uchar L[5];
bit flag_big;
bit flag_hour;
uchar hour_show;
uchar min_show;
void Timer2Init(void)
{
AUXR |= 0x04; //?????1T??
T2L = 0x20; //??????
T2H = 0xD1; //??????
AUXR |= 0x10; //???2????
IE2|= 0x04;
EA=1;
}
void t2int() interrupt 12 //????
{ static Seg_Com=1;
///ÖÜÆÚË¢ÐÂ
++count_key;
++count_time;
///ÊýÂë¹Ü
control(0xc0,0x00);
control(0xe0,Seg_Code[Seg_Bit[Seg_Com]]);
control(0xc0,1<<(Seg_Com-1));
if(++Seg_Com>8) Seg_Com=1;
///led///
control(0x80,~(L[4]<<3 |L[3]<<2 |L[2]<<1 |L[1]));
}
void System_Init()
{
control(0x80,0xff);
control(0xa0,0x00);
Set_Time(0x23,0x09,0x59);//¸Õ¿ªÊ¼ÏÔʾ0£¬½â¾ö·½·¨£¬³õʼ»¯¸³³õÖµ
Timer2Init();
}
void Data_Task()
{ if(T2H<0xd9)
{
if(count_time<150)
{
{count_time=0;
hour=Read_Ds1302_Byte(0x85);
min=Read_Ds1302_Byte(0x83);
sec=Read_Ds1302_Byte(0x81);
}
}
if(flag_save==1)
{flag_save=0;
value1=input_save/256;
value2=input_save%256;
Write_24c02(0x00,hour_save);
Write_24c02(0x01,min_save);
Write_24c02(0x02,value1);
Write_24c02(0x03,value2);
}
}
}
void Logic_Task()
{
if(flag_input==1)
{
flag_input=0;
input=input*10+input_value;
++count_input;
}
L[1]=(interface==0)?(1):(0);
L[2]=(interface==1)?(1):(0);
L[3]=(interface==2)?(1):(0);
L[4]=(flag_big)?(1):(0);
if(count_input==1&&flag_hour==0)
{hour_save=(hour/16*10)+(hour%16);
hour_show=hour;
min_show=min;
min_save=(min/16*10)+(min%16);
flag_hour=1;
}
}
void Display_Task()
{ if(interface==0)//ʱ¼ä
{
Seg_Bit[1]=hour/16;
Seg_Bit[2]=hour%16;
Seg_Bit[3]=11;
Seg_Bit[4]=min/16;
Seg_Bit[5]=min%16;
Seg_Bit[6]=11;
Seg_Bit[7]=sec/16;
Seg_Bit[8]=sec%16;
}
if(interface==1)//ʱ¼ä
{
Seg_Bit[1]=12;
Seg_Bit[2]=10;
Seg_Bit[3]=10;
Seg_Bit[4]=10;
Seg_Bit[5]=(input>999)?(input/1000%10):(10);
Seg_Bit[6]=(input>99)?(input/100%10):(10);
Seg_Bit[7]=(input>9)?(input/10%10):(10);
Seg_Bit[8]=(input>0)?(input%10):(10);
}
if(interface==2)//ʱ¼ä
{
Seg_Bit[1]=14;
Seg_Bit[2]=10;
Seg_Bit[3]=10;
Seg_Bit[4]=hour_show/16;
Seg_Bit[5]=hour_show%16;
Seg_Bit[6]=11;
Seg_Bit[7]=min_show/16;
Seg_Bit[8]=min_show%16;
}
}
uchar Read_Key()
{ static uchar count_press=0;
static uchar flag_press=0;
uchar value;
uchar x=0,y=0;
P3=0x0f;P4=0x00;
if(P30==0) x=3;
if(P31==0) x=2;
if(P32==0) x=1;
if(P33==0) x=0;
P3=0xf0;P4=0xff;
if(P34==0) y=4;
if(P35==0) y=3;
if(P42==0) y=2;
if(P44==0) y=1;
if(y)
{
if((++count_press>=8)&&(flag_press==0))
{
count_press=0;
flag_press=1;
value=x+y*4;
}
}
else
{
count_press=0;
flag_press=0;
}
return value;
}
void Key_Task()
{
uchar key_value=0;
if(count_key>5)
{
count_key=0;
key_value=Read_Key();
}
if(key_value==4)
{
if(++interface==3)
{interface=0;
}
if(interface==2)//½øÈë¼Ç¼½çÃ濪ʼ´æÊý¾Ý
{
count_input=0;
flag_hour=0;
flag_save=1;
if(input>input_save)
{flag_big=1;
}
else{flag_big=0;}
input_save=input;
input=0;
}
}
if(key_value==5)/s5ÇåÁã
{if(interface==1)
{flag_hour=0;
input=0;
count_input=0;
}
}
if(interface==1 && count_input<4)
{
if(key_value==10)
{
flag_input=1;
input_value=1;
}
if(key_value==14)
{
flag_input=1;
input_value=2;
}
if(key_value==6)
{
flag_input=1;
input_value=0;
}
if(key_value==18)
{
flag_input=1;
input_value=3;
}
if(key_value==9)
{
flag_input=1;
input_value=4;
}
if(key_value==13)
{
flag_input=1;
input_value=5;
}
if(key_value==17)
{
flag_input=1;
input_value=6;
}
if(key_value==8)
{
flag_input=1;
input_value=7;
}
if(key_value==12)
{
flag_input=1;
input_value=8;
}
if(key_value==16)
{
flag_input=1;
input_value=9;
}
}
}
int main()
{
System_Init();
while(1)
{
Data_Task();
Logic_Task();
Display_Task();
Key_Task();
}
}
底层驱动
就放个需要自己写的部分