初级会员

- 积分
- 132
- 金钱
- 132
- 注册时间
- 2012-4-7
- 在线时间
- 0 小时
|
#include "usart.h"
//#include "stm32f10x.h" //这个头文件包括STM32F10x所有外围寄存器、位、内存映射的定义
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "uCOS_II.H"
#include "gui.h"
#include "adc.h"
#ifndef GUI_FLASH
#define GUI_FLASH
#endif
extern GUI_FLASH const GUI_FONT GUI_FontHZ_front;
//#define N 50 //滤波次数
/*-------------------------------------------------
功能:中位数滤波函数,N值可根据实际情况调整
排序采用冒泡法
参数:滤波前AD值
返回:滤波后的AD值
--------------------------------------------------*/
/*u16 Filter(u8 ch)
{
u16 value;
u16 value_buf[N];
u16 count,i,j,temp;
for ( count=0;count<N;count++)
{
value=Get_ADC(ch);
delay_ms(1);
value_buf[count] = value;
}
for (j=0;j<N-1;j++)
{
for (i=0;i<N-j;i++)
{
if ( value_buf>value_buf[i+1] )
{
temp = value_buf;
value_buf = value_buf[i+1];
value_buf[i+1] = temp;
}
}
}
temp=0;
for(i=0;i<5;i++)
{
temp=temp+value_buf[N/2-i]+value_buf[N/2+i];
}
return temp/10;
}
*/
/*-------------------------------------------------
功能:串口1发送字符串
参数:字符串,
返回:无
--------------------------------------------------*/
void Uart1_PutChar(u8 ch)
{
USART1->DR = (u8)ch;
while((USART1->SR&0X40)==0); //循环发送,直到发送完毕
}
void Uart1_PutString(u8 *Buf,u8 len)
{
u8 i;
for(i= 0; i<len; i++)
{
Uart1_PutChar(*Buf++);
}
}
int main(void)
{
u8 *p;
u8 table[5];
u32 adcx;
u16 temp=0;
p=table;
SystemInit();
delay_init(); //延时初始化
uart_init(9600);
NVIC_Configuration();//设置NVIC中断分组2:2位抢占优先级,2位响应优先级
GUI_Init();
Adc_Init();
while(1)
{
//adcx=Get_Adc_Average(ADC_Channel_0,10);
adcx=Get_Adc(ADC_Channel_0);
// GUI_DispDecAt(adcx,156,130,4) ;
temp =adcx*(330/4096);
adcx = temp;
GUI_DispDecAt(adcx,156,130,4) ; // 此处的数据显示出来为0000 不知道咋回事
table[0]=adcx / 100 + 0x30;
table[1]='.';
table[2]=adcx % 100/10 + 0x30;
table[3]=adcx %10 + 0x30;
table[4]='V';
Uart1_PutString(p,5); //串口1发送数据
Uart1_PutString("\r\n",2); //换行
delay_ms(50);
}
}
问题乳红色字体
|
|