当前位置:网站首页>Analysis of the problems of the 10th Blue Bridge Cup single chip microcomputer provincial competition
Analysis of the problems of the 10th Blue Bridge Cup single chip microcomputer provincial competition
2022-07-03 07:31:00 【start field】
Don't talk much , Let's take a look at the 10th (2019) Your topic .
subject

The topic of this time is still three modules ( Nixie tube 、LED、 Key ), Also used. ADC、DAC、NE555, except NE555 I haven't seen it before , Others are also common peripherals , As long as you have practiced , It's not difficult , The most important thing is programming logic .
1 The nixie tube shows
The nixie tube has a voltage measurement interface and a frequency measurement interface .
2 LED
The interface is voltage measurement interface L1 bright , Frequency measurement interface L2 bright , Voltage in [1.5,2.5) perhaps >=3.5V when L3 bright , Frequency at [1k,5k) perhaps >=10k when L4 bright , When a fixed voltage is output L5 destroy , otherwise L5 bright .
3 Key module
Using separate keys ,s4 It is the switching between voltage measurement interface and frequency measurement interface ,s5 yes DAC Fixed output voltage or DAC The output changes with the output voltage of the voltmeter ,s6 yes LED The switch of ,s7 It is the switch of digital tube display .
4 NE555
NE555 Just use two timers , One for counting , One for timing . Among them, timing 1ms Look at how many counts are recorded , turn RB3, The frequency will change .
5 ADC
Is to rewrite the underlying driver code (IIC).
6 DAC
Is to rewrite the underlying driver code (IIC).
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 DA_out(unsigned char date)
{
IIC_Start();
IIC_SendByte(0x90);
IIC_WaitAck();
IIC_SendByte(0x40);
IIC_WaitAck();
IIC_SendByte(date);
IIC_WaitAck();
IIC_Stop();
}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 DA_out(unsigned char date);
#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
static u8 key_state,key_num,key_press,segadder;
u8 value=0;
extern bit mode,tube;
extern u8 a;
u8 code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff,0xc1,0xce};
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<<segadder;P2&=0x1f;
P2=(P2&0x1f)|0xe0;
if((a==1||mode==0)&&segadder==5&&tube==1)
P0=tab[seg[segadder]]&0x7f;
else
P0=tab[seg[segadder]];
P2&=0x1f;
if(++segadder==8)segadder=0;
}
u8 Read_key() // Independent keyboard
{
key_press=P3&0x0f;
switch(key_state)
{
case state_0:
if(key_press!=0x0f)
key_state=state_1;
break;
case state_1:
if(key_press!=0x0f)
{
if((key_press & 0x08)==0) key_num=4;
if((key_press & 0x04)==0) key_num=5;
if((key_press & 0x02)==0) key_num=6;
if((key_press & 0x01)==0) key_num=7;
key_state=state_2;
}
else
key_state=state_0;
break;
case state_2:
if(key_press==0x0f)
key_state=state_0;
break;
}
value=key_num;
key_num=0;
return value;
}
void Timer1Init(void) // Timer 1 timing 1ms
{
AUXR |= 0x40;
TMOD &= 0x0F;
TL1 = 0xCD;
TH1 = 0xD4;
TF1 = 0;
TR1 = 1;
EA = 1;
ET1 = 1;
}
void Timer0Init(void) // Timer 0 Switch to counting mode
{
TMOD = 0x04;
TL0 = 0;
TH0 = 0;
TF0 = 0;
TR0 = 1;
ET0 = 1;
}init.h
#ifndef _INIT_H_
#define _INIT_H_
#include<stc15f2k60s2.h>
void all_init();
void display();
unsigned char Read_key();
void Timer1Init(void);
void Timer0Init(void);
#endifjm.c
#include"jm.h"
#define u8 unsigned char
#define u16 unsigned int
extern bit mode,v,led,tube; // extern Indicates that this variable is defined elsewhere , To quote... Here
extern u8 seg[];
extern u16 F,RB2;
void jm4()
{
if(mode==0)
jm5(); // Voltage measurement interface
else // Frequency measurement interface
{
seg[0]=13;
seg[1]=11;
seg[2]=11;
if(F/10000!=0)
{
seg[3]=F/10000;
seg[4]=F/1000%10;
seg[5]=F/100%10;
seg[6]=F/10%10;
seg[7]=F%10;
}
else if(F/1000!=0)
{
seg[3]=11; // The unused nixie tube goes out
seg[4]=F/1000;
seg[5]=F/100%10;
seg[6]=F/10%10;
seg[7]=F%10;
}
else if(F/100!=0)
{
seg[3]=11;
seg[4]=11;
seg[5]=F/100;
seg[6]=F/10%10;
seg[7]=F%10;
}
else
{
seg[3]=11;
seg[4]=11;
seg[5]=11;
seg[6]=F/10;
seg[7]=F%10;
}
}
}
void jm5()
{
if(v==0)
{
seg[0]=12;
seg[1]=11;
seg[2]=11;
seg[3]=11;
seg[4]=11;
seg[5]=2;
seg[6]=0;
seg[7]=0;
}
else if(v==1)
{
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;
}
}
void jm6() //LED function
{
u8 i=0xff;
if(led==1)
{
if(mode==0)
{
P2=(P2&0x1f)|0x80;P0=0xfe;P2&=0x1f;
}
else
{
P2=(P2&0x1f)|0x80;P0=0xfd;P2&=0x1f;
}
if((RB2>=150&&RB2<250)||(RB2>350))
{
P2=(P2&0x1f)|0x80;P02=0;P2&=0x1f;
}
else
{
P2=(P2&0x1f)|0x80;P02=1;P2&=0x1f;
}
if((F>=1000&&F<5000)||(F>=10000))
{
P2=(P2&0x1f)|0x80;P03=0;P2&=0x1f;
}
else
{
P2=(P2&0x1f)|0x80;P03=1;P2&=0x1f;
}
if(v==1)
{
P2=(P2&0x1f)|0x80;P04=0;P2&=0x1f;
}
else
{
P2=(P2&0x1f)|0x80;P04=1;P2&=0x1f;
}
}
else
{
P2=(P2&0x1f)|0x80;P0=0xff;P2&=0x1f;
}
}
void jm7() // Nixie tube switch function
{
if(tube==0)
{
seg[0]=11;
seg[1]=11;
seg[2]=11;
seg[3]=11;
seg[4]=11;
seg[5]=11;
seg[6]=11;
seg[7]=11;
}
else
jm4();
}jm.h
#ifndef _JM_H_
#define _JM_H_
#include<stc15f2k60s2.h>
void jm4();
void jm5();
void jm6();
void jm7();
#endifmain.c
#include"init.h"
#include"IIC.h"
#include"jm.h"
#define u8 unsigned char
#define u16 unsigned int
u8 num=0,a=0,b=0;
u16 RB2_count=0,F_count=0,F=0,RB2=0;
bit mode=0,v=0,led=1,tube=1,F_flag=0,RB2_flag=0;
void main()
{
all_init();
Timer1Init();
Timer0Init();
while(1)
{
num=Read_key();
switch(num)
{
case 4:
mode^=1;
a=0;
break;
case 5:
v^=1;
a=1;
break;
case 6:
led^=1;
b=0;
break;
case 7:
tube^=1;
jm7();
break;
}
if(a==0&&tube==1)jm4();
if(a==1&&tube==1)jm5();
if(b==0)jm6();
if(F_flag==1) // Calculate the frequency
{
F_flag=0;
TR0=0;
F=TH0*256+TL0;
TL0=0;
TH0=0;
TR0=1;
}
if(RB2_flag==1)
{
RB2_flag=0;
RB2=Read_AD();
if(v==0)DA_out(102.4); //DAC Output
else DA_out(RB2);
RB2=(RB2*100)/51.0+0.5;
}
}
}
void Timer1() interrupt 3
{
display();
if(++RB2_count==500)
{
RB2_count=0;
RB2_flag=1;
}
if(++F_count==1000)
{
F_count=0;
F_flag=1;
}
}边栏推荐
- 为什么说数据服务化是下一代数据中台的方向?
- Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
- 【最詳細】最新最全Redis面試大全(50道)
- 2. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
- 你开发数据API最快多长时间?我1分钟就足够了
- Application of pigeon nest principle in Lucene minshouldmatchsumscorer
- [cmake] cmake link SQLite Library
- 最全SQL与NoSQL优缺点对比
- Segment read
- The underlying mechanism of advertising on websites
猜你喜欢
![[solved] sqlexception: invalid value for getint() - 'Tian Peng‘](/img/bf/f6310304d58d964b3d09a9d011ddb5.png)
[solved] sqlexception: invalid value for getint() - 'Tian Peng‘

Docker builds MySQL: the specified path of version 5.7 cannot be mounted.

Paper learning -- Study on the similarity of water level time series of Xingzi station in Poyang Lake

Sorting, dichotomy

Image recognition and detection -- Notes

7.2 brush two questions

Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS

New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears

Comparison of advantages and disadvantages between most complete SQL and NoSQL

Map interface and method
随机推荐
[solved] sqlexception: invalid value for getint() - 'Tian Peng‘
Chrome 98 Private Network Access problem w/ disabled web security: Request had no target IP address
项目经验分享:实现一个昇思MindSpore 图层 IR 融合优化 pass
The babbage industrial policy forum
SecureCRT password to cancel session recording
Arduino 软串口通信 的几点体会
VMware virtual machine installation
Longest common prefix and
Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS
4everland: the Web3 Developer Center on IPFs has deployed more than 30000 dapps!
File operation serialization recursive copy
Download address collection of various versions of devaexpress
7.2 brush two questions
TypeScript let与var的区别
JUnit unit test of vertx
Lucene skip table
New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears
FileInputStream and fileoutputstream
不出网上线CS的各种姿势
IPv4 address