当前位置:网站首页>Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition
Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition
2022-07-03 07:35:00 【start field】
Recently, I have just finished writing the title of the 11th session , Let's see 2020 The title of the provincial competition in .
subject

The topic is still LED、 Nixie tube 、 Key three modules , And analog voltage input (ADC)、AT24C02(EEPROM), Are common peripherals , And the question appeared before , So it's not hard , All the tests are basic skills .
1 The nixie tube shows
The nixie tube mainly displays the obtained voltage 、 There are three interfaces for counting and parameter setting , However, pay attention to the voltage data interface after power on .
2 LED
When the voltage is less than the set parameter 5s after L1 bright , This is still very easy to do . When the count is odd L2 bright , If you count , I first judge whether the voltage is larger or smaller than the parameter, and then judge whether the voltage is larger or smaller than the parameter after a period of time , If the results of the two comparisons are different, there is an intersection between the voltage and the parameters . Define a variable count, Every time the wrong key is pressed count++, When count>=3 when L3 bright , The right key makes count=0.
3 Key module
This time I use a matrix keyboard, which is different from the previous one .s12 It's the voltage 、 Switch between the three interfaces of counting and parameter setting ,s13 It is a key that can reset the count ,s16,s17 It's an addition and subtraction button, but please note that the range is [0,5].
4 ADC
Is to rewrite the underlying driver code (IIC).
5 EEPROM
Is to rewrite the underlying driver code (IIC), Pay attention to adding and subtracting parameters *10 Save to after EEPROM in , So after adding and subtracting, you can directly /10.0 such *10 It is also the original value , In addition, the specified storage address is 0.
IIC.c
#include"IIC.h"
#define DELAY_TIME 5
#define SlaveAddrW 0xA0
#define SlaveAddrR 0xA1
sbit SDA = P2^1;
sbit SCL = P2^0;
void IIC_Delay(unsigned char i)
{
do{_nop_();}
while(i--);
}
void IIC_Start(void)
{
SDA = 1;
SCL = 1;
IIC_Delay(DELAY_TIME);
SDA = 0;
IIC_Delay(DELAY_TIME);
SCL = 0;
}
void IIC_Stop(void)
{
SDA = 0;
SCL = 1;
IIC_Delay(DELAY_TIME);
SDA = 1;
IIC_Delay(DELAY_TIME);
}
bit IIC_WaitAck(void)
{
bit ackbit;
SCL = 1;
IIC_Delay(DELAY_TIME);
ackbit = SDA;
SCL = 0;
IIC_Delay(DELAY_TIME);
return ackbit;
}
void IIC_SendByte(unsigned char byt)
{
unsigned char i;
for(i=0; i<8; i++)
{
SCL = 0;
IIC_Delay(DELAY_TIME);
if(byt & 0x80) SDA = 1;
else SDA = 0;
IIC_Delay(DELAY_TIME);
SCL = 1;
byt <<= 1;
IIC_Delay(DELAY_TIME);
}
SCL = 0;
}
unsigned char IIC_RecByte(void)
{
unsigned char i, da;
for(i=0; i<8; i++)
{
SCL = 1;
IIC_Delay(DELAY_TIME);
da <<= 1;
if(SDA) da |= 1;
SCL = 0;
IIC_Delay(DELAY_TIME);
}
return da;
}
unsigned char Read_AD()
{
unsigned char temp;
IIC_Start();
IIC_SendByte(0x90);
IIC_WaitAck();
IIC_SendByte(0x03);
IIC_WaitAck();
IIC_Stop();
IIC_Start();
IIC_SendByte(0x91);
IIC_WaitAck();
temp=IIC_RecByte();
IIC_Stop();
return temp;
}
void write_eeprom(unsigned char add,unsigned char da)
{
IIC_Start();
IIC_SendByte(0xa0);
IIC_WaitAck();
IIC_SendByte(add);
IIC_WaitAck();
IIC_SendByte(da);
IIC_WaitAck();
IIC_Stop();
}
unsigned char Read_eeprom(unsigned char add)
{
unsigned char da;
IIC_Start();
IIC_SendByte(0xa0);
IIC_WaitAck();
IIC_SendByte(add);
IIC_WaitAck();
IIC_Stop();
IIC_Start();
IIC_SendByte(0xa1);
IIC_WaitAck();
da=IIC_RecByte();
IIC_Stop();
return da;
}IIC.h
#ifndef _IIC_H_
#define _IIC_H_
#include<stc15f2k60s2.h>
#include<intrins.h>
void IIC_Delay(unsigned char i);
void IIC_Start(void);
void IIC_Stop(void);
bit IIC_WaitAck(void);
void IIC_SendByte(unsigned char byt);
unsigned char IIC_RecByte(void);
unsigned char Read_AD();
void write_eeprom(unsigned char add,unsigned char da);
unsigned char Read_eeprom(unsigned char add);
#endifinit.c
#include"init.h"
#define u8 unsigned char
#define u16 unsigned int
#define state_0 0
#define state_1 1
#define state_2 2
#define key_io P3
extern u8 mode;
static u8 segaddr=0,key_press,key_state,key_num=0,row;
u8 value=0;
u8 code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff,0xc1,0x8c,0xc8};
u8 seg[]={11,11,11,11,11,11,11,11};
void all_init() // Turn off irrelevant peripherals
{
P2=(P2&0x1f)|0x80;P0=0xff;P2&=0x1f;
P2=(P2&0x1f)|0xa0;P04=0;P06=0;P2&=0x1f;
P2=(P2&0x1f)|0xc0;P0=0x00;P2&=0x1f;
P2=(P2&0x1f)|0xe0;P0=0xff;P2&=0x1f;
}
void display() // Nixie tube display function
{
P2=(P2&0x1f)|0xe0;P0=0xff;P2&=0x1f;
P2=(P2&0x1f)|0xc0;P0=1<<segaddr;P2&=0x1f;
if((mode==1||mode==2)&&segaddr==5) // Judge whether to use decimal point
{
P2=(P2&0x1f)|0xe0;P0=tab[seg[segaddr]]&0x7f;P2&=0x1f;
}
else
{
P2=(P2&0x1f)|0xe0;P0=tab[seg[segaddr]];P2&=0x1f;
}
if(++segaddr==8)segaddr=0;
}
u8 Read_key() // Matrix keyboard ( State machine )
{
switch(key_state)
{
case state_0:
key_io=0x0f; P42=0; P44=0;
key_press =key_io;
if(key_press != 0x0f)
key_state = state_1;
break;
case state_1:
key_press =key_io;
if(key_press != 0x0f)
{
if((key_io&0x08)==0) row=4;
if((key_io&0x04)==0) row=5;
if((key_io&0x02)==0) row=6;
if((key_io&0x01)==0) row=7;
key_io=0xf0; P42=1;P44=1;
if(P44==0) key_num=row;
if(P42==0) key_num=row+4;
if((key_io&0x20)==0) key_num=row+8;
if((key_io&0x10)==0) key_num=row+12;
key_state = state_2;
}
else
key_state = state_0;
break;
case state_2:
key_io=0x0f; P42=0; P44=0;
key_press =key_io;
if(key_press == 0x0f) key_state = state_0;
break;
}
value=key_num;
key_num=0;
return value;
}
void Timer0Init(void)
{
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0xCD;
TH0 = 0xD4;
TF0 = 0;
TR0 = 1;
EA = 1;
ET0 = 1;
}
init.h
#ifndef _INIT_H_
#define _INIT_H_
#include<stc15f2k60s2.h>
void all_init();
void display();
unsigned char Read_key();
void Timer0Init(void);
#endifjm.c
#include"jm.h"
#include"IIC.h"
#define u8 unsigned char
#define u16 unsigned int
extern u8 mode,seg[],N,Y; // extern Indicates that this variable is defined elsewhere , To quote... Here
extern u16 RB2;
extern float V;
void Delay5ms()
{
unsigned char i, j;
i = 54;
j = 199;
do
{
while (--j);
} while (--i);
}
void jm12()
{
if(mode==1) // Voltage display interface
{
seg[0]=12;
seg[1]=11;
seg[2]=11;
seg[3]=11;
seg[4]=11;
seg[5]=RB2/100;
seg[6]=RB2/10%10;
seg[7]=RB2%10;
}
if(mode==2) // Parameter display interface
{
seg[0]=13;
seg[1]=11;
seg[2]=11;
seg[3]=11;
seg[4]=11;
seg[5]=Y/10;
seg[6]=Y%10;
seg[7]=0;
}
if(mode==3) // Counting display interface
{
seg[0]=14;
seg[1]=11;
seg[2]=11;
seg[3]=11;
seg[4]=11;
seg[5]=11;
seg[6]=N/10;
seg[7]=N%10;
}
}
void jm13() // Count reset interface
{
if(mode==3)
N=0;
}
void jm16()
{
if(mode==2)
{
Y+=5;
if(Y>=50)Y=0;
V=Y/10.0;
}
write_eeprom(0x00,V*10);
Delay5ms();
}
void jm17()
{
if(mode==2)
{
Y-=5;
if(Y<=0)Y=50;
V=Y/10.0;
}
write_eeprom(0x00,V*10);
Delay5ms();
}jm.h
#ifndef _JM_H_
#define _JM_H_
#include<stc15f2k60s2.h>
void jm12();
void jm13();
void jm16();
void jm17();
void Delay5ms();
#endifmain.c
#include"init.h"
#include"IIC.h"
#include"jm.h"
#define u8 unsigned char
#define u16 unsigned int
u8 num=0,mode=1,N=0,Y=30,count=0,e_count=0,high=0,low=0;
u16 RB2_count=0,RB2=0,L1_count=0,cp_count=0;
bit RB2_flag=0,L1_flag=0,e_flag=0,cp_flag=0,L1=0;
extern u8 seg[];
float V;
void LED();
void main()
{
all_init();
Timer0Init();
while(1)
{
num=Read_key();
switch(num)
{
case 12:
if(++mode==4)mode=1;
break;
case 13:
if(mode==3) // Determine whether the key is correct
{
jm13();
count=0;
}
else count++;
break;
case 16:
if(mode==2) // Determine whether the key is correct
{
jm16();
count=0;
}
else count++;
break;
case 17:
if(mode==2) // Determine whether the key is correct
{
jm17();
count=0;
}
else count++;
break;
}
jm12();
LED();
if(Y*10>=RB2) // Compare the voltage and parameters for the first time
high=1;
else if(Y*10<=RB2)
low=1;
if(cp_flag==1) //500ms Judge the voltage and parameters for the second time
{
cp_flag=0;
if(high+low==2)
{
N++;
high=0,low=0;
}
else
high=0,low=0;
}
if(RB2_flag==1)
{
RB2_flag=0;
RB2=Read_AD();
RB2=(RB2*100)/51.0+0.5;
}
if(RB2<Y*10)L1_flag=1; // Judge L1 Whether it is on
else
{
L1_flag=0;
L1=0;
}
if(e_flag==1)
{
e_flag=0;
V=Read_eeprom(0x00);
Y=V;
}
}
}
void LED()
{
u8 i=0xff;
if(L1==1)
{
P2=(P2&0x1f)|0x80;P0=i&0xfe;P2&=0x1f;
}
else
{
P2=(P2&0x1f)|0x80;P0=i|0x01;P2&=0x1f;
}
if(N%2!=0)
{
P2=(P2&0x1f)|0x80;P0=i&0xfd;P2&=0x1f;
}
else
{
P2=(P2&0x1f)|0x80;P0=i|0x02;P2&=0x1f;
}
if(count>=3)
{
P2=(P2&0x1f)|0x80;P0=i&0xfb;P2&=0x1f;
}
else
{
P2=(P2&0x1f)|0x80;P0=i|0x04;P2&=0x1f;
}
}
void Timer0() interrupt 1
{
display();
if(++RB2_count==100)
{
RB2_count=0;
RB2_flag=1;
}
if(L1_flag==1)
{
L1_count++;
if(L1_count==5000)
{
L1_count=0;
L1=1;
}
}
if(++e_count==200)
{
e_count=0;
e_flag=1;
}
if(high==1||low==1)
{
if(++cp_count==500)
{
cp_count=0;
cp_flag=1;
}
}
}边栏推荐
- II. D3.js draw a simple figure -- circle
- 你开发数据API最快多长时间?我1分钟就足够了
- Unified handling and interception of exception exceptions of vertx
- What did the DFS phase do
- Technical dry goods | reproduce iccv2021 best paper swing transformer with Shengsi mindspire
- 技术干货|昇思MindSpore可变序列长度的动态Transformer已发布!
- 项目经验分享:基于昇思MindSpore实现手写汉字识别
- Longest common prefix and
- An overview of IfM Engage
- Hello world of vertx
猜你喜欢

Lucene introduces NFA

Topic | synchronous asynchronous

7.2 brush two questions
![[Development Notes] cloud app control on device based on smart cloud 4G adapter gc211](/img/55/fea5fe315932b92993d21f861befbe.png)
[Development Notes] cloud app control on device based on smart cloud 4G adapter gc211
![[coppeliasim4.3] C calls UR5 in the remoteapi control scenario](/img/ca/2f72ea3590c358a6c9884aaa1a1c33.png)
[coppeliasim4.3] C calls UR5 in the remoteapi control scenario
![PdfWriter. GetInstance throws system Nullreferenceexception [en] pdfwriter GetInstance throws System. NullRef](/img/65/1f28071fc15e76abb37f1b128e1d90.jpg)
PdfWriter. GetInstance throws system Nullreferenceexception [en] pdfwriter GetInstance throws System. NullRef

Use of generics

項目經驗分享:實現一個昇思MindSpore 圖層 IR 融合優化 pass

技术干货|AI框架动静态图统一的思考

Analysis of the eighth Blue Bridge Cup single chip microcomputer provincial competition
随机推荐
Hello world of vertx
docker建立mysql:5.7版本指定路径挂载不上。
[mindspire paper presentation] summary of training skills in AAAI long tail problem
Lucene skip table
Lombok cooperates with @slf4j and logback to realize logging
Spa single page application
Comparison of advantages and disadvantages between most complete SQL and NoSQL
pgAdmin 4 v6.11 发布,PostgreSQL 开源图形化管理工具
Technical dry goods Shengsi mindspire innovation model EPP mvsnet high-precision and efficient 3D reconstruction
docket
技术干货|昇思MindSpore初级课程上线:从基本概念到实操,1小时上手!
Vertx metric Prometheus monitoring indicators
Analysis of the problems of the 10th Blue Bridge Cup single chip microcomputer provincial competition
Use of generics
Lucene introduces NFA
7.2 brush two questions
Logging log configuration of vertx
Collector in ES (percentile / base)
技术干货|利用昇思MindSpore复现ICCV2021 Best Paper Swin Transformer
Wireshark software usage