GD32F103 — 17-ADC测可调电阻和光敏电阻

GD32F103 DRG GD-1 17-ADC测可调电阻和光敏电阻 示例

GD32F103 — 17-ADC测可调电阻和光敏电阻

来源: DRG GD-1 开发板例程
源文件: GD32/drg_gd_1_gd32f103c8t6-master/17-ADC测可调电阻和光敏电阻/test/APP/main.c

子模块

  • Firmware
  • test

关键代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include "systick.h"
#include "i2c.h"
#include "oled_i2c.h"
#include "resister_adc.h"

int main(){
	systick_config();
	i2c_init();
	
	oled_init();
	oled_clear_all();
	oled_show_string(14, 0, (uint8_t *)"Resister ADC", 16);
	
	resister_adc_init();
	float photo_res;  //Źֵ
	float var_res;    //ſɵֵ
	
	char temp_string[20];  // ֵתΪַĽ

	while(1){
		// ʾתĽ
		photo_res = get_photo_r();
		sprintf(temp_string, "photo_res:%.1fKohm", photo_res);
		oled_show_string(2, 2, (uint8_t *)temp_string, 8);
		
		// ʾɵתĽ
		var_res = get_var_r();
		sprintf(temp_string, "var_res:%.1fKohm", var_res);
		oled_show_string(2, 3, (uint8_t *)temp_string, 8);
		
	}
}
世界是你们
使用 Hugo 构建
主题 StackJimmy 设计