当前位置:网站首页>The seventh finals of the Blue Bridge Cup
The seventh finals of the Blue Bridge Cup
2022-06-13 00:44:00 【Hao Yuehua】
I always feel that the title is ambiguous , For example, press the original key After loading , That is, if you press other after modification key Do not load into epprom, Always consider the wrong way to manipulate . The cleaning and judgment of all kinds of marks are really annoying . There are always some fine controls that need to be debugged , Maybe this is the level of a master .
main
#include "sys.h"
u8 s=0;
u8 smgtime=0;
u8 keytime=0;
u16 ft=0;// Flash time
bit ff=0;// Flashing sign
u16 pl=0;// frequency
u16 zq=0;// cycle
u16 plt=0;// Time to measure frequency
bit event=0;//0 lower than 1 beyond
u16 adc=0;// Measured voltage value
u16 adct=0;// Read ADC Time interval of
u8 uic=0; //0 The clock displays normally 1 Flash time 2 Flash points 3 Flash second
//4 Voltage measurement 5 Flash voltage up 6 Under flash voltage
//7 Frequency measurement shows 8 Cycle display 9 Query display 10 Show event time
u16 rt=0;// Read interval
bit modify=0;// Modify the time stamp
bit modify_v=0;// Modify the voltage sign
u8 wi=0;// write in epprom Count
u8 wi2=0;
bit wt=0;// Save event time flag
void ClearFlag(){
if(modify){
if(rkey!=7)modify=0;
}
if(modify_v==1){
if(rkey!=6)modify_v=0;
}
}
void SaveTimeTe(){// Save the time when the event occurred
if(wt){
switch(wi2){
case 0:
Write_epprom(2,BTIME[0]);
break;
case 1:
Write_epprom(3,BTIME[1]);
break;
case 2:
Write_epprom(4,BTIME[2]);
case 3:
wi2=0;
wt=0;
break;
}
wi2++;
}
}
// Save upper voltage limit and lower voltage limit
void SaveToep(){
if(modify_v==2){
switch(wi){
case 0:
Write_epprom(0,ADLIM[0]/100);
wi++;
break;
case 1:
Write_epprom(1,ADLIM[1]/100);
wi++;
break;
case 2:
wi=0;
modify_v=0;
break;
}
}
}
void UISetting(){
if(smgtime>45){
smgtime=0;
SaveTimeTe();
if(!uic){
DT[0]=TIME[0]/10;
DT[1]=TIME[0]%10;
DT[2]=11;
DT[3]=TIME[1]/10;
DT[4]=TIME[1]%10;
DT[5]=11;
DT[6]=TIME[2]/10;
DT[7]=TIME[2]%10;
}
else if(uic==1){
DT[0]=ff?TIME[0]/10:10;
DT[1]=ff?TIME[0]%10:10;
DT[2]=11;
DT[3]=TIME[1]/10;
DT[4]=TIME[1]%10;
DT[5]=11;
DT[6]=TIME[2]/10;
DT[7]=TIME[2]%10;
}
else if(uic==2){
DT[0]=TIME[0]/10;
DT[1]=TIME[0]%10;
DT[2]=11;
DT[3]=ff?TIME[1]/10:10;
DT[4]=ff?TIME[1]%10:10;
DT[5]=11;
DT[6]=TIME[2]/10;
DT[7]=TIME[2]%10;
}
else if(uic==3){
DT[0]=TIME[0]/10;
DT[1]=TIME[0]%10;
DT[2]=11;
DT[3]=TIME[1]/10;
DT[4]=TIME[1]%10;
DT[5]=11;
DT[6]=ff?TIME[2]/10:10;
DT[7]=ff?TIME[2]%10:10;
}
else if(uic==4){
DT[0]=11;
DT[1]=1;
DT[2]=11;
DT[3]=10;
DT[4]=adc/1000;
DT[5]=adc/100%10;
DT[6]=adc/10%10;
DT[7]=adc%10;
}
else if(uic==5){
DT[0]=ff?ADLIM[0]/1000:10;
DT[1]=ff?ADLIM[0]/100%10:10;
DT[2]=ff?ADLIM[0]/10%10:10;
DT[3]=ff?ADLIM[0]%10:10;
DT[4]=ADLIM[1]/1000;
DT[5]=ADLIM[1]/100%10;
DT[6]=ADLIM[1]/10%10;
DT[7]=ADLIM[1]%10;
}
else if(uic==6){
DT[0]=ADLIM[0]/1000;
DT[1]=ADLIM[0]/100%10;
DT[2]=ADLIM[0]/10%10;
DT[3]=ADLIM[0]%10;
DT[4]=ff?ADLIM[1]/1000:10;
DT[5]=ff?ADLIM[1]/100%10:10;
DT[6]=ff?ADLIM[1]/10%10:10;
DT[7]=ff?ADLIM[1]%10:10;
}
else if(uic==7||uic==8){
DT[0]=11;
DT[1]=2;
DT[2]=11;
DT[3]=(uic==7?pl/10000%10:zq/10000%10);
DT[4]=(uic==7?pl/1000%10:zq/1000%10);
DT[5]=(uic==7?pl/100%10:zq/100%10);
DT[6]=(uic==7?pl/10%10:zq/10%10);
DT[7]=(uic==7?pl%10:zq%10);
}
else if(uic==9){
DT[0]=10;
DT[1]=10;
DT[2]=10;
DT[3]=10;
DT[4]=10;
DT[5]=10;
DT[6]=0;
DT[7]=event?1:0;
}
else if(uic==10){
DT[0]=BTIME[0]/10;
DT[1]=BTIME[0]%10;
DT[2]=11;
DT[3]=BTIME[1]/10;
DT[4]=BTIME[1]%10;
DT[5]=11;
DT[6]=BTIME[2]/10;
DT[7]=BTIME[2]%10;
}
}
}
void KeyConsole(){
if(keytime>12){
keytime=0;
key_scan();
if(rkey){
ClearFlag();
switch(rkey){
case 7:// The clock
uic=0;
if(modify){
modify=0;
WriteTime();
}
break;
case 6:// voltage
uic=4;
if(modify_v==1)modify_v=2;
break;
case 5:// frequency
uic=7;
break;
case 4:// choice
if(uic<4){
if(uic==3)uic=1;
else{
uic=++uic%4;
}
}
else if(4<=uic&&uic<7){
if(uic==6)uic=5;
else {
uic=++uic%7;
}
}
else if(uic==7||uic==8){
uic=(uic==7?8:7);
}
else if(uic==9||uic==10){
uic=(uic==9?10:9);
}
break;
case 9:// Inquire about
uic=9;
break;
case 11:// Add
if(uic==1||uic==2||uic==3){
modify=1;
if(uic==1) TIME[uic-1]=++TIME[uic-1]%24;
else if(uic==2||uic==3)TIME[uic-1]=++TIME[uic-1]%60;
}
else if(uic==5||uic==6){
ADLIM[uic==5?0:1]+=500;
modify_v=1;
}
break;
case 10:// reduce
if(uic==1||uic==2||uic==3){
if(!TIME[uic-1])break;
TIME[uic-1]--;
modify=1;
}
else if(uic==5||uic==6){
if(!ADLIM[uic==5?0:1])break;
ADLIM[uic==5?0:1]-=500;
modify_v=1;
}
break;
}
}
SaveToep();
}
}
void main(){
sys_init();
Timer1Init();
WriteTime();
Timer0Init();
while(1){
KeyConsole();
UISetting();
if(rt>1000){
rt=0;
if(uic!=1&&uic!=2&&uic!=3)
ReadTime();
}
if(adct>450){
adct=0;
adc= 5000/255* Read_adc(0x03);
if(adc>ADLIM[0]||adc<ADLIM[1]){
event=adc>ADLIM[0]?1:0;
BTIME[0]=TIME[0];
BTIME[1]=TIME[1];
BTIME[2]=TIME[2];
wt=1;
wi2=0;
}
}
}
}
void TIME1() interrupt 3{
smg_play(DT[s],s++);
if(s>7)s=0;
smgtime++;keytime++;
rt++;
adct++;
if(uic==1||uic==2||uic==3||uic==5||uic==6){
if(ft++==1000){
ff=~ff;
ft=0;
}
}
else
ft=0;
if(plt==0){
TR0=1;
plt++;
}
else if(plt++==500){
plt=0;
TR0=0;
pl=TH0<<8|TL0;
pl<<=1;
TH0=TL0=0;
zq=1000000/pl;
}
}sys.c
#include "sys.h"
u8 code SMGINDEX[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff
,0xbf // -
};
u8 DT[]={10,10,10,10,10,10,10,10};
u8 key_state=0;
u8 rkey=0;
u8 key_v=0;
u8 xdata TIME[]={23,59,50};
u8 xdata BTIME[]={0,0,0};
u16 xdata ADLIM[]={0,0};
void Delay5ms() //@12.000MHz
{
unsigned char i, j;
i = 59;
j = 90;
do
{
while (--j);
} while (--i);
}
// System initialization and epprom initialization
void sys_init(){
u8 temp1;
u8 temp2;
P0=0xff;
lock(7);
P0=0;
lock(6);
P0=0;
lock(5);
P0=0xff;
lock(4);
temp1= Read_epprom(0x10);
Delay5ms();
temp2= Read_epprom(0x11);
Delay5ms();
if( temp1!=9&&temp2!=9){//255*255
Write_epprom(0x10,9);
Delay5ms();
Write_epprom(0x11,9);
Delay5ms();
Write_epprom(0,20);
Delay5ms();
Write_epprom(1,10);
Delay5ms();
ADLIM[0]= Read_epprom(0)*100;
Delay5ms();
ADLIM[1]= Read_epprom(1)*100;
Delay5ms();
}
else {
ADLIM[0]= Read_epprom(0)*100;
Delay5ms();
ADLIM[1]= Read_epprom(1)*100;
Delay5ms();
BTIME[0]= Read_epprom(2);
Delay5ms();
BTIME[1]= Read_epprom(3);
Delay5ms();
BTIME[2]= Read_epprom(4);
Delay5ms();
}
}
void smg_play(u8 du,u8 we){
P0=0xff;
lock(7);
P0=0;
P0=1<<we;
lock(6);
P0=0xff;
P0=SMGINDEX[du];
lock(7);
}
void key_scan(){
switch(key_state){
case 0:
key_v=0;
P3=P3|0x0f;
P42=0;
P44=0;
if((P3&0x0f)!=0x0f)key_state=1;
break;
case 1:
P3=P3|0x0f;
P42=0;
P44=0;
if((P3&0x0f)!=0x0f){
key_state=2;
if(!P30)key_v=7;
else if(!P31)key_v=6;
else if(!P32)key_v=5;
else if(!P33)key_v=4;
P3&=0xf0;
P42=1;
P44=1;
if(!P42)key_v+=4;
rkey=key_v;
}
else
key_state=0;
break;
case 2:
rkey=0;
P3=P3|0x0f;
P42=0;
P44=0;
if((P3&0x0f)==0x0f)key_state=0;
break;
}
}
void Timer1Init(void) //1000 Microsecond @12.000MHz
{
AUXR &= 0xBF; // Timer clock 12T Pattern
TMOD &= 0x0F; // Set timer mode
TL1 = 0x18; // Set the initial timing value
TH1 = 0xFC; // Set the initial timing value
TF1 = 0; // eliminate TF1 sign
TR1 = 1; // Timer 1 Start timing
EA=1;
ET1=1;
}
void Timer0Init(void) //100 Microsecond @12.000MHz
{
AUXR &= 0x7F; // Timer clock 12T Pattern
TMOD &= 0xF0; // Set timer mode
TMOD|=0x05;
TL0 = 0x00; // Set the initial timing value
TH0 = 0x00; // Set the initial timing value
TF0 = 0; // eliminate TF0 sign
TR0 = 0; // Timer 0 Start timing
ET0=0;
}
sys.h
#ifndef __SYS_H_
#define __SYS_H_
typedef unsigned char u8;
typedef unsigned int u16;
#define lock(x) P2=P2&0x1f|(x<<5); P2=P2&0x1f;
#include "mystc.h"
void sys_init();
void smg_play(u8 du,u8 we);
void key_scan();
void Timer1Init(void);
void ReadTime();
void WriteTime();
u8 Read_adc(u8 word);
u8 Read_epprom(u8 word);
void Write_epprom(u8 word,u8 dat);
void Timer0Init(void);
u8 DT[];
extern u8 rkey;
u8 xdata TIME[];
u16 xdata ADLIM[];
u8 xdata BTIME[];
#endif边栏推荐
- [network protocol] problems and solutions in the use of LwIP
- Kotlin 协程的四种启动模式
- RCC clock configuration of stm32f401
- Card constructions -- two points
- 1115. alternate printing foobar
- Basic operations of FreeMarker
- Blinker FAQs
- Notes: the 11th and 12th generation mobile versions of Intel support the native thunderbolt4 interface, but the desktop version does not
- 高阶极点对于波形的影响
- OceanBase 雄踞墨天轮2021年度中国数据库魔力象限领导者
猜你喜欢

Another year 1024, happy programmer's Day!

Static analysis of malicious code

Win10 home vs pro vs enterprise vs enterprise LTSC

Canvas airplane game

Daily buckle exercise - conclusion

Stm32f4 development of DMA transmission to GPIO port
![BUUCTF之BabyUpload[GXYCTF2019]](/img/e8/202298b64d8764355fad348b50fee6.png)
BUUCTF之BabyUpload[GXYCTF2019]

也许尘埃落地,我们才能想清楚互联网的本质
![[GYCTF2020]Ezsqli --BUUCTF](/img/8b/3c8b48daf7719482a235fd622737aa.png)
[GYCTF2020]Ezsqli --BUUCTF

Easyexcel read excel simple demo
随机推荐
Successfully installed opencv under delphixe
Learning and Development notes of mongdb
[LeetCode]9. Palindromes thirty-two
BUUCTF之BabySQL[极客大挑战 2019]
[LeetCode]13. Roman numerals to integers thirty
Easyexcel read excel simple demo
OceanBase 雄踞墨天轮2021年度中国数据库魔力象限领导者
Three kinds of thinking make me reborn
[GYCTF2020]Ezsqli --BUUCTF
New blog address
How to solve the duplication problem when MySQL inserts data in batches?
Using com0com/com2tcp to realize TCP to serial port (win10)
6.824 Lab 2: Raft
MySQL queries the quantity of each month and the year-on-year and month on month data of each month
People and gods are angry. Details of Tangshan "mass beating of women incident"
Summary of openstack installation problems
JPA execution failed in scheduled task -executing an update/delete query transactionrequiredexception
Kali system -- host, dig, dnsenum, imtry for DNS collection and analysis
ROS从入门到精通(零) 教程导读
Paper reading and sharing