当前位置:网站首页>The 6th Blue Bridge Cup single chip microcomputer provincial competition
The 6th Blue Bridge Cup single chip microcomputer provincial competition
2022-07-02 03:38:00 【Super 561】



difficulty How to set the upper and lower temperature limits by pressing the key ; Define an array to display the temperature , Determine the upper and lower limits of the display temperature by the number of key presses ; Define an array to store the value of temperature , Use the number of key presses to determine whether the temperature is ten digits or one digit
main.c
#include <STC15F2K60S2.H>
#include <ONEWIRE.H>
unsigned int wendu;
unsigned char qujian;
unsigned char keynumber;
unsigned char display_mode;
unsigned char Tmax=30;
unsigned char Tmin=20;
unsigned char key_press;
unsigned char led_flag=1;
#define NO_KEY 0xff
#define KEY_STATE0 0
#define KEY_STATE1 1
#define KEY_STATE2 2
unsigned char smgdisplay[8];
unsigned char wd[8];
unsigned char smg_du[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void Device_ctrl(unsigned char p2date,unsigned char p0date);
unsigned char key_scan()
{
static unsigned char key_state=KEY_STATE0;
unsigned char key_value=0,key_temp;
unsigned char key1,key2;
P30=0;P31=0;P32=0;P33=0;P34=1;P35=1;P42=1;P44=1;
if(P44==0){key1=0x70;}
if(P42==0){key1=0xb0;}
if(P35==0){key1=0xd0;}
if(P34==0){key1=0xe0;}
if((P44==1)&&(P42==1)&&(P35==1)&&(P34==1)){key1=0xf0;}
P30=1;P31=1;P32=1;P33=1;P34=0;P35=0;P42=0;P44=0;
if(P30==0){key2=0x0e;}
if(P31==0){key2=0x0d;}
if(P32==0){key2=0x0b;}
if(P33==0){key2=0x07;}
if((P30==1)&&(P31==1)&&(P32==1)&&(P33==1)){key2=0x0f;}
key_temp=key1|key2;
switch(key_state)
{
case KEY_STATE0: if(key_temp!=NO_KEY)
{
key_state=KEY_STATE1;
}
break;
case KEY_STATE1: if(key_temp==NO_KEY)
{key_state=KEY_STATE0;}
else
{
switch(key_temp)
{
case 0x77:key_value=4;break;
case 0x7b:key_value=5;break;
case 0x7d:key_value=6;break;
case 0x7e:key_value=7;break;
case 0xb7:key_value=8;break;
case 0xbb:key_value=9;break;
case 0xbd:key_value=10;break;
case 0xbe:key_value=11;break;
case 0xd7:key_value=12;break;
case 0xdb:key_value=13;break;
case 0xdd:key_value=14;break;
case 0xde:key_value=15;break;
case 0xe7:key_value=16;break;
case 0xeb:key_value=17;break;
case 0xed:key_value=18;break;
case 0xee:key_value=19;break;
}
key_state=KEY_STATE2;
}
break;
case KEY_STATE2:if(key_temp==NO_KEY)
{key_state=KEY_STATE0;}break;
}
return key_value;
}
unsigned int key_count;
void key_process()
{
unsigned int key_val;
if(key_count>=5)
{
key_count=0;
key_val=key_scan();
switch(key_val)
{
case 4:smgdisplay[key_press]=smg_du[9];wd[key_press]=9;key_press++;break;
case 5:smgdisplay[key_press]=smg_du[6];wd[key_press]=6;key_press++;break;
case 6:smgdisplay[key_press]=smg_du[3];wd[key_press]=3;key_press++;break;
case 7:smgdisplay[key_press]=smg_du[0];wd[key_press]=0;key_press++;break;
case 8:display_mode++;
if(display_mode==2)
{
display_mode=0;
key_press=0;
Tmax=wd[1]*10+wd[2];
Tmin=wd[6]*10+wd[7];
if(Tmax<Tmin)
{
P2=0X80;P0=~0X02;P2=0;
led_flag=0;
}
else
{
P2=0X80;P0=0Xff;P2=0;
led_flag=1;
}
}break;
case 9:smgdisplay[key_press]=smg_du[7];wd[key_press]=7;key_press++;break;
case 10:smgdisplay[key_press]=smg_du[4];wd[key_press]=4;key_press++;break;
case 11:smgdisplay[key_press]=smg_du[1];wd[key_press]=1;key_press++;break;
case 12:if(display_mode==1)
{
smgdisplay[1]=0x00;
smgdisplay[2]=0x00;
smgdisplay[6]=0x00;
smgdisplay[7]=0x00;
key_press=0;
}break;
case 13:smgdisplay[key_press]=smg_du[8];wd[key_press]=8;key_press++;break;
case 14:smgdisplay[key_press]=smg_du[5];wd[key_press]=5;key_press++;break;
case 15:smgdisplay[key_press]=smg_du[2];wd[key_press]=2;key_press++;break;
case 16:break;
case 17:break;
case 18:break;
case 19:break;
}
}
}
void Device_ctrl(unsigned char p2date,unsigned char p0date)
{
P0=p0date;
P2=P2&0X1F|p2date;
P2&=0X1F;
}
unsigned char smg_display[8];
unsigned int smg_count;
void smg_show()
{
unsigned int i;
Device_ctrl(0xc0,0);
if(display_mode==0)
{
Device_ctrl(0xe0,~smg_display[i]);
}
else
{
Device_ctrl(0xe0,~smgdisplay[i]);
}
Device_ctrl(0xc0,0x01<<i);
i=(i+1)%8;
}
void smg_process()
{
smgdisplay[0]=0x40;
smgdisplay[3]=0x00;
smgdisplay[4]=0x00;
smgdisplay[5]=0x40;
if(smg_count>3)
{
smg_count=0;
if(display_mode==0)
{
if(wendu<Tmin)
{
qujian=0;
}
if(Tmin<wendu<Tmax)
{
qujian=1;
}
if(wendu>Tmax)
{
qujian=2;
}
smg_display[0]=0x40;
smg_display[1]=smg_du[qujian];
smg_display[2]=0x40;
smg_display[3]=0x00;
smg_display[4]=0x00;
smg_display[5]=0x00;
smg_display[6]=smg_du[wendu/10];
smg_display[7]=smg_du[wendu%10];
}
else
{
if(key_press==3)
{
key_press=6;
}
if(key_press==8)
{
key_press=9;
}
}
}
}
unsigned int temp_count;
void temp_process()
{
if(temp_count>=100)
{
temp_count=0;
wendu=rd_temperature();
}
}
void work_process()
{
if(qujian==0)
{
P2=0xa0;P0=0x30;P2=0;
}
if(qujian==1)
{
P2=0xa0;P0=0x00;P2=0;
}
if(qujian==2)
{
P2=0xa0;P0=0x30;P2=0;
}
}
void Timer2Init() //1 millisecond @12.000MHz
{
AUXR &= 0xFB; // Timer clock 12T Pattern
T2L = 0x18; // Set initial value of timing
T2H = 0xFC; // Set initial value of timing
AUXR |= 0x10; // Timer 2 Start timing
IE2|=0X04;
EA=1;
}
unsigned int led_count;
bit ledflag;
void led_process()
{
if(qujian==0)
{
if(led_count>800)
{
led_count=0;
ledflag=~ledflag;
if(ledflag)
{
P2=0X80;P0=~0X01;P2=0;
}
else
{
P2=0X80;P0=0xFF;P2=0;
}
}
}
if(qujian==1)
{
if(led_count>400)
{
led_count=0;
ledflag=~ledflag;
if(ledflag)
{
P2=0X80;P0=~0X01;P2=0;
}
else
{
P2=0X80;P0=0xFF;P2=0;
}
}
}
if(qujian==2)
{
if(led_count>200)
{
led_count=0;
ledflag=~ledflag;
if(ledflag)
{
P2=0X80;P0=~0X01;P2=0;
}
else
{
P2=0X80;P0=0xFF;P2=0;
}
}
}
}
void main()
{
Timer2Init();
Device_ctrl(0xa0,0x00);
Device_ctrl(0x80,0xff);
while(1)
{
key_process();
smg_process();
temp_process();
work_process();
led_process();
}
}
void timer2service() interrupt 12
{
smg_count++;
smg_show();
key_count++;
temp_count++;
led_count++;
}onewire.c
#include "onewire.h"
// Single bus internal delay function
void Delay_OneWire(unsigned int t)
{
t=t*12;
while(t--);
}
// Single bus write operation
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);
}
// Single bus read operation
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;
}
//DS18B20 initialization
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;
}
float rd_temperature(void)
{
float temp;
unsigned char low,high;
init_ds18b20();
Write_DS18B20(0XCC);
Write_DS18B20(0X44);
init_ds18b20();
Write_DS18B20(0XCC);
Write_DS18B20(0XBE);
low=Read_DS18B20();
high=Read_DS18B20();
temp=(high<<8)|low;
temp=temp*0.0625;
return temp;
}onewire.h
#ifndef __ONEWIRE_H
#define __ONEWIRE_H
#include <STC15F2K60S2.H>
sbit DQ = P1^4;
float rd_temperature(void);
#endif
边栏推荐
- Merge interval, linked list, array
- Review materials of project management PMP high frequency examination sites (8-1)
- Oracle viewing locked tables and unlocking
- Global and Chinese market of gynaecological health training manikin 2022-2028: Research Report on technology, participants, trends, market size and share
- Verilog parallel block implementation
- 0 foundation how to learn automated testing? Follow these seven steps step by step and you will succeed
- Global and Chinese market of bone adhesives 2022-2028: Research Report on technology, participants, trends, market size and share
- Download and use of the super perfect screenshot tool snipaste
- Comment élaborer une stratégie nuageuse à l'ère des nuages mixtes
- What is the logical structure of database file
猜你喜欢

Get started with Aurora 8b/10b IP core in one day (5) -- learn from the official routine of framing interface

一天上手Aurora 8B/10B IP核(5)----从Framing接口的官方例程学起

Sentry experience and architecture, a fledgling monitoring product with a market value of $100million

JIT deep analysis

One of the future trends of SAP ui5: embrace typescript

微信小程序中 在xwml 中使用外部引入的 js进行判断计算

Uniapp uses canvas to generate posters and save them locally

【DesignMode】建造者模式(Builder model)

NLog使用
![[designmode] builder model](/img/e8/855934d57eb6868a4d188b2bb1d188.png)
[designmode] builder model
随机推荐
Oracle common SQL
JIT deep analysis
Global and Chinese markets for electronic laryngoscope systems 2022-2028: Research Report on technology, participants, trends, market size and share
Verilog state machine
"Analysis of 43 cases of MATLAB neural network": Chapter 41 implementation of customized neural network -- personalized modeling and Simulation of neural network
What kind of interview is more effective?
halcon图像矫正
《MATLAB 神经网络43个案例分析》:第41章 定制神经网络的实现——神经网络的个性化建模与仿真
Work hard all day long and be alert at sunset
Download and use of the super perfect screenshot tool snipaste
Get started with Aurora 8b/10b IP core in one day (5) -- learn from the official routine of framing interface
FFMpeg AVFrame 的概念.
Account management of MySQL
In wechat applet, the externally introduced JS is used in xwml for judgment and calculation
MySQL connection query and subquery
C#聯合halcon脫離halcon環境以及各種報錯解决經曆
[HCIA continuous update] working principle of OSPF Protocol
Gradle foundation | customize the plug-in and upload it to jitpack
Kotlin基础学习 15
aaaaaaaaaaaaa