/* 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” 并且在字模中有“基于”的数组,但是 屏幕上并没有显示, 却在该位置上显示“数数”,求大神指点。
|