|
stm32f103r6的程序带仿真 有4个模块的
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "adc.h"
- #include "smg.h"
- #include "timer.h"
- //0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F, .,全灭
- u8 smg_num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x80,0x00};
- u8 smg_wei=0;//数码管位选
- //ADC变量
- static u16 adcx=0;
- static u16 adcx1=0;
- static float temp=0;
- u8 num=0;//数码管值
- u8 adc_t=0;//adc采样时间值
- int main(void)
- {
- LED_Init();
- Adc_Init();
- while(1) {
-
- adc_t++;
- if(adc_t==10)//ADC 采样
- {
- adc_t=0;
- adcx=Get_Adc_Average(ADC_CH9,3);//ADC原始值
- temp=(float)adcx*(3.3/4096);//ADC电压值
- adcx1=temp;
- temp-=adcx1;
- temp*=1000;
- }
- Delay(30);
- if(adcx>0){
- switch(smg_wei)
- {
- //ADC采样原始值
- case 0: if(adcx>1000)num = smg_num[adcx/1000];
- else num = 0x00;
- break;
- case 1: if(adcx>100) num = smg_num[adcx%1000/100];
- else num = 0x00;
- break;
- case 2: if(adcx>10) num = smg_num[adcx%100/10];
- else num = 0x00;
- break;
- case 3: num = smg_num[adcx%10]; break;
- case 4: num = 0x00; break;
- //ADC换算后的电压值
- case 5: // num = smg_num[adcx1]|0x01;break;
- num = smg_num[adcx1]|0x80;break;
- case 6: num = smg_num[(u16)temp/100]; break;
- case 7: num = smg_num[(u16)temp%100/10];break;
- }
- GPIOC->ODR=num;
- LED_Wei(smg_wei);
- smg_wei++;
- if(smg_wei==8)
- smg_wei=0;
- }
-
- }
- }
复制代码
所有资料51hei提供下载:
|
评分
-
查看全部评分
|