当前位置:网站首页>The fourth provincial competition of Bluebridge cup single chip microcomputer
The fourth provincial competition of Bluebridge cup single chip microcomputer
2022-07-02 03:38:00 【Super 561】



difficulty :1 Show the amount of water : The total water output has a decimal point, so let the total water output *100, The interruption of calculating the total water output takes one millisecond as a cycle , The outflow speed is 100ml/ second , The nixie tube shows : The total water output is in liters ,0.01 l =10ml, So every time 100ms Add one to the total water output .
if(water_flag==1)
{
water_count++;
if(water_count>=100)
{
water_count=0;
water=water+1;
}
}2 Show total price : Price or let price *100 Show ; Because the price is 0.5 element / l , So divide the total water yield by 2 Get price
main.c
#include <STC15F2K60S2.H>
#include <IIC.H>
unsigned char display_mode=1;// Nixie tube display interface
unsigned int water;// Total water output
unsigned int cost;// Price
unsigned int dianya;// voltage
unsigned char ad(unsigned char add)//ad function
{
unsigned char date;
IIC_Start();
IIC_SendByte(0X90);
IIC_WaitAck();
IIC_SendByte(add);
IIC_WaitAck();
IIC_Start();
IIC_SendByte(0X91);
IIC_WaitAck();
date=IIC_RecByte();
IIC_SendAck(1);
IIC_Stop();
return date;
}
unsigned int ad_count;
void da_process()// Used to read the acquisition voltage
{
if(ad_count>5)
{
ad_count=0;
dianya=ad(0x01);
dianya=dianya/51;
}
}
void Device_ctrl(unsigned char p2date,unsigned char p0date)
{
P0=p0date;
P2=P2&0x1f|p2date;
P2&=0x1f;
}
unsigned char trig_btn;
unsigned char cont_btn;
unsigned int key_count;
bit water_flag;
void key_btn()// Key function
{
unsigned char readdate=P3^0xff;
trig_btn=readdate&(cont_btn^readdate);
cont_btn=readdate;
}
void key_process()// Key handling functions
{
if(key_count>=5)
{
key_count=0;
key_btn();
if(trig_btn==0x08)//s4
{
}
if(trig_btn==0x04)//s5
{
}
if(trig_btn==0x02)//s6
{
display_mode=0;
water_flag=0;
cost=0.5*water;
Device_ctrl(0xa0,0x00);
}
if(trig_btn==0x01)//s7
{
display_mode=1;
water_flag=1;
Device_ctrl(0xa0,0x30);
}
}
}
unsigned char smg_display[8];
unsigned int smg_count;
unsigned char smg_du[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void smg_show()// Nixie tube function
{
unsigned int i;
Device_ctrl(0xc0,0);
Device_ctrl(0xe0,~smg_display[i]);
Device_ctrl(0xc0,0x01<<i);
i=(i+1)%8;
}
void smg_process()// Nixie tube interface display
{
if(smg_count>=3)
{
smg_count=0;
if(display_mode)
{
smg_display[0]=0x00;
smg_display[1]=smg_du[0]|0x80;
smg_display[2]=smg_du[5];
smg_display[3]=smg_du[0];
smg_display[4]=smg_du[water/1000];
smg_display[5]=smg_du[water/100%10]|0x80;
smg_display[6]=smg_du[water/10%10];
smg_display[7]=smg_du[water%10];
}
else
{
smg_display[0]=0x00;
smg_display[1]=smg_du[0]|0x80;
smg_display[2]=smg_du[5];
smg_display[3]=smg_du[0];
smg_display[4]=smg_du[cost/1000];
smg_display[5]=smg_du[cost/100%10]|0x80;
smg_display[6]=smg_du[cost/10%10];
smg_display[7]=smg_du[cost%10];
}
}
}
unsigned int led_count;
void led_process()//LED function
{
if(led_count>5)
{
led_count=0;
if(dianya<1.25)
{
Device_ctrl(0x80,~0x01);
}
else
{
Device_ctrl(0x80,0xff);
}
}
}
void Timer2Init() //1 millisecond @12.000MHz
{
AUXR |= 0x04; // Timer clock 1T Pattern
T2L = 0x20; // Set initial value of timing
T2H = 0xD1; // Set initial value of timing
AUXR |= 0x10; // Timer 2 Start timing
IE2|=0X04;
EA=1;
}
void main()
{
Timer2Init();
Device_ctrl(0x80,0xff);
Device_ctrl(0xa0,0x00);
while(1)
{
smg_process();
key_process();
da_process();
led_process();
}
}
unsigned int water_count;
void water_process()
{
if(water_flag==1)
{
water_count++;
if(water_count>=100)
{
water_count=0;
water=water+1;
}
}
}
void timer2service() interrupt 12
{
smg_count++;
smg_show();
ad_count++;
water_process();
key_count++;
led_count++;
}iic.c
#include "iic.h"
#define DELAY_TIME 5
//I2C Bus internal delay function
void IIC_Delay(unsigned char i)
{
do{_nop_();}
while(i--);
}
//I2C Bus start signal
void IIC_Start(void)
{
SDA = 1;
SCL = 1;
IIC_Delay(DELAY_TIME);
SDA = 0;
IIC_Delay(DELAY_TIME);
SCL = 0;
}
//I2C Bus stop signal
void IIC_Stop(void)
{
SDA = 0;
SCL = 1;
IIC_Delay(DELAY_TIME);
SDA = 1;
IIC_Delay(DELAY_TIME);
}
// Send a reply or non reply signal
void IIC_SendAck(bit ackbit)
{
SCL = 0;
SDA = ackbit;
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;
}
//I2C The bus sends a byte of 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;
}
//I2C The bus receives a byte of data
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;
}
iic.h
#ifndef __IIC_H
#define __IIC_H
#include <STC15F2K60S2.H>
#include "intrins.h"
sbit SDA = P2^1;
sbit SCL = P2^0;
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);
#endif边栏推荐
- Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
- How to establish its own NFT market platform in 2022
- Global and Chinese markets for hand hygiene monitoring systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Go execute shell command
- uniapp 使用canvas 生成海报并保存到本地
- 傅里叶级数
- Kubernetes cluster storageclass persistent storage resource core concept and use
- Global and Chinese market of gynaecological health training manikin 2022-2028: Research Report on technology, participants, trends, market size and share
- [punch in] flip the string (simple)
- Load different fonts in QML
猜你喜欢

蓝桥杯单片机省赛第九届

In wechat applet, the externally introduced JS is used in xwml for judgment and calculation

MySQL index, transaction and storage engine

Getting started with MQ

《MATLAB 神經網絡43個案例分析》:第42章 並行運算與神經網絡——基於CPU/GPU的並行神經網絡運算

蓝桥杯单片机省赛第十一届第二场

蓝桥杯单片机省赛第七届

Haute performance et faible puissance Cortex - A53 Core Board | i.mx8m mini

蓝桥杯单片机省赛第十二届第二场

汇率的查询接口
随机推荐
NLog使用
【DesignMode】建造者模式(Builder model)
跳出舒适区,5年点工转型自动化测试工程师,我只用了3个月时间
Failed to upgrade schema, error: “file does not exist
微信小程序中 在xwml 中使用外部引入的 js进行判断计算
蓝桥杯单片机省赛第十届
Global and Chinese market of bone adhesives 2022-2028: Research Report on technology, participants, trends, market size and share
Uniapp uses canvas to generate posters and save them locally
What is the binding path of SAP ui5
蓝桥杯单片机数码管技巧
[golang] leetcode intermediate bracket generation & Full Permutation
[mv-3d] - multi view 3D target detection network
Pointer array & array pointer
"Analysis of 43 cases of MATLAB neural network": Chapter 41 implementation of customized neural network -- personalized modeling and Simulation of neural network
Global and Chinese market of handheld ultrasonic scanners 2022-2028: Research Report on technology, participants, trends, market size and share
Use blocking or non blocking for streamline
接口调试工具模拟Post上传文件——ApiPost
Which of PMP and software has the highest gold content?
uniapp 使用canvas 生成海报并保存到本地
Load different fonts in QML