当前位置:网站首页>Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition
Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition
2022-07-03 07:36:00 【start field】
I have just finished this topic , Let's take a look 2021 The title of the year , What's wrong , I hope you will correct me .
subject
First of all, there are still three modules ( Nixie tube 、LED、 Key ) , also DS18B20,DA Output . I have written some provincial competition questions , These are the things that I test every time , As long as every module has been practiced , It shouldn't be difficult . I found that from 2020 Year begins , Although I still use four buttons , But it becomes a matrix button , Before, there were independent buttons .
1 The nixie tube shows
The digital tube has a temperature display , Parameter setting and DA Output three interfaces , adopt s4 To switch .
2 LED
When in mode 1 In the state of L1 bright , When the nixie tube is in the temperature display interface L2 bright , In the parameter setting interface L3 bright ,DA When outputting the interface L4 bright .
3 Key module
Using a matrix keyboard ,s4 It is the switching of three interfaces ,s8,s9 Is the addition and subtraction of temperature parameters 1, There is a small hole here, that is, the set temperature parameter takes effect only when you exit the parameter setting interface , This requires defining the variables of two temperature parameters , One is used to add and subtract temperature parameters , Assign a value to another variable when exiting the temperature parameter interface , The other is used to compare the size with the real-time temperature .s5 There are two models , Model a The real-time temperature is less than the temperature parameter DA Output 0v, Otherwise output 5v. Model 2 Output voltage according to the relationship given in the figure .
4 DS18B20
Is to rewrite the underlying driver code (onewire), Then put it in the timer , Read every once in a while .
5 DAC
Is to rewrite the underlying driver code (IIC).
onewire.c
#include"onewire.h"
sbit DQ = P1^4;
void Delay_OneWire(unsigned int t)
{
t*=12;
while(t--);
}
void Write_DS18B20(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++)
{
DQ = 0;
DQ = dat&0x01;
Delay_OneWire(5);
DQ = 1;
dat >>= 1;
}
Delay_OneWire(5);
}
unsigned char Read_DS18B20(void)
{
unsigned char i;
unsigned char dat;
for(i=0;i<8;i++)
{
DQ = 0;
dat >>= 1;
DQ = 1;
if(DQ)
{
dat |= 0x80;
}
Delay_OneWire(5);
}
return dat;
}
bit init_ds18b20(void)
{
bit initflag = 0;
DQ = 1;
Delay_OneWire(12);
DQ = 0;
Delay_OneWire(80);
DQ = 1;
Delay_OneWire(10);
initflag = DQ;
Delay_OneWire(5);
return initflag;
}
unsigned int Get_temp()
{
unsigned int result;
unsigned char high,low;
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0x44);
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0xbe);
low=Read_DS18B20();
high=Read_DS18B20();
result=(high<<8)|low;
result*=6.25;
return result;
}
onewire.h
#ifndef _ONEWIRE_H_
#define _ONEWIRE_H_
#include<stc15f2k60s2.h>
void Delay_OneWire(unsigned int t);
void Write_DS18B20(unsigned char dat);
unsigned char Read_DS18B20(void);
bit init_ds18b20(void);
unsigned int Get_temp();
#endif
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;
}
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);
void DA_out(unsigned char date);
#endif
init.c
#include"init.h"
#define u8 unsigned char
#define u16 unsigned int
#define state_0 0
#define state_1 1
#define state_2 2
u8 code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff,0xc6,0x8c,0x88};
u8 seg[]={11,11,11,11,11,11,11,11};
static u8 segaddr=0;
u8 value=0;
extern u8 mode;
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!=2&&segaddr==5)
{
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
{
static u8 key_press,key_num=0,key_state=0;
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 Timer0Init(void)
{
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0xCD;
TH0 = 0xD4;
TF0 = 0;
TR0 = 1;
ET0 = 1;
EA = 1;
}
init.h
#ifndef _INIT_H_
#define _INIT_H_
#include<stc15f2k60s2.h>
void all_init();
void display();
unsigned char Read_key();
void Timer0Init(void);
#endif
jm.c
#include"jm.h"
#include"IIC.h"
#define u8 unsigned char
#define u16 unsigned int
u16 TT=2500,TF=2500;
extern u8 mode,seg[]; // extern Indicates that this variable is defined elsewhere , To quote... Here
extern u16 temp,RB2;
extern bit MS;
void jm4()
{
if(mode==1) // Temperature display interface
{
seg[0]=12;
seg[1]=11;
seg[2]=11;
seg[3]=11;
seg[4]=temp/1000;
seg[5]=temp/100%10;
seg[6]=temp/10%10;
seg[7]=temp%10;
}
else if(mode==2) // Parameter setting interface
{
seg[0]=13;
seg[1]=11;
seg[2]=11;
seg[3]=11;
seg[4]=11;
seg[5]=11;
seg[6]=TF/1000;
seg[7]=TF/100%10;
}
else if(mode==3) //DA Output interface
{
seg[0]=14;
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 jm5() // Mode switching function
{
if(MS==0)
{
if(temp<TT)
{
DA_out(0);
RB2=0;
}
else
{
DA_out(255);
RB2=500;
}
}
else
{
if(temp<=2000)
{
DA_out(196);
RB2=100;
}
else if(temp>2000&&temp<=4000)
{
DA_out((0.15*temp-200)*51.0);
RB2=(u16)(0.15*temp-200+0.5);
}
else
{
DA_out(204);
RB2=400;
}
}
}
void jm8()
{
if(mode==2)TF-=100;
}
void jm9()
{
if(mode==2)TF+=100;
}
void LED() //LED Show function
{
u8 i=0xff;
if(MS==0)
{
P2=(P2&0x1f)|0x80;P0=i&0xfe;P2&=0x1f;
}
else
{
P2=(P2&0x1f)|0x80;P0=i|0x01;P2&=0x1f;
}
if(mode==1)
{
P2=(P2&0x1f)|0x80;P0=i&0xfd;P2&=0x1f;
}
else if(mode==2)
{
P2=(P2&0x1f)|0x80;P0=i&0xfb;P2&=0x1f;
}
else if(mode==3)
{
P2=(P2&0x1f)|0x80;P0=i&0xf7;P2&=0x1f;
}
}
jm.h
#ifndef _JM_H_
#define _JM_H_
#include<stc15f2k60s2.h>
void jm4();
void jm5();
void jm8();
void jm9();
void LED();
#endif
main.c
#include"init.h"
#include"jm.h"
#include"onewire.h"
#include"IIC.h"
#define u8 unsigned char
#define u16 unsigned int
u8 num=0,temp_count=0;
u8 mode=1;
u16 temp,RB2=325;
bit MS=0,temp_flag=0;
extern TT,TF;
void main()
{
all_init();
Timer0Init();
while(1)
{
if(temp_flag==1) // Every time 200ms Read the value of primary temperature
{
temp_flag=0;
temp=Get_temp();
}
num=Read_key();
switch(num)
{
case 4:
if(++mode==4)mode=1;
break;
case 5:
MS^=1;
break;
case 6:
jm8();
TT=TF;
break;
case 7:
jm9();
TT=TF;
break;
}
jm4();
jm5();
LED();
}
}
void Timer0() interrupt 1
{
display();
if(++temp_count==200)
{
temp_count=0;
temp_flag=1;
}
}
One last time , Each module is relatively simple , The most important programming logic .
边栏推荐
- Collector in ES (percentile / base)
- Analysis of the problems of the 10th Blue Bridge Cup single chip microcomputer provincial competition
- docket
- Hnsw introduction and some reference articles in lucene9
- Industrial resilience
- Raspberry pie update tool chain
- 7.2 brush two questions
- 7.2刷题两个
- 2. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
- Summary of Arduino serial functions related to print read
猜你喜欢
Margin left: -100% understanding in the Grail layout
Custom generic structure
Technology dry goods | luxe model for the migration of mindspore NLP model -- reading comprehension task
技术干货|昇思MindSpore NLP模型迁移之LUKE模型——阅读理解任务
c语言指针的概念
技术干货|昇思MindSpore算子并行+异构并行,使能32卡训练2420亿参数模型
Use of generics
Map interface and method
IPv4 address
Es writing fragment process
随机推荐
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
Le Seigneur des anneaux: l'anneau du pouvoir
C code production YUV420 planar format file
Pgadmin 4 v6.11 release, PostgreSQL open source graphical management tool
c语言指针的概念
Leetcode 198: house raiding
Various postures of CS without online line
Hello world of vertx
[Development Notes] cloud app control on device based on smart cloud 4G adapter gc211
IPv4 address
技术干货|昇思MindSpore初级课程上线:从基本概念到实操,1小时上手!
PdfWriter. GetInstance throws system Nullreferenceexception [en] pdfwriter GetInstance throws System. NullRef
项目经验分享:基于昇思MindSpore,使用DFCNN和CTC损失函数的声学模型实现
[coppeliasim4.3] C calls UR5 in the remoteapi control scenario
项目经验分享:基于昇思MindSpore实现手写汉字识别
Vertx's responsive MySQL template
Jeecg menu path display problem
Why is data service the direction of the next generation data center?
Technical dry goods Shengsi mindspire innovation model EPP mvsnet high-precision and efficient 3D reconstruction
Visit Google homepage to display this page, which cannot be displayed