当前位置:网站首页>Multi function event recorder of the 5th National Games of the Blue Bridge Cup
Multi function event recorder of the 5th National Games of the Blue Bridge Cup
2022-07-06 02:07:00 【Miseñor】
I feel this session is too difficult , Almost all of them are used ( Except ultrasound ), But the serial port is still not very good at writing , The function is written , But it doesn't run in the main function . And I don't know why , Photosensitive that becomes 03 The passage , It's weird , It's completely opposite to the previous .
subject :( No electronic file found , That's all )
Code :
main.c
//#include"reg52.h"
#include <STC12C5A60S2.H>
#include"intrins.h"
#include"ds1302.h"
#include"onewire.h"
#include"iic.h"
int temperature;
unsigned int urat;
int code write_add[]={
0x80,0x82,0x84};
int code read_add[]={
0x81,0x83,0x85};
int time[]={
0x55,0x59,0x23};
unsigned int code xianshi[]={
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf,0xc6,0x89};
sbit S4=P3^3;
sbit S5=P3^2;
int smg_mode=0;
int work_mode=0;// Automatically
int RD_1,RD_3;
int last_time;// residence time
int led_work=0xff;
int eeprom_time;
void choose_573(int i)
{
switch(i)
{
case(0):P2=(P2&0x1f)|0x00;break;// close
case(4):P2=(P2&0x1f)|0x80;break;//Y4
case(5):P2=(P2&0x1f)|0xa0;break;//Y5
case(6):P2=(P2&0x1f)|0xc0;break;//Y6
case(7):P2=(P2&0x1f)|0xe0;break;//Y7
}
}
void init_system()
{
choose_573(4);
P0=0xff;
choose_573(5);
P0=0x00;
choose_573(0);
}
//=======================================time
void write_time()
{
int i;
Write_Ds1302_Byte(0x8e,0x00);
for(i=0;i<3;i++)
{
Write_Ds1302_Byte(write_add[i],time[i]);
}
Write_Ds1302_Byte(0x8e,0x80);
}
void read_time()
{
int i;
for(i=0;i<3;i++)
{
time[i]=Read_Ds1302_Byte(read_add[i]);
}
}
//=======================================
//=======================================temperature rd1 rd3
void get_temperature()
{
temperature=rd_temperature();
}
void get_rd1()// photosensitive
{
RD_1=Rd1();
}
void get_rd3()// resistance
{
RD_3=Rd3();
}void Timer0Init(void) //5 millisecond @11.0592MHz
{
AUXR |= 0x80; // Timer clock 1T Pattern
TMOD &= 0xF0; // Set timer mode
TL0 = 0x00; // Set the initial timing value
TH0 = 0x28; // Set the initial timing value
TF0 = 0; // eliminate TF0 sign
TR0 = 1; // Timer 0 Start timing
ET0=1;
EA=1;
}
int count_1;
void service_time0() interrupt 1
{
if(RD_3<=100)
{
count_1++;
last_time=count_1/200;
}
else
{
count_1=0;
// last_time=0; // Timing zero elimination
}
}
//=======================================
//=======================================key_board
void Delay10ms() //@11.0592MHz
{
unsigned char i, j;
i = 108;
j = 145;
do
{
while (--j);
} while (--i);
}
void key_board()
{
if(S5==0)
{
Delay10ms();
if(S5==0)
{
smg_mode++;
if(smg_mode>=3)
{
smg_mode=0;
}
}
while(!S5);
}
if(S4==0)
{
Delay10ms();
if(S4==0)
{
work_mode++;
if(work_mode>=2)
{
work_mode=0;
}
}
while(!S4);
}
}
//=======================================
//=======================================smg
void Delay300us() //@11.0592MHz
{
unsigned char i, j;
_nop_();
_nop_();
i = 4;
j = 54;
do
{
while (--j);
} while (--i);
}
void SMG(int wei,int dat)
{
choose_573(6);
P0=0x80>>(wei-1);
choose_573(7);
P0=xianshi[dat];
choose_573(0);
Delay300us();
choose_573(7);
P0=xianshi[10];
choose_573(0);
}
void smg_display()
{
if(smg_mode==0)
{
SMG(1,13);
SMG(2,RD_1%10);
SMG(3,RD_1/10);
SMG(4,10);
SMG(5,10);
SMG(6,12);
SMG(7,temperature%10);
SMG(8,temperature/10);
}
if(smg_mode==1)
{
SMG(1,time[0]%16);
SMG(2,time[0]/16);
if(time[0]%2==0)
{
SMG(3,10);
}
else
{
SMG(3,11);
}
SMG(4,time[1]%16);
SMG(5,time[1]/16);
if(time[0]%2==0)
{
SMG(6,10);
}
else
{
SMG(6,11);
}
SMG(7,time[2]%16);
SMG(8,time[2]/16);
}
if(smg_mode==2)
{
SMG(1,last_time%10);
SMG(2,(last_time%100)/10);
SMG(3,(last_time%1000)/100);
SMG(4,(last_time%10000)/1000);
SMG(5,11);
// SMG(6,RD_3%10);
// SMG(7,(RD_3%100)/10);
// SMG(8,(RD_3%1000)/100);
SMG(6,10);
SMG(7,10);
SMG(8,10);
}
}
//=======================================
//======================================= A serial port
//void UartInit(void) //[email protected]
//{
// SCON = 0x50; //8 Bit data , Variable baud rate
// AUXR |= 0x40; // Timer clock 1T Pattern
// AUXR &= 0xFE; // A serial port 1 Select timer 1 Baud rate generator
// TMOD &= 0x0F; // Set timer mode
// TL1 = 0xE0; // Set the initial timing value
// TH1 = 0xFE; // Set the initial timing value
// ET1 = 0; // Disable timer %d interrupt
// TR1 = 1; // Timer 1 Start timing
//
// ES=1;
// EA=0;
//}
//void service_Uart() interrupt 4
//{
// if(RI==1)
// {
// urat=SBUF;
// RI=0;
// }
//}
//void sendByte(unsigned char dat)
//{
// SBUF=dat;
// while(TI=0);
// TI=0;
//}
//void sendString(unsigned char *str)
//{
// while(*str!='\0')
// {
// sendByte(*str++);
// }
//}
//void urat_work()
//{
// unsigned int *temp_urat=&temperature;
// if(RD_3<=30)
// {
// sendString(temp_urat);
// }
//}
//=======================================
//=======================================led
void led_display()
{
if(work_mode==0)
{
led_work=(led_work&0xfe)|0x00;
choose_573(4);
P0=led_work;
choose_573(0);
}
else
{
led_work=(led_work&0xfe)|0x01;
choose_573(4);
P0=led_work;
choose_573(0);
}
if(work_mode==1)
{
led_work=(led_work&0xfd)|0x00;
choose_573(4);
P0=led_work;
choose_573(0);
}
else
{
led_work=(led_work&0xfd)|0x02;
choose_573(4);
P0=led_work;
choose_573(0);
}
if(RD_3<=100)
{
led_work=(led_work&0xfb)|0x00;
choose_573(4);
P0=led_work;
choose_573(0);
}
else
{
led_work=(led_work&0xfb)|0x04;
choose_573(4);
P0=led_work;
choose_573(0);
}
}
//=======================================
//=======================================eeprom
void eeprom_time_work()
{
if(RD_3>=100)
{
Delay300us();
if(RD_3<=100)
{
eeprom_time++;
}
}
}
void eeprom()
{
if(work_mode==1)
{
if(eeprom_time%5==0)
{
write_EEPROM(0x01,temperature);
write_EEPROM(0x02,RD_3);
write_EEPROM(0x03,time[2]);
write_EEPROM(0x04,time[1]);
write_EEPROM(0x05,time[0]);
write_EEPROM(0x06,last_time);
}
if(eeprom_time%5==1)
{
write_EEPROM(0x11,temperature);
write_EEPROM(0x12,RD_3);
write_EEPROM(0x13,time[2]);
write_EEPROM(0x14,time[1]);
write_EEPROM(0x15,time[0]);
write_EEPROM(0x16,last_time);
}
if(eeprom_time%5==2)
{
write_EEPROM(0x21,temperature);
write_EEPROM(0x22,RD_3);
write_EEPROM(0x23,time[2]);
write_EEPROM(0x24,time[1]);
write_EEPROM(0x25,time[0]);
write_EEPROM(0x26,last_time);
}
if(eeprom_time%5==3)
{
write_EEPROM(0x31,temperature);
write_EEPROM(0x32,RD_3);
write_EEPROM(0x33,time[2]);
write_EEPROM(0x34,time[1]);
write_EEPROM(0x35,time[0]);
write_EEPROM(0x36,last_time);
}
if(eeprom_time%5==4)
{
write_EEPROM(0x41,temperature);
write_EEPROM(0x42,RD_3);
write_EEPROM(0x43,time[2]);
write_EEPROM(0x44,time[1]);
write_EEPROM(0x45,time[0]);
write_EEPROM(0x46,last_time);
}
}
}
//=======================================
void main()
{
init_system();
write_time();
Timer0Init();
while(1)
{
key_board();
get_temperature();
get_rd1();
get_rd3();
smg_display();
read_time();
led_display();
eeprom_time_work();
eeprom();
}
}
onewire.c
/* Program description : Single bus driver Software environment : Keil uVision 4.10 Hardware environment : CT107 SCM comprehensive training platform ( External crystal oscillator 12MHz) STC89C52RC Single chip microcomputer Japan period : 2011-8-9 */
#include "reg52.h"
sbit DQ = P1^4; // Single bus interface
// Single bus delay function
void Delay_OneWire(unsigned int t) //STC89C52RC
{
t=t*12;
while(t--);
}
// Through a single bus to DS18B20 Write a byte
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);
}
// from DS18B20 Read a byte
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 Device 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;
}
int temper;
unsigned char rd_temperature(void)
{
int HBS,LBS;
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0x44);
Delay_OneWire(200);
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0xbe);
LBS=Read_DS18B20();
HBS=Read_DS18B20();
temper=HBS;
temper=(temper<<4)|(LBS>>4);
return temper;
}
onewire.h
#ifndef __ONEWIRE_H
#define __ONEWIRE_H
unsigned char rd_temperature(void); //; ;
#endif
iic.c
/* Program description : IIC Bus driver Software environment : Keil uVision 4.10 Hardware environment : CT107 SCM comprehensive training platform 8051,12MHz Japan period : 2011-8-9 */
#include "reg52.h"
#include "intrins.h"
#define DELAY_TIME 5
#define SlaveAddrW 0xA0
#define SlaveAddrR 0xA1
// Bus pin definition
sbit SDA = P2^1; /* cable */
sbit SCL = P2^0; /* Clock line */
void IIC_Delay(unsigned char i)
{
do{
_nop_();}
while(i--);
}
// Bus start condition
void IIC_Start(void)
{
SDA = 1;
SCL = 1;
IIC_Delay(DELAY_TIME);
SDA = 0;
IIC_Delay(DELAY_TIME);
SCL = 0;
}
// Bus stop condition
void IIC_Stop(void)
{
SDA = 0;
SCL = 1;
IIC_Delay(DELAY_TIME);
SDA = 1;
IIC_Delay(DELAY_TIME);
}
// Send reply
void IIC_SendAck(bit ackbit)
{
SCL = 0;
SDA = ackbit; // 0: The reply ,1: Non response
IIC_Delay(DELAY_TIME);
SCL = 1;
IIC_Delay(DELAY_TIME);
SCL = 0;
SDA = 1;
IIC_Delay(DELAY_TIME);
}
// Waiting for an answer
bit IIC_WaitAck(void)
{
bit ackbit;
SCL = 1;
IIC_Delay(DELAY_TIME);
ackbit = SDA;
SCL = 0;
IIC_Delay(DELAY_TIME);
return ackbit;
}
// adopt I2C The bus sends data
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;
}
// from I2C Data is received on the bus
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;
}
int Rd1()// resistance
{
int temp;
IIC_Start();
IIC_SendByte(0x90);
IIC_WaitAck();
IIC_SendByte(0x01);
IIC_WaitAck();
IIC_Stop();
IIC_Start();
IIC_SendByte(0x91);
IIC_WaitAck();
temp=IIC_RecByte();
IIC_SendAck(1);
IIC_Stop();
temp=temp*0.388+0.5;
return temp;
}
int Rd3()
{
int temp_1;
IIC_Start();
IIC_SendByte(0x90);
IIC_WaitAck();
IIC_SendByte(0x03);
IIC_WaitAck();
IIC_Stop();
IIC_Start();
IIC_SendByte(0x91);
IIC_WaitAck();
temp_1=IIC_RecByte();
IIC_SendAck(1);
IIC_Stop();
return temp_1;
}
void write_EEPROM(int add,int dat)
{
IIC_Start();
IIC_SendByte(0xa0);
IIC_WaitAck();
IIC_SendByte(add);
IIC_WaitAck();
IIC_SendByte(dat);
IIC_WaitAck();
IIC_Stop();
}
int read_EEPROM(int add)
{
int temp;
IIC_Start();
IIC_SendByte(0xa0);
IIC_WaitAck();
IIC_SendByte(add);
IIC_WaitAck();
IIC_Start();
IIC_SendByte(0xa1);
IIC_WaitAck();
temp=IIC_RecByte();
IIC_SendAck(1);
IIC_Stop();
return temp;
}
iic.h
#ifndef _IIC_H
#define _IIC_H
void IIC_Start(void);
void IIC_Stop(void);
bit IIC_WaitAck(void);
void IIC_SendAck(bit ackbit);
void IIC_SendByte(unsigned char byt);
unsigned char IIC_RecByte(void);
int Rd1();
int Rd3();
int read_EEPROM(int add);
void write_EEPROM(int add,int dat);
#endif
ds1302.c
/* Program description : DS1302 The driver Software environment : Keil uVision 4.10 Hardware environment : CT107 SCM comprehensive training platform 8051,12MHz Japan period : 2011-8-9 */
#include <reg52.h>
#include <intrins.h>
sbit SCK=P1^7;
sbit SDA=P2^3;
sbit RST = P1^3; // DS1302 Reset
void Write_Ds1302(unsigned char temp)
{
unsigned char i;
for (i=0;i<8;i++)
{
SCK=0;
SDA=temp&0x01;
temp>>=1;
SCK=1;
}
}
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;
}
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
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
边栏推荐
- 500 lines of code to understand the principle of mecached cache client driver
- Using SA token to solve websocket handshake authentication
- PHP campus financial management system for computer graduation design
- Computer graduation design PHP college student human resources job recruitment network
- A basic lintcode MySQL database problem
- LeetCode 322. Change exchange (dynamic planning)
- Kubernetes stateless application expansion and contraction capacity
- Virtual machine network, networking settings, interconnection with host computer, network configuration
- Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
- Redis key operation
猜你喜欢
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
Using SA token to solve websocket handshake authentication
1. Introduction to basic functions of power query
Numpy array index slice
Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
Redis如何实现多可用区?
[depth first search notes] Abstract DFS
Overview of spark RDD
Selenium waiting mode
Grabbing and sorting out external articles -- status bar [4]
随机推荐
剑指 Offer 12. 矩阵中的路径
Win10 add file extension
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Selenium element positioning (2)
How to improve the level of pinduoduo store? Dianyingtong came to tell you
[depth first search notes] Abstract DFS
Social networking website for college students based on computer graduation design PHP
Shutter doctor: Xcode installation is incomplete
National intangible cultural heritage inheritor HD Wang's shadow digital collection of "Four Beauties" made an amazing debut!
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
module ‘tensorflow. contrib. data‘ has no attribute ‘dataset
You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
【Flask】获取请求信息、重定向、错误处理
竞赛题 2022-6-26
Reasonable and sensible
Tensorflow customize the whole training process
500 lines of code to understand the principle of mecached cache client driver
Ali test Open face test
【Flask】静态文件与模板渲染