我用的
芯片是
STM32,以下程序可以编译通过,但是TFT是白屏,大侠帮忙看看,指出问题,小弟不胜感激!
#include "stm32f10x.h"
#include "stm32_eval.h"
#include <stdio.h>
#include "ili9320.h"
#include "stm32f10x_conf.h"
#include "ili9320_api.h"
#include "stm32f10x_adc.h"
#include "stm32f10x_dma.h"
#include "
ARMJISHU_TouchScreen_ADS7843.h"
#define BmpHeadSize (54)
#define DR_ADDRESS ((uint32_t)0x4001244C) //ADC1 DR寄存器基地址
ADC_InitTypeDef ADC_InitStructure; //ADC初始化结构体声明
DMA_InitTypeDef DMA_InitStructure; //DMA初始化结构体声明
__IO uint16_t ADCConvertedValue; // ADC为12位模数转换器,只有ADCConvertedValue的低12位有效
void ADC_GPIO_Configura
tion(void);
void Num2String(uint32_t Num,uint8_t *Ptr);
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
static void Delay_ARMJISHU(__IO uint32_t nCount)
{
for (; nCount != 0; nCount--)
{
if(GPIO_ADS7843_INT_VALID)
{
ARMJISHU_TouchScreen_ADS7843();
}
}
}
void ili9320_PutStr_16x24(u16 StartX, u16 StartY, u8 *str, u16 len, u16 charColor, u16 bkColor)
{
u16 i;
u8 *pstr = str;
for (i=0 ;i<len;i++)
{
ili9320_PutChar_16x24((StartX+16*i),StartY,*pstr++,charColor,bkColor);
}
}
void ili9320_PutStr_16x24_Center(u16 StartY, u8 *str, u16 len, u16 charColor, u16 bkColor)
{
u16 StartX;
StartX = (320 - 16*len)/2;
ili9320_PutStr_16x24(StartX,StartY, str, len, charColor, bkColor);
}
int main(void)
{
u16 i, len;
u8 AD_CharData[4];
u8 *str;
u16 charColor;
u16 bkColor;
len = sizeof(AD_CharData)-1;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //使能DMA时钟
/* DMA1 channel1 configuration ----------------------------------------------*/
DMA_DeInit(DMA1_Channel1); //开启DMA1的第一通道
DMA_InitStructure.DMA_PeripheralBaseAddr = DR_ADDRESS; //DMA对应的外设基地址
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue; //内存存储基地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //DMA的转换模式为SRC模式,由外设搬移到内存
DMA_InitStructure.DMA_BufferSize = 1; //DMA缓存大小,1个
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //接收一次数据后,设备地址禁止后移
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; //关闭接收一次数据后,目标内存地址后移
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //定义外设数据宽度为16位
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //DMA搬移数据尺寸,HalfWord就是为16位
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //转换模式,循环缓存模式。
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMA优先级高
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //M2M模式禁用
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
/* Enable ADC1 and GPIOC clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE); //使能ADC和GPIOC时钟
/* ADC1 configuration ------------------------------------------------------*/
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外部开关,关闭状态
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //对齐方式,ADC为12位中,右对齐方式
ADC_InitStructure.ADC_NbrOfChannel = 1; //开启通道数,1个
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel13 configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 1, ADC_SampleTime_55Cycles5);
//ADC通道组, 第13个通道 采样顺序1,转换时间
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE); //ADC命令,使能
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE); //开启ADC1
/* 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); //连续转换开始,ADC通过DMA方式不断的更新RAM区。
ili9320_Initializtion();
ili9320_Clear(Blue);
while (1)
{
Num2String(ADCConvertedValue,AD_CharData);
ili9320_PutStr_16x24_Center(20, AD_CharData, len,charColor, bkColor);
Delay_ARMJISHU(10000000);
}
}
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(EVAL_COM1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
{
}
return ch;
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif
void ADC_GPIO_Configuration(void) //ADC配置函数
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure PC.00 (ADC Channel10) as analog input -------------------------*/
//PC0 作为模拟通道10输入引脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //管脚1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;//输入模式
GPIO_Init(GPIOC, &GPIO_InitStructure); //GPIO组
}
//int整型数转换成字符串
void Num2String(uint32_t Num,uint8_t *Ptr)
{
uint8_t instr[4];
uint8_t i=4;
uint8_t k;
do
{
instr[--i] = Num%10+'0';
Num/=10;
}while(Num!=0);
for(k=i;k<4;k++)
{
*Ptr++=instr[k];
}
*Ptr = ' ';
}
嗯,这个方法值得学习,后来调通了。
一周热门 更多>