下你所需,载你所想!
汇集开发技术源码资料

STM8驱动数码管

:7.922MB :1 :2022-10-11 15:59:30

部分简介

STM8驱动数码管如果开发者对于本文件有需要的可以参考。
STM8驱动数码管
#include "stm8s.h"
#include "sys.h"
#include "stm8s_gpio.h"
#include "hddriver.h"
#include "display.h"
#define ADC_ABS(x) (((x) < (0)) ? (-(x)):(x))
void delay_us(unsigned short time)
{
unsigned short i;
for(i=0;i_asm("nop");
_asm("nop");
_asm("nop");
_asm("nop");
}
}
unsigned int current_arry[50]={0,0,0,};
void quick_sort(unsigned int *s, unsigned char l, unsigned char r)
{
if (l < r){
unsigned char i = l, j = r, x = s[l];
while (i < j){
while(i < j && s[j] >= x)
j--;
if(i < j)
s[i ] = s[j];
while(i < j && s[i] < x)
i ;
if(i < j)
s[j--] = s[i];
}
s[i] = x;
quick_sort(s, l, i - 1);
quick_sort(s, i 1, r);
}
}
uint16_t adc_v_pre=0;
uint16_t adc_v=0;
main()
{

uint32_t adc_ave=0;
uint8_t count;
sys_init();
adc_init();
gpio_init();
Display_init();
dis_data[0] = 0;
dis_data[1] = 1;
dis_data[2] = 2;
dis_data[3] = 3;
dis_data[4] = 4;
dis_data[5] = 5;
while (1){
// adc_ave=0;
for(count=0;count<50;count )
current_arry[count]=ADC1_GetConversionValue();//10it=1024

//quick_sort(current_arry,1,50);
adc_v_pre = adc_v;
adc_v=current_arry[20]/10.24 1;//adc_v*100)/1024;//0--100
if(adc_v>100) adc_v=100;
if(ADC_ABS(adc_v_pre-adc_v)>3){
//adc_v = adc_v_pre;
}else{
adc_v = adc_v_pre;
}
dis_data[0] = adc_v/100;
dis_data[1] = adc_v%100/10;
dis_data[2] = adc_v%10;
dis_data[3] = 3;
dis_data[4] = 4;
dis_data[5] = 5;
Display_data();

}
}

STM8驱动数码管

热门推荐

相关文章