当前位置:网站首页>Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
2022-08-10 06:56:00 【won't take pictures】
#Foreword
This article mainly explains how to use the OLED screen to display the analog value detected by the analog light sensor
For how to use the OLED screen, please refer toBased on STC8G2K64S4 microcontroller to control OLED screen through I2C hardware
Finally, I won't be bothered by the photosensitive threshold and the light factor of the venue. The first two times were because of this, and then the consecutive start failed and it split directly in situ.Use the OLED display to display the analog values to observe the parameters more intuitively, and then modify the threshold values in the program
Hardware aspects
The main control board and OLED continue to use the last one, so I won't introduce it here. If you don't understand, you can read the article I mentioned above
The analog photosensitive is used here, and there are many treasures.The main difference from digital is that it will be smaller, there is no adjustable resistance, and the price will be relatively lower
As the name suggests, the analog photosensitive does not output a digital quantity, that is to say, it is not a simple 0 and 1, but an output analog value.In fact, the digital photosensitive is to add an adjustable rheostat on the principle of analog quantity to determine a value as the dividing line, and then compare the analog value with the dividing line, if it is greater than the dividing line, it will output 1; if it is less than the dividing line, the output will be 0
Let's talk about color first. Of course, there is no big problem with normal black and white. If there is light yellow or red, it is likely to be judged as white, which will lead to tracking problems.Although there are adjustable resistors, you can adjust the level of the dividing line, but you can't see it directly. Maybe it can be detected by a multimeter or other methods, but it greatly increases the time
Furthermore, there is the problem of the site. The ambient light at the scene is basically different from the ambient light that I debugged in the school. This will also cause the analog value of black or white to cross the dividing line, and all are judged as one color.If this happens in the three minutes of preparation before the game, it will explode directly
So the use of analog photosensitive can solve all the above problems, and the tracking part will basically not have problems
Software aspects
The analog value cannot be directly seen in the program, and it needs to be converted into an analog value through ad.
Note here that the pin of the analog photosensitive OUT must be connected to the pin of the microcontroller with adc function, not the common io port.This also depends on the chip
The principle is that the analog light sensor detects the voltage, and then the pin of the microcontroller needs to convert this voltage into an analog value, the formula is as follows
a //Analog valuev //Measured voltagevrsf //reference voltage256 //8-bit precisiona=v/vref*256
vrsf is generally explained in the chip manual, different chips are different.In STC8G2K64S4, it is connected with vcc, so it is 5V
Accuracy is easy to understand. The larger the number of digits, the more accurate it is. Generally, there are 9 and 10 digits to choose from
The next step is to display the analog value with OLED, and also use the library function of Zhufei Technology
Initialize adc:
adc_init(ADC_P06,ADC_SYSclk_DIV_2); //Select P06 as ADC function, ADC clock frequency is SYSclk/2
Digital display of analog values:
void gewei() //One digit display{int yushu;yushu=q%10;if(yushu == 1)one(2,47);if(yushu == 2)two(2,47);if(yushu == 3)three(2,47);if(yushu == 4)four(2,47);if(yushu == 5)five(2,47);if(yushu == 6)six(2,47);if(yushu == 7)seven(2,47);if(yushu == 8)eight(2,47);if(yushu == 9)nine(2,47);if(yushu == 0)zero(2,47);}void shiwei() //Ten display{int yushu;yushu=q/10%10;if(yushu == 1)one(2,40);if(yushu == 2)two(2,40);if(yushu == 3)three(2,40);if(yushu == 4)four(2,40);if(yushu == 5)five(2,40);if(yushu == 6)six(2,40);if(yushu == 7)seven(2,40);if(yushu == 8)eight(2,40);if(yushu == 9)nine(2,40);if(yushu == 0)zero(2,40);}void baiwei() //Hundreds display{int yushu;yushu=q/100%10;if(yushu == 1)one(2,33);if(yushu == 2)two(2,33);if(yushu == 3)three(2,33);if(yushu == 4)four(2,33);if(yushu == 5)five(2,33);if(yushu == 6)six(2,33);if(yushu == 7)seven(2,33);if(yushu == 8)eight(2,33);if(yushu == 9)nine(2,33);if(yushu == 0)zero(2,33);}
Main code:
#include "headfile.h"int q;void main(){DisableGlobalIRQ(); //Close the total interruptboard_init(); //Initialize internal registers, do not delete this code.init_all(); //Initialize all functionsEnableGlobalIRQ(); //Enable global interruptpingmu_init(); //Screen initializationxianshi(); //Open the screen displaywhile(1){q = adc_once(ADC_P06, ADC_10BIT); //collect ADC once, precision 10 bitsgewei(); //display unitsshiwei(); //display tensbaiwei(); //display hundredspca_delay_ms(10);}}
Please refer to the OLED code hereBased on STC8G2K64S4 microcontroller to control OLED screen through I2C hardware
Effect display:
#Summary
I believe that in future competitions, the photosensitive tracking will be very stable, and I will not panic because of insufficient time on site.Although it is not a very powerful thing, it may be very useful.In terms of code, there are still many sub-functions that need to be optimized. Once these things are done, it will be more convenient in the subsequent use process
I am a novice, I have questions to exchange and discuss, and be taught with an open mind
边栏推荐
- 2022河南萌新联赛第(五)场:信息工程大学 H - 小明喝奶茶
- 数据库公共字段自动填充
- 复现dns外带数据结合sqlmap
- Discussion on Chinese Fuzzy Retrieval in Databases
- 自动化测试框架Pytest(三)——自定义allure测试报告
- Chapter 11 Database Design Specifications [2. Index and Tuning] [MySQL Advanced]
- 人工神经网络工作原理,神经网络的工作原理
- 【电商业务】外行为何难区别 商品属性与商品规格
- Deep understanding of the array
- Quickly grasp game resources in one hour and remote hot update
猜你喜欢
What is an MQTT gateway?What is the difference with traditional DTU?
基于STC8G2K64S4单片机通过OLED屏幕显示模拟量光敏模拟值
深入理解数组
MySQL's InnoDB engine (6)
神经网络可视化有3D版本了,美到沦陷 已开源
概率分布及其应用
结构体初阶
C语言文件操作
Data types for database learning
Nude speech - lying flat - brushing questions - big factory (several tips for Android interviews)
随机推荐
Big guy, when Oracle single-table incremental synchronization, the source database server takes up nearly 2g of memory. This is not normal, right?
【MySQL】使用MySQL Workbench软件新建表
2022 Henan Mengxin League No. 5: University of Information Engineering J-AC Automata
结构体初阶
2022河南萌新联赛第(五)场:信息工程大学 F - 分割草坪
MySQL事务隔离级别
请问为什么sqlserver cdc,任务启动过了一天,会报这个错误,明明已经开启cdc了。
数据库学习之表的约束
3. Transactions [mysql advanced]
自组织是管理者和成员的双向奔赴
Ladies and gentlemen, oracle11g, cdc2.2, flink1.13.6, single-table incremental synchronization.Without adding data
Grammar Basics (Judgment Statements)
[Reinforcement Learning] "Easy RL" - Q-learning - CliffWalking (cliff walking) code interpretation
大佬,oracle单表增量同步时候源库服务器额外占用内存近2g,这不正常吧
761. 特殊的二进制序列
IDLE开发wordCount程序(第五弹)
力扣(LeetCode)221. 最大正方形(2022.08.09)
浅谈C语言实现冒泡排序
【Event Preview on August 9】Prometheus Summit
各位大佬,oracle11g,cdc2.2,flink1.13.6,单表增量同步。在没新增数据的情