当前位置:网站首页>Blue Bridge Cup single chip microcomputer sixth temperature recorder
Blue Bridge Cup single chip microcomputer sixth temperature recorder
2022-07-02 03:38:00 【Super 561】
difficulty : How to record ten temperature data and display ; Define an array , To record temperature data , The number of temperature data displayed can be determined by the number of key presses
main.c
#include <STC15F2K60S2.H>
#include <DS1302.H>
#include <ONEWIRE.H>
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;
}
void Device_ctrl(unsigned char p2date,unsigned char p0date)
{
P0=p0date;
P2=P2&0X1F|p2date;
P2&=0X1F;
}
unsigned char smg_count;
unsigned char smg_du[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned char interval_time[]={1,5,30,60};
unsigned int time;
unsigned char interval_display[8];
unsigned char time_display[8];
unsigned char caiji_display[8];
unsigned char temp_shouji[10];
unsigned char key_press=0;
unsigned char display_mode;
unsigned char shi,fen,miao;
unsigned int smg_count_flag;
unsigned int temp_duqu;
unsigned int duqu;
bit smg_flag;
bit temp_flag;
void set_sfm(unsigned char shi,unsigned char fen,unsigned char miao)
{
Write_Ds1302_Byte(0x8e,0);
Write_Ds1302_Byte(0x80,(miao/10*16)+miao%10);
Write_Ds1302_Byte(0x82,(fen/10*16)+fen%10);
Write_Ds1302_Byte(0x84,(shi/10*16)+shi%10);
Write_Ds1302_Byte(0X8e,0x80);
}
void start_temp()
{
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0x44);
}
float read_temp()
{
unsigned char low,high;
float temp;
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0xbe);
low=Read_DS18B20();
high=Read_DS18B20();
temp=(high<<8)|low;
temp=temp*0.0625;
return temp;
}
unsigned int temp_count;
unsigned char temp_cishu=1;
unsigned char temp_number=1;
void temp_process()
{
if(temp_flag)
{
if(temp_count>time*1000)
{
temp_count=0;
temp_duqu=read_temp();
temp_shouji[temp_cishu]=temp_duqu;
temp_cishu++;
if(temp_cishu==10)
{
temp_cishu=0;
display_mode=2;
temp_flag=0;
Device_ctrl(0x80,~0X01);
}
start_temp();
}
}
}
void smg_show()
{
unsigned char i;
Device_ctrl(0XC0,0);
if(display_mode==0)
{
Device_ctrl(0xe0,~interval_display[i]);
}
if(display_mode==1)
{
Device_ctrl(0xe0,~time_display[i]);
}
if(display_mode==2)
{
Device_ctrl(0xe0,~caiji_display[i]);
}
Device_ctrl(0xc0,0x01<<i);
i=(i+1)%8;
}
void smg_process()
{
EA=0;
shi=Read_Ds1302_Byte(0x85);
fen=Read_Ds1302_Byte(0x83);
miao=Read_Ds1302_Byte(0x81);
shi=shi/16*10+shi%16;
fen=fen/16*10+fen%16;
miao=miao/16*10+miao%16;
EA=1;
if(smg_count>3)
{
smg_count=0;
interval_display[0]=0x00;
interval_display[1]=0x00;
interval_display[2]=0x00;
interval_display[3]=0x00;
interval_display[4]=0x00;
interval_display[5]=0x40;
caiji_display[0]=0x40;
caiji_display[3]=0x00;
caiji_display[4]=0x00;
caiji_display[5]=0x40;
if(display_mode==0)
{
time=interval_time[key_press];
interval_display[6]=smg_du[time/10];
interval_display[7]=smg_du[time%10];
}
if(display_mode==1)
{
time_display[0]=smg_du[shi/10];
time_display[1]=smg_du[shi%10];
time_display[3]=smg_du[fen/10];
time_display[4]=smg_du[fen%10];
time_display[6]=smg_du[miao/10];
time_display[7]=smg_du[miao%10];
if(smg_flag)
{
time_display[2]=0x00;
time_display[5]=0x00;
}
else
{
time_display[2]=0x40;
time_display[5]=0x40;
}
}
if(display_mode==2)
{
caiji_display[1]=smg_du[temp_number/10];
caiji_display[2]=smg_du[temp_number%10];
duqu=temp_shouji[temp_number];
caiji_display[6]=smg_du[duqu/10];
caiji_display[7]=smg_du[duqu%10];
}
}
}
unsigned char Trig_btn;
unsigned char Cont_btn;
unsigned int key_count;
void key_btn()
{
unsigned char readdate=P3^0xff;
Trig_btn=readdate&(Cont_btn^readdate);
Cont_btn=readdate;
}
void key_process()
{
if(key_count>10)
{
key_count=0;
key_btn();
if(Trig_btn==0x08)//s4
{
key_press++;
if(key_press==4)
{
key_press=0;
}
}
if(Trig_btn==0x04)//s5
{
if(display_mode==0)
{
display_mode=1;
temp_flag=1;
}
}
if(Trig_btn==0x02)//s6
{
if(display_mode==2)
{
Device_ctrl(0x80,0XFF);
temp_number++;
if(temp_number==11)
{
temp_number=1;
}
}
}
if(Trig_btn==0x01)//s7
{
if(display_mode==2)
{
display_mode=0;
}
}
}
}
void main()
{
Timer2Init();
set_sfm(23,59,50);
start_temp();
Device_ctrl(0xa0,0x00);
Device_ctrl(0x80,0xff);
while(1)
{
smg_process();
key_process();
temp_process();
}
}
void timer2service() interrupt 12
{
key_count++;
smg_count++;
smg_show();
smg_count_flag++;
temp_count++;
if(smg_count_flag>1000)
{
smg_count_flag=0;
smg_flag=~smg_flag;
}
}
DS1302.C
#include "ds1302.h"
// Write Bytes
void Write_Ds1302(unsigned char temp)
{
unsigned char i;
for (i=0;i<8;i++)
{
SCK = 0;
SDA = temp&0x01;
temp>>=1;
SCK=1;
}
}
// towards DS1302 Registers write data
void Write_Ds1302_Byte( unsigned char address,unsigned char dat )
{
RST=0; _nop_();
SCK=0; _nop_();
RST=1; _nop_();
Write_Ds1302(address);
Write_Ds1302(dat);
RST=0;
}
// from DS1302 Register reads data
unsigned char Read_Ds1302_Byte ( unsigned char address )
{
unsigned char i,temp=0x00;
RST=0; _nop_();
SCK=0; _nop_();
RST=1; _nop_();
Write_Ds1302(address);
for (i=0;i<8;i++)
{
SCK=0;
temp>>=1;
if(SDA)
temp|=0x80;
SCK=1;
}
RST=0; _nop_();
SCK=0; _nop_();
SCK=1; _nop_();
SDA=0; _nop_();
SDA=1; _nop_();
return (temp);
}
DS1302.H
#ifndef __DS1302_H
#define __DS1302_H
#include <STC15F2K60S2.H>
#include <intrins.h>
sbit SCK = P1^7;
sbit SDA = P2^3;
sbit RST = P1^3;
void Write_Ds1302(unsigned char temp);
void Write_Ds1302_Byte( unsigned char address,unsigned char dat );
unsigned char Read_Ds1302_Byte( unsigned char address );
#endif
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;
}
ONEWIRE.H
#ifndef __ONEWIRE_H
#define __ONEWIRE_H
#include <STC15F2K60S2.H>
sbit DQ = P1^4;
void Delay_OneWire(unsigned int t);
void Write_DS18B20(unsigned char dat);
unsigned char Read_DS18B20(void);
bit init_ds18b20(void);
#endif
边栏推荐
- Knowing things by learning | self supervised learning helps improve the effect of content risk control
- Global and Chinese market of autotransfusion bags 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for infant care equipment, 2022-2028: Research Report on technology, participants, trends, market size and share
- 《MATLAB 神经网络43个案例分析》:第41章 定制神经网络的实现——神经网络的个性化建模与仿真
- 蓝桥杯单片机第六届温度记录器
- This article describes the step-by-step process of starting the NFT platform project
- Failed to upgrade schema, error: “file does not exist
- VS2010插件NuGet
- [untitled] basic operation of raspberry pie (2)
- 初识string+简单用法(二)
猜你喜欢
初出茅庐市值1亿美金的监控产品Sentry体验与架构
Docker installs canal and MySQL for simple testing and implementation of redis and MySQL cache consistency
高性能 低功耗Cortex-A53核心板 | i.MX8M Mini
蓝桥杯单片机省赛第十届
Generate random numbers that obey normal distribution
[designmode] builder model
蓝桥杯单片机第六届温度记录器
Download and use of the super perfect screenshot tool snipaste
Analyse de 43 cas de réseaux neuronaux MATLAB: Chapitre 42 opérations parallèles et réseaux neuronaux - - opérations parallèles de réseaux neuronaux basées sur CPU / GPU
一天上手Aurora 8B/10B IP核(5)----从Framing接口的官方例程学起
随机推荐
Docker installs canal and MySQL for simple testing and implementation of redis and MySQL cache consistency
Kotlin basic learning 17
Verilog state machine
Global and Chinese markets for hand hygiene monitoring systems 2022-2028: Research Report on technology, participants, trends, market size and share
《MATLAB 神經網絡43個案例分析》:第42章 並行運算與神經網絡——基於CPU/GPU的並行神經網絡運算
What is the binding path of SAP ui5
In the era of programmers' introspection, five-year-old programmers are afraid to go out for interviews
VS2010 plug-in nuget
JIT deep analysis
C # joint halcon out of halcon Environment and various Error Reporting and Resolution Experiences
一天上手Aurora 8B/10B IP核(5)----从Framing接口的官方例程学起
C#联合halcon脱离halcon环境以及各种报错解决经历
Merge interval, linked list, array
Sentry experience and architecture, a fledgling monitoring product with a market value of $100million
Unity脚本的基础语法(8)-协同程序与销毁方法
halcon图像矫正
Use blocking or non blocking for streamline
Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
Kotlin基础学习 17
Kotlin basic learning 15