声明本人是新人请各位大佬多多关照,由于在做任务时遇到的问题,我希望能够一一在论坛上能够帮到你们。该文件适用于将stm32f407的寄存器版本的例程LCD的ADC过渡到OLED
单片机源程序如下:
- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "oled.h"
- #include "key.h"
- #include "adc.h"
- #include "led.h"
- extern __IO u16 ADC_ConvertedValue[9];
- u8 temp;
- u8 temp1;
- u32 AD1_value,AD2_value;
- int main(void)
- { u16 adcx;
- u16 adcx1;
- u8 i=0;
- u8 keyval=0;
- KEY_Init();
- Stm32_Clock_Init(336,8,2,7);
- delay_init(10);
- uart_init(84,115200);
- OLED_Init();
- Adc_Init();
- LED_Init();
- OLED_Refresh_Gram();//更新显示到OLED
- while(1)
- {
-
-
- OLED_ShowFontHZ(16*0,0,0,16,1);
- OLED_ShowFontHZ(16*1,0,1,16,1);//电压-60
- OLED_ShowFontHZ(16*2,0,3,16,1);
-
- OLED_ShowFontHZ(16*0,15,0,16,1);
- OLED_ShowFontHZ(16*1,15,2,16,1);//电流-40
- OLED_ShowFontHZ(16*2,15,3,16,1);
-
- OLED_ShowFontHZ(16*0,30,5,16,1);
- OLED_ShowFontHZ(16*1,30,6,16,1);//功率-20
- OLED_ShowFontHZ(16*2,30,3,16,1);
-
- OLED_ShowFontHZ(16*0,45,7,16,1);
- OLED_ShowFontHZ(16*1,45,8,16,1);//公因0
- OLED_ShowFontHZ(16*2,45,3,16,1);
-
- adcx1=Get_Adc_Average(ADC_CH5,20);//通道5平均数赋值adcx1
- temp=(float)adcx1*(3.3/4096);
- adcx=temp;
- LCD_ShowxNum(16*3.2,0,adcx,1,16,1);//显示电压值
-
- AD2_value=adcx1*10.0;
- OLED_ShowNum(16*5,0,AD2_value,3,16);//小数部分
- OLED_ShowFontHZ(16*4,0,9,16,1);//.
- OLED_ShowFontHZ(16*7,0,4,16,1);//v
-
-
- delay_ms(250);
- OLED_Refresh_Gram();//更新显示到OLED
- delay_ms(500);
- keyval=KEY_Scan();
- switch(keyval)
- {
- case 1:
- if(keyval==1)
- {
- delay_ms(250);
- LED0=~LED0;
- delay_ms(250);
-
- }
-
-
- break;
- case 2:
- if(keyval==2)
- {
- }
-
- break;
- case 3 :
- if(keyval==3)
- {
- }
- break;
- case 4 : //同时控制LED0,LED1翻转
- if(keyval==4)
- {
- }
- break;
-
- }
- }
-
-
- }
复制代码
所有资料51hei提供下载:
菜单ADC内部测电压.7z
(121.14 KB, 下载次数: 37)
|