当前位置:网站首页>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*256vrsf 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/2Digital 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
边栏推荐
- 探索神经网络架构教程视频,设计神经网络的步骤
- 图像处理用什么神经网络,神经网络提取图片特征
- A few lines of code can crash the system;
- [网络安全]实操AWVS靶场复现CSRF漏洞
- Deep understanding of the array
- mysql之两阶段提交
- Chapter 12 Other Database Tuning Strategies [2. Index and Tuning] [MySQL Advanced]
- CuteOneP is a PHP-based OneDrive multi-network disk mount program with member synchronization and other functions
- 3. Transactions [mysql advanced]
- 搭建 risc-v 编译环境
猜你喜欢

深入理解数组

自动化测试框架Pytest(三)——自定义allure测试报告

ATH10 sensor reads temperature and humidity

语法基础(判断语句)

WooCommerce 安装和 rest api 使用

探索神经网络架构教程视频,设计神经网络的步骤

Confluence可以连接数据库但是在下一步就报错了

Fiddler(八) - 抓取手机APP的流量-插件Fiddler Orchestra Beta安装&配置

Reproduce dns out-band data combined with sqlmap

力扣(LeetCode)221. 最大正方形(2022.08.09)
随机推荐
求问各位大佬,FLink SQL读取source的时候去指定水位线的时间字段,如果指定的这个字段中格
自动化测试框架搭建 ---- 标记性能较差用例
概率分布及其应用
order by注入与limit注入,以及宽字节注入
1413. Stepwise Summation to Get Minimum Positive Numbers
oracle业务表的数据发生增删改,该表的索引会写redo,undo吗?
第2章 变量和基本类型读书笔记
图像处理用什么神经网络,神经网络提取图片特征
The difference between initializing objects as null and empty objects in JS
Sort binary tree code
May I ask why sqlserver cdc will report this error one day after the task is started, obviously cdc has been opened.
CuteOneP is a PHP-based OneDrive multi-network disk mount program with member synchronization and other functions
High quality WordPress download station 5 play theme template
u-boot ERROR: Failed to allocate 0x5c6f bytes below 0x17ffffff.Failed using fdt_high value
自动化测试框架Pytest(三)——自定义allure测试报告
力扣(LeetCode)221. 最大正方形(2022.08.09)
[Network Security] Practice AWVS Range to reproduce CSRF vulnerability
3-6月面经总结,200多页真题笔记和详解(含核心考点及6家大厂)
关于MongoDb查询Decimal128转BigDecimal问题
1413. 逐步求和得到正数的最小值