打印
[STM32F1]

用32驱动12864的问题

[复制链接]
823|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
renchouduodushu|  楼主 | 2015-7-20 22:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*Include---------------------------*/
#include"stm32f10x_lib.h"                //°üº¬ËùÓеÄÍ·Îļþ
#include<stdio.h>

//----------------º¯ÊýÉùÃ÷--------------------
void Delay_MS(u16 dly)
{
        u16 i,j;
        for(i=0;i<dly;i++)
                for(j=1000;j>0;j--);
}

void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART3_Configuration(void);
void LCDDisplay(u8 x, u8 y, u8 *Data);
void LCDInit(void);
void LCDCursorPosition(u8 x, u8 y);
void LCDWriteData(u8 Data);
void LCDWiteCommand(u8 Command);
void LcdData(unsigned char Data);

/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{       
       
//        u8 i;
//        u8 data1[]={0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca};
//        u8 data[]={0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca};
//        #ifdef DEBUG
//        debug();
//        #endif

//        //------------³õʼ»¯------------
//        RCC_Configuration();
//        GPIO_Configuration();
//        USART3_Configuration();
//        while(1)
//        {
//                for(i=0;i<5;i++)
//                {
//                USART_SendData(USART3, data[i]);
//                Delay_MS(2000);
//                }
//        }
                RCC_Configuration();
                GPIO_Configuration();
                GPIO_SetBits(GPIOB, GPIO_Pin_11);
                //----------------PB8.9.10.11
                //¸ßÊÇÊý¾ÝÊäÈëµÍÊÇÖ¸Áî
                //¸ßÊǶÁÈ¡ µÍÊÇдÈë
                //´ÓµÍµ½¸ßµÄÌø±ä
                //¸ßÊDz¢ÐÐ µÍÊÇ´®ÐÐ
                        LCDInit();
                 while (1)
  {

               
//                Delay_MS(20);
//                LCDInit();
//                Delay_MS(20);
               
                //        for(i=0;i<5;i++)
        //                {       
                       
        //                }
               
                        LCDDisplay(0, 1, "¹þ¹þÄãÃÃ");
                        LCDDisplay(1, 2, "ÖÕÓڳɹ¦ÁË");
                        LCDDisplay(2, 0, "¸Ð¾õÔÙÒ²²»°®ÁË");
                        LCDDisplay(3, 2, "ÄÌÄ̵Ä");
//         
        }
}

/*******************************************************************************
* Function Name  : Delay_Ms
* Description    : delay 1 ms.
* Input          : dly (ms)
* Output         : None
* Return         : None
*******************************************************************************/

/*******************************************************************************
* Function Name  : RCC_Configuration
* Description    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RCC_Configuration(void)
{
        //----------ʹÓÃÍⲿRC¾§Õñ-----------
        RCC_DeInit();                        //³õʼ»¯ÎªÈ±Ê¡Öµ
        RCC_HSEConfig(RCC_HSE_ON);        //ʹÄÜÍⲿµÄ¸ßËÙʱÖÓ
        while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);        //µÈ´ýÍⲿ¸ßËÙʱÖÓʹÄܾÍÐ÷
       
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);        //Enable Prefetch Buffer
        FLASH_SetLatency(FLASH_Latency_2);                //Flash 2 wait state
       
        RCC_HCLKConfig(RCC_SYSCLK_Div1);                //HCLK = SYSCLK
        RCC_PCLK2Config(RCC_HCLK_Div1);                        //PCLK2 =  HCLK
        RCC_PCLK1Config(RCC_HCLK_Div2);                        //PCLK1 = HCLK/2
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);        //PLLCLK = 8MHZ * 9 =72MHZ
        RCC_PLLCmd(ENABLE);                        //Enable PLLCLK

        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);        //Wait till PLLCLK is ready
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);        //Select PLL as system clock
        while(RCC_GetSYSCLKSource()!=0x08);                //Wait till PLL is used as system clock source
       
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB,ENABLE );
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO ,ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
}


void GPIO_Configuration(void)
{
       
        GPIO_InitTypeDef        GPIO_InitStructure;       


        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;//指令和数据输出管脚
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;       
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;
        GPIO_Init(GPIOA,&GPIO_InitStructure);                               
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//指令和数据管脚
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;       
        GPIO_Init(GPIOB,&GPIO_InitStructure);                               
                                               
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//读写管脚
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;       
        GPIO_Init(GPIOB,&GPIO_InitStructure);                               
                                                                                                                                                                                       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//使能管脚
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;       
        GPIO_Init(GPIOB,&GPIO_InitStructure);                               
                                                                                                                                                                                       
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//用于12864的串并控制接12864的15脚
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP  ;         
        GPIO_Init(GPIOB,&GPIO_InitStructure);                                 
                                                                                                                                                                               
       

       
}
void LCDWiteCommand(u8 Command)
{
         u8 LCDTemp = 0;
         GPIO_ResetBits(GPIOB,GPIO_Pin_8);
         GPIO_ResetBits(GPIOB,GPIO_Pin_9);
         GPIO_SetBits(GPIOB,GPIO_Pin_10);
         Delay_MS(10);
         LCDTemp = LCDTemp | Command;
         GPIO_Write(GPIOA, LCDTemp);
         Delay_MS(10);
         GPIO_ResetBits(GPIOB,GPIO_Pin_10);
         Delay_MS(10);
}
void LCDWriteData(u8 Data)
{
         u8 LCDTemp = 0;
         GPIO_SetBits(GPIOB,GPIO_Pin_8);
         GPIO_ResetBits(GPIOB,GPIO_Pin_9);
         GPIO_SetBits(GPIOB,GPIO_Pin_10);
         Delay_MS(10);
         LCDTemp = LCDTemp | Data;
         GPIO_Write(GPIOA, LCDTemp);
         Delay_MS(10);
         GPIO_ResetBits(GPIOB,GPIO_Pin_10);
         Delay_MS(10);  
}

void LCDCursorPosition(u8 x, u8 y)
{
         u8 Position;
         if (x==0)
         {
                        x=0x80;
         }
         else if (x==1)
         {
                         x=0x90;
         }
         else if (x==2)
         {
                        x=0x88;
         }
         else if (x==3)
         {
                        x=0x98;
         }
         Position = x + y;
                                                                               
         LCDWiteCommand(Position);
}

void LCDInit(void)
{
         LCDWiteCommand(0x30);
         Delay_MS(50);
         LCDWiteCommand(0x0c);
         Delay_MS(50);
         LCDWiteCommand(0x01);  
         Delay_MS(50);
         LCDWiteCommand(0x06);
         Delay_MS(50);
}
void LCDDisplay(u8 x, u8 y, u8 *Data)
{
         LCDCursorPosition(x,y);
         Delay_MS(50);
        while(*Data != '\0')
{
                        LCDWriteData(*Data);
                        Data++;
                        Delay_MS(5);
}
}
沙发
fanxsd| | 2015-7-20 22:16 | 只看该作者
什么问题呢 只有代码?

使用特权

评论回复
板凳
renchouduodushu|  楼主 | 2015-7-20 22:20 | 只看该作者
上面的程序太乱了,看下面这个程序
跪求大神们帮我看一下,老是显示不出来字符!已经调了两天了累觉不爱了要!
#include"stm32f10x_lib.h"
#include<stdio.h>
void Delay_MS(u16 dly)
{
        u16 i,j;
        for(i=0;i<dly;i++)
                for(j=1000;j>0;j--);
}

void RCC_Configuration(void);
void GPIO_Configuration(void);
void LCDDisplay(u8 x, u8 y, u8 *Data);
void LCDInit(void);
void LCDCursorPosition(u8 x, u8 y);
void LCDWriteData(u8 Data);
void LCDWiteCommand(u8 Command);
int main(void)
{        
                RCC_Configuration();
                GPIO_Configuration();
                GPIO_SetBits(GPIOB, GPIO_Pin_11);
                  LCDInit();
                 while (1)
  {

                        LCDDisplay(0, 1, "ASD");
                        LCDDisplay(1, 2, "ASD");
                        LCDDisplay(2, 0, "¸DF");
                        LCDDisplay(3, 2, "CXV");
      
        }
}

void RCC_Configuration(void)
{
        //----------ʹÓÃÍⲿRC¾§Õñ-----------
        RCC_DeInit();                        //³õʼ»¯ÎªÈ±Ê¡Öµ
        RCC_HSEConfig(RCC_HSE_ON);        //ʹÄÜÍⲿµÄ¸ßËÙʱÖÓ
        while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);        //µÈ´ýÍⲿ¸ßËÙʱÖÓʹÄܾÍÐ÷
        
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);        //Enable Prefetch Buffer
        FLASH_SetLatency(FLASH_Latency_2);                //Flash 2 wait state
        
        RCC_HCLKConfig(RCC_SYSCLK_Div1);                //HCLK = SYSCLK
        RCC_PCLK2Config(RCC_HCLK_Div1);                        //PCLK2 =  HCLK
        RCC_PCLK1Config(RCC_HCLK_Div2);                        //PCLK1 = HCLK/2
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);        //PLLCLK = 8MHZ * 9 =72MHZ
        RCC_PLLCmd(ENABLE);                        //Enable PLLCLK

        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);        //Wait till PLLCLK is ready
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);        //Select PLL as system clock
        while(RCC_GetSYSCLKSource()!=0x08);                //Wait till PLL is used as system clock source
        
        
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB,ENABLE );
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO ,ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
}


void GPIO_Configuration(void)
{
        
        GPIO_InitTypeDef        GPIO_InitStructure;        


        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;//指令和数据输出管脚
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;        
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;
        GPIO_Init(GPIOA,&GPIO_InitStructure);                                
        
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//指令和数据管脚
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;        
        GPIO_Init(GPIOB,&GPIO_InitStructure);                                
                                                
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//读写管脚
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;        
        GPIO_Init(GPIOB,&GPIO_InitStructure);                                
                                                                                                                                                                                       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//使能管脚
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;        
        GPIO_Init(GPIOB,&GPIO_InitStructure);                                
                                                                                                                                                                                       
        
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//用于12864的串并控制接12864的15脚
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP  ;         
        GPIO_Init(GPIOB,&GPIO_InitStructure);                                 
                                                                                                                                                                                
        

        
}
void LCDWiteCommand(u8 Command)
{
         u8 LCDTemp = 0;
         GPIO_ResetBits(GPIOB,GPIO_Pin_8);
         GPIO_ResetBits(GPIOB,GPIO_Pin_9);
         GPIO_SetBits(GPIOB,GPIO_Pin_10);
         Delay_MS(10);
         LCDTemp = LCDTemp | Command;
         GPIO_Write(GPIOA, LCDTemp);
         Delay_MS(10);
         GPIO_ResetBits(GPIOB,GPIO_Pin_10);
         Delay_MS(10);
}
void LCDWriteData(u8 Data)
{
         u8 LCDTemp = 0;
         GPIO_SetBits(GPIOB,GPIO_Pin_8);
         GPIO_ResetBits(GPIOB,GPIO_Pin_9);
         GPIO_SetBits(GPIOB,GPIO_Pin_10);
         Delay_MS(10);
         LCDTemp = LCDTemp | Data;
         GPIO_Write(GPIOA, LCDTemp);
         Delay_MS(10);
         GPIO_ResetBits(GPIOB,GPIO_Pin_10);
         Delay_MS(10);  
}

void LCDCursorPosition(u8 x, u8 y)
{
         u8 Position;
         if (x==0)
         {
                        x=0x80;
         }
         else if (x==1)
         {
                         x=0x90;
         }
         else if (x==2)
         {
                        x=0x88;
         }
         else if (x==3)
         {
                        x=0x98;
         }
         Position = x + y;
                                                                                
         LCDWiteCommand(Position);
}

void LCDInit(void)
{
         LCDWiteCommand(0x30);
         Delay_MS(50);
         LCDWiteCommand(0x0c);
         Delay_MS(50);
         LCDWiteCommand(0x01);  
         Delay_MS(50);
         LCDWiteCommand(0x06);
         Delay_MS(50);
}
void LCDDisplay(u8 x, u8 y, u8 *Data)
{
         LCDCursorPosition(x,y);
         Delay_MS(50);
        while(*Data != '\0')
{
                        LCDWriteData(*Data);
                        Data++;
                        Delay_MS(5);
}
}

使用特权

评论回复
地板
airwill| | 2015-7-21 08:08 | 只看该作者
又来一个请人改代码的新人.
虽然很多网友们比较有经验, 但是没有板子和液晶屏, 问题基本只能靠猜, 比你有板子有屏有调试器条件差太多. 所以还是楼主自己请调试器帮忙吧.
顺便给你推荐一份本坛高人撰写的初学者学习调试的很棒的教材.程序调试黑宝书
https://bbs.21ic.com/forum.php?mo ... 1%E5%AE%9D%E4%B9%A6
加油

使用特权

评论回复
5
643757107| | 2015-7-22 21:23 | 只看该作者
又来一个请人改代码的新人.

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

2

帖子

0

粉丝