OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 7870|回复: 11

stm32 A/D采样的变量实时在线显示的问题

[复制链接]

2

主题

13

帖子

0

精华

新手上路

积分
41
金钱
41
注册时间
2013-5-14
在线时间
0 小时
发表于 2013-5-24 17:07:04 | 显示全部楼层 |阅读模式
/* Includes ------------------------------------------------------------------*/
#include "ili9320.h"
#include "stm32f10x_lib.h"
#include "platform_config.h"



#include "stdio.h"
#include  <string.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u16 AD_value;
u8 AsciiBuff[5];
static vu32 TimingDelay = 0;
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
vu16 ADCConvertedValue;
ErrorStatus HSEStartUpStatus;

extern u8 gImage_11[];

/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void ADC1_Configuration(void);
void InterruptConfig(void);
void NVIC_Configuration(void);
void Delay1(vu32 nCount);
void Decrement_TimingDelay(void);
void SysTick_Config(void);
void CheckBitmapFilesStatus(void);

/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name : main
* Description   : Main program.
* Input         : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
  debug();
#endif

  RCC_Configuration();   
  InterruptConfig();
  SysTick_Config();
  ADC1_Configuration();  
  GPIO_Configuration();
  ili9320_Initializtion(); //LCD初始化
  ili9320_Clear(Black);    //清屏

  ili9320_DrawPicture(68, 64, 97, 99, gImage_11);    //97分别99为图片的高度和宽度

  WriteString(10,220,"PT100数据采集系统当前电压值\r \n \r当前电压值:    \r  \n  \n \n  \r --基于STM32F103RB",Blue);
 
  WriteString(10,260,AsciiBuff,Blue);
  
/*    AsciiBuff[5]
  /* Configure IO connected to LD1, LD2, LD3 LD4 and LD5 leds *********************/
  /* Enable GPIO_LED clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_LED, ENABLE);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIO_LED, &GPIO_InitStructure);

  while (1)
  {
    /* Turn on LD1 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_6);
    /* Insert delay */
    Delay1(20);

    /* Turn on LD2 and LD3 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_7 | GPIO_Pin_8);
    /* Turn off LD1 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_6);
    /* Insert delay */
    Delay1(20);

    /* Turn on LD4 and LD5 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_9 | GPIO_Pin_10);
    /* Turn off LD2 and LD3 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_7 | GPIO_Pin_8);
    /* Insert delay */
    Delay1(20);

    /* Turn off LD4 and LD5 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_9 | GPIO_Pin_10);
  }   



 
}

 void HexToASCII(u16 data)
{

data = AD_value;     
AsciiBuff[0] = data/1000%10 + 0x30;
AsciiBuff[1] = data/100%10 + 0x30;
AsciiBuff[2] = data/10%10 + 0x30;
AsciiBuff[3] = data%10 + 0x30;
AsciiBuff[4] = 0;
}
/*******************************************************************************
* Function Name : RCC_Configuration
* Description   : Configures the different system clocks.
* Input         : None
* Output         : None
* Return         : None
*******************************************************************************/
/* ADC1 configuration ------------------------------------------------------*/
void ADC1_Configuration(void)
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 1;
  ADC_Init(ADC1, &ADC_InitStructure);

  /* ADC1 regular channel13 configuration */ 
  ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 1, ADC_SampleTime_55Cycles5);


  
  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 reset calibaration register */   
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));

  /* Start ADC1 Software Conversion */ 
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);

   AD_value=ADC_GetConversionValue(ADC1);
  
  
}


void RCC_Configuration(void)
{   
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if(HSEStartUpStatus == SUCCESS)
  {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);
 
    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1); 
  
    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1); 

    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);

    /* ADCCLK = PCLK2/4 */
    RCC_ADCCLKConfig(RCC_PCLK2_Div4); 

    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    /* Enable PLL */ 
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }
}

/*******************************************************************************
* Function Name : NVIC_Configuration
* Description   : Configures Vector Table base location.
* Input         : None
* Output         : None
* Return         : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef  VECT_TAB_RAM  
  /* Set the Vector Table base location at 0x20000000 */ 
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); 
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */ 
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
#endif
}

/*******************************************************************************
* Function Name : InterruptConfig
* Description   : Configures the used IRQ Channels and sets their priority.
* Input         : None
* Output         : None
* Return         : None
*******************************************************************************/
void InterruptConfig(void)
  /* Deinitializes the NVIC */
  NVIC_DeInit();

  NVIC_Configuration();

  /* Configure the Priority Group to 2 bits */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

  /* Configure the SysTick handler priority */
  NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 0, 0);
}

/*******************************************************************************
* Function Name : Delay
* Description   : Inserts a delay time.
* Input         : nCount: specifies the delay time length (time base 10 ms).
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Configure PC.03 (ADC Channel13) as analog input -------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOC, &GPIO_InitStructure);


}

 void Delay1(u32 nCount)
{
  TimingDelay = nCount;

  /* Enable the SysTick Counter */
  SysTick_CounterCmd(SysTick_Counter_Enable);
  
  while(TimingDelay != 0)
  {
  }

  /* Disable the SysTick Counter */
  SysTick_CounterCmd(SysTick_Counter_Disable);

  /* Clear the SysTick Counter */
  SysTick_CounterCmd(SysTick_Counter_Clear);
}

/*******************************************************************************
* Function Name : Decrement_TimingDelay
* Description   : Decrements the TimingDelay variable.
* Input         : None
* Output         : TimingDelay
* Return         : None
*******************************************************************************/
void Decrement_TimingDelay(void)
{
  if (TimingDelay != 0x00)
  {
    TimingDelay--;
  }
}

/*******************************************************************************
* Function Name : SysTick_Config
* Description   : Configure a SysTick Base time to 10 ms.
* Input         : None
* Output         : None
* Return         : None
*******************************************************************************/
void SysTick_Config(void)
{
  /* Configure HCLK clock as SysTick clock source */
  SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
 
  /* SysTick interrupt each 100 Hz with HCLK equal to 72MHz */
  SysTick_SetReload(720000);

  /* Enable the SysTick Interrupt */
  SysTick_ITConfig(ENABLE);
}
#ifdef  DEBUG
/*******************************************************************************
* Function Name : assert_failed
* Description   : Reports the name of the source file and the source line number
*                  where the assert_param error has occurred.
* Input         : - file: pointer to the source file name
*                  - line: assert_param error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif



问题一:我想实现AD采样的值能够在线显示在屏幕,但是我蒋AD转换程序和显示字符程序结合时,部分字符是可以显示出来,始终没能显示我想显示的变量值,烦请大神帮我看看程序结构有没有明显的错误。

问题二:程序上是写着“--基于STM32F103RB” 并且在字模中有“基于”的数组,但是 屏幕上并没有显示, 却在该位置上显示“数数”,求大神指点。








正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

15

主题

180

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
348
金钱
348
注册时间
2013-4-23
在线时间
25 小时
发表于 2013-5-24 17:17:42 | 显示全部楼层
回复【楼主位】竹语:
---------------------------------
while(1)里的东西都是GPIO的操作,不可能实现你的目标
回复 支持 反对

使用道具 举报

2

主题

13

帖子

0

精华

新手上路

积分
41
金钱
41
注册时间
2013-5-14
在线时间
0 小时
 楼主| 发表于 2013-5-24 17:25:39 | 显示全部楼层
回复【2楼】wobukansanguo:
---------------------------------
whle(1)里面的是led灯  但是屏幕显示同时,led并没有亮起来,说明while(1)也没有执行呢  ,     那如果要把AD采样变量实时在线显示,我该怎嘛改呀?
回复 支持 反对

使用道具 举报

15

主题

180

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
348
金钱
348
注册时间
2013-4-23
在线时间
25 小时
发表于 2013-5-24 17:34:53 | 显示全部楼层
回复【3楼】竹语:
---------------------------------
实时显示就要在while(1)中获得一次数据并显示。清除上一次显示后再显示本次,如此永无止境的循环下去
回复 支持 反对

使用道具 举报

2

主题

13

帖子

0

精华

新手上路

积分
41
金钱
41
注册时间
2013-5-14
在线时间
0 小时
 楼主| 发表于 2013-5-24 17:35:16 | 显示全部楼层
回复【2楼】wobukansanguo:
---------------------------------
 while (1)
   {
    /* Turn on LD1 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_6);
    /* Insert delay */
    Delay1(20);

    /* Turn on LD2 and LD3 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_7 | GPIO_Pin_8);
    /* Turn off LD1 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_6);
    /* Insert delay */
    Delay1(20);

    /* Turn on LD4 and LD5 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_9 | GPIO_Pin_10);
    /* Turn off LD2 and LD3 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_7 | GPIO_Pin_8);
    /* Insert delay */
    Delay1(20);

    /* Turn off LD4 and LD5 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_9 | GPIO_Pin_10);
    
      ADC1_Configuration();  
      GPIO_Configuration(); 
    WriteString(10,260,AsciiBuff,Blue);

}

我将AD采样变量显示句放在while(1)里面,现在 led灯在闪烁,但是显示界面依然没有变化。  就是采样变量调用在线显示功能始终没法实现。  到底是哪里的问题呢?
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-5-24 19:47:47 | 显示全部楼层
回复【5楼】竹语:
---------------------------------
你的画曲线函数在哪里?
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

2

主题

13

帖子

0

精华

新手上路

积分
41
金钱
41
注册时间
2013-5-14
在线时间
0 小时
 楼主| 发表于 2013-5-24 21:00:08 | 显示全部楼层
回复【6楼】正点原子:
---------------------------------
大神,我不是很理解你指的曲线函数是指哪个函数。  我是想将采样的变量实时显示在屏幕上,应该只是个变化的数字。
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-5-24 21:30:35 | 显示全部楼层
哦,sorry,我以为要显示曲线呢....
你单独测试下:WriteString(10,260,AsciiBuff,Blue); 
这个函数,看看好使不吧...
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

2

主题

13

帖子

0

精华

新手上路

积分
41
金钱
41
注册时间
2013-5-14
在线时间
0 小时
 楼主| 发表于 2013-5-24 22:06:42 | 显示全部楼层
回复【8楼】正点原子:
---------------------------------
  没法显示AsciiBuff      但可以显示字符    是我将AD采样值转换放在数组环节出错?   但是要怎么修改才可以?
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-5-25 00:28:27 | 显示全部楼层
学会如何将ad值转换为数组.
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

2

主题

13

帖子

0

精华

新手上路

积分
41
金钱
41
注册时间
2013-5-14
在线时间
0 小时
 楼主| 发表于 2013-5-25 15:41:34 | 显示全部楼层
回复【10楼】正点原子:
---------------------------------
嗯 可以了  可以将变量显示出来了    

  但是   一直显示的是  0000  不管我怎么变动 R7  始终没有在线变化   
大循环程序在下,

 while (1)
   {
    /* Turn on LD1 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_6);
    /* Insert delay */
    Delay1(20);

    /* Turn on LD2 and LD3 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_7 | GPIO_Pin_8);
    /* Turn off LD1 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_6);
    /* Insert delay */
    Delay1(20);

    /* Turn on LD4 and LD5 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_9 | GPIO_Pin_10);
    /* Turn off LD2 and LD3 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_7 | GPIO_Pin_8);
    /* Insert delay */
    Delay1(20);

    /* Turn off LD4 and LD5 */
     GPIO_SetBits(GPIO_LED, GPIO_Pin_9 | GPIO_Pin_10);

    ADC_GetConversionValue(ADC1) ;
     AD_value=ADC_GetConversionValue(ADC1);
 HexToASCII(AD_value);   
    WriteString(100,250,AsciiBuff,Blue);

}


A/D没有采样到吗?没有采样值?  要怎么看A/D是不是确实有采样到了?
回复 支持 反对

使用道具 举报

2

主题

13

帖子

0

精华

新手上路

积分
41
金钱
41
注册时间
2013-5-14
在线时间
0 小时
 楼主| 发表于 2013-5-25 15:59:42 | 显示全部楼层

void ADC1_Configuration(void)
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 1;
  ADC_Init(ADC1, &ADC_InitStructure);

  /* ADC1 regular channel13 configuration */ 
  ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 1, ADC_SampleTime_55Cycles5);
 
  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 reset calibaration register */   
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));

  /* Start ADC1 Software Conversion */ 
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);  
}

采样的是ADC13如图   是我配置有问题吗?  为什么总是显示的是0000




回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-7-19 08:23

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表