微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > stm32控制240128液晶没有显示

stm32控制240128液晶没有显示

时间:10-02 整理:3721RD 点击:
我最近在用stm32驱动240128液晶,搞了几天了,一直没反应,有会的,或者搞过类型的请帮我解决一下。液晶是直接5V供电,我是用四线串行时序,信号线直接和探索者开发板的GPIO口相连。下面是我的程序,望帮小弟解决一下。
/******************************************************************
2aê?LCD240128òo?§?y?ˉí·???t
******************************************************************/
#ifndef __LCD240128_H__
#define __LCD240128_H__
#include "sys.h"
#include "delay.h"
/********************************************
LCD1ü???¨ò?
********************************************/
//#define  LCD240128_CS  PAout(12)
//#define  LCD240128_RST PAout(13)
//#define  LCD240128_RS  PAout(14)
//#define  LCD240128_SCL PAout(15)
//#define  LCD240128_SDA PBout(15)

//#define  LCD240128_CS  PDout(14)
//#define  LCD240128_RST PDout(11)
//#define  LCD240128_RS  PDout(15)
//#define  LCD240128_SCL PEout(8)
//#define  LCD240128_SDA PEout(9)
#define  LCD240128_CS_L    GPIO_ResetBits(GPIOD, GPIO_Pin_14)
#define  LCD240128_CS_H    GPIO_SetBits(GPIOD, GPIO_Pin_14)
#define  LCD240128_RST_L   GPIO_ResetBits(GPIOD, GPIO_Pin_11)
#define  LCD240128_RST_H   GPIO_SetBits(GPIOD, GPIO_Pin_11)
#define  LCD240128_RS_L    GPIO_ResetBits(GPIOD, GPIO_Pin_15)
#define  LCD240128_RS_H    GPIO_SetBits(GPIOD, GPIO_Pin_15)
#define  LCD240128_SCL_L   GPIO_ResetBits(GPIOE, GPIO_Pin_8)
#define  LCD240128_SCL_H   GPIO_SetBits(GPIOE, GPIO_Pin_8)
#define  LCD240128_SDA_L   GPIO_ResetBits(GPIOE, GPIO_Pin_9)
#define  LCD240128_SDA_H   GPIO_SetBits(GPIOE, GPIO_Pin_9)

#define DIS_ON  0X3D
#define DIS_OFF        0X3C
#define REST    0X76

#define LCD240128_ClrAll    128
#define LCD240128_Direction 0 //??è??é????ê?oá?á??ê?
/*********************************************
LCD?à1?oˉêy?¨ò?
**********************************************/
void LCD240128_WriteCommand(u8 Command);
void LCD240128_WriteData(u8 Sdata);
void LCD240128_ClearDisplay(u8 page);
void LCD240128_Draw(u8 line,u8 list,u8 pw,u8 ph,u8 *Draw,u8 fbit);
void DrawPicture(u8 line,u8 list,const u8 *Sk,u8 fbit);
void LCD240128_Init(void);
void SetXY(u8 x, u8 y);
void ShowString(u8 x, u8 y, u8* str);
#endif
#include "lcd240128.h"
/*******************************************************************************************
* oˉêy?èê?£o·¢?í??á?oˉêy£??????è?í
* è???×ê?′£o
* ê?è?2?êy£o°?????á???
* oˉêy·μ??£o?T
*******************************************************************************************/
void LCD240128_WriteCommand(u8 Command)
{
   
    u8 i;
    LCD240128_CS_L;
          delay_ms(5);
    LCD240128_RS_L;
          delay_ms(5);
    for(i = 0; i < 8; i++)
    {
        LCD240128_SCL_L;
        if(Command & 0x80) { LCD240128_SDA_H; }
        else { LCD240128_SDA_L; }
                                delay_ms(5);
        LCD240128_SCL_H;
        Command <<= 1;
    }
                delay_ms(5);
    LCD240128_CS_H;
    delay_ms(5);
}
/*******************************************************************************************
* oˉêy?èê?£o·¢?íêy?Yoˉêy£??????è?í
* è???×ê?′£o
* ê?è?2?êy£o°???êy?Y
* oˉêy·μ??£o?T
*******************************************************************************************/
void LCD240128_WriteData(u8 Sdata)
{
    u8 i;
    LCD240128_CS_L;
          delay_ms(5);
    LCD240128_RS_H;
          delay_ms(5);
    for(i = 0; i < 8; i++)
    {
        LCD240128_SCL_L;
        if(Sdata & 0x80) {LCD240128_SDA_H;}
        else {LCD240128_SDA_L;}
        delay_ms(5);
        LCD240128_SCL_H;
        Sdata <<= 1;
    }
                delay_ms(5);
    LCD240128_CS_H;
                delay_ms(5);
}
/*****************************************************************************************
??ê?×?·?′?
*****************************************************************************************/
void SetXY(u8 x, u8 y)
{  
   LCD240128_WriteCommand(0X01);
         LCD240128_WriteCommand(x);
         LCD240128_WriteCommand(0xC0);
         LCD240128_WriteCommand(y);
         
}
/********************************************************************************************
??ê?×?·?′?
*********************************************************************************************/
void ShowString(u8 x, u8 y, u8* str)
{
   SetXY(x, y);
         while(*str!='\0')
         {
                  LCD240128_WriteData(*str++);
         }
}
/*******************************************************************************************
* oˉêy?èê?£o????ê?£?°′ò3??3y?£è?1?ê?è?ò3êy′óóú7£¨LCD240128_ClrAll£?£????á??3y
* è???×ê?′£o
* ê?è?2?êy£oò3£?page?££¨LCD240128_ClrAll£?
* oˉêy·μ??£o
*******************************************************************************************/
void LCD240128_ClearDisplay(u8 page)
{
    u8 i;
    u8 j;
    if(page > LCD240128_ClrAll - 1)
    {
        //???á
        for(i = 0; i < LCD240128_ClrAll; i++)
        {
            LCD240128_WriteCommand(0X01);                         //éè??òaD′è?μ?ò3μ??·
            LCD240128_WriteCommand(i);                                //ò3μ??·D′è?
            LCD240128_WriteCommand(0XC0);                         //éè??òaD′è?μ?áDμ??·
            LCD240128_WriteCommand(0);                                //áDμ??·D′è?
            for(j = 0; j < 32; j++)
            {
                LCD240128_WriteData(0x00);                //???á
            }
        }
    }
    else{        //?????¨ò3
        LCD240128_WriteCommand(0X01);                         //éè??òaD′è?μ?ò3μ??·
        LCD240128_WriteCommand(page);                        //ò3μ??·D′è?
        LCD240128_WriteCommand(0XC0);                         //éè??òaD′è?μ?áDμ??·
        LCD240128_WriteCommand(0);                                //áDμ??·D′è?
        for(j = 0; j < 32; j++)
        {
            LCD240128_WriteData(0x00);                        //???á
        }
    }
}
/*******************************************************************************************
* oˉêy?èê?£o?ú???¨??????ê?í?±ê?¢×??£
                        í?±ê?úoá?áê±?í±?D?ê?8μ???êy£??á?áê±??±?D?ê?8μ???êy?£
* è???×ê?′£o??
* ê?è?2?êy£ooá×?±ê£?×Y×?±ê£?í?±ê?í£?í?±ê??£?í?±ê????£?·′??±ê?????£
* oˉêy·μ??£o?T
*******************************************************************************************/
void DrawPicture(u8 line,u8 list,const u8 *Sk,u8 fbit)
{
        u8 i,j;
        u8 skdata;

        for(i=0;i<128;i++)         //í??????è
        {
                LCD240128_WriteCommand(0X01);                         //éè??òa??ê?μ?DDμ??·
                LCD240128_WriteCommand(line+i);                        //μ??·D′è?
                LCD240128_WriteCommand(0XC0);                         //éè??òa??ê?μ?áDμ??·
                LCD240128_WriteCommand(list);                                //μ??·D′è?
                for(j=0;j<30;j++)                                //í????í?è=240/8
                {
                        skdata=*(Sk+j+i*30);
                        if(fbit)                                         //è?1?·′?????a1£?·′??êy?Y
                        {
                                skdata=~skdata;
                        }
                        LCD240128_WriteData(skdata);                                               
                }                       
        }
}
/**************************************************************************************
?-μ?oˉêy
**************************************************************************************/
void LCD240128_Draw(u8 line,u8 list,u8 pw,u8 ph,u8 *Draw,u8 fbit)
{
    u8 i, j;
    u8 lie, page;
    u8 plie, ppage;
    switch(LCD240128_Direction)
    {
        case 0://oá?á
            plie = pw / 8;
            ppage = ph;
            lie = line / 8 + 2;
            page = list + 1;
            break;
        case 1://?á?á
            plie = ph / 8;
            ppage = pw;
            lie = list / 8 + 2;
            page = line + 1;
            break;
        case 2:
            break;
        case 3:
            break;
    }
    for(i = 0; i < ppage; i++)                                //í???ò3êy£¨í?±ê?úoá?áê±??±?D?ê?8μ???êy£??á?áê±?í±?D?ê?8μ???êy£?
    {
        LCD240128_WriteCommand(0X01);                         //éè??òaD′è?μ?ò3μ??·
        LCD240128_WriteCommand(page + i);                        //ò3μ??·D′è?
        LCD240128_WriteCommand(0XC0);                         //éè??òaD′è?μ?áDμ??·
        LCD240128_WriteCommand(lie);                                //áDμ??·D′è?
        for(j = 0; j < plie; j++)
        {
            if(fbit)
            {
                LCD240128_WriteData(~(*Draw));
            }
            else
            {
                LCD240128_WriteData(*Draw);
            }
            Draw++;
        }
    }
}
/*******************************************************************************************
* oˉêy?èê?£oòo?§?á3?ê??ˉoˉêy
* è???×ê?′£o
* ê?è?2?êy£o
* oˉêy·μ??£o
*******************************************************************************************/
void LCD240128_Init(void)
{
          //3?ê??ˉLCDμ??÷??IO?ú
    GPIO_InitTypeDef  GPIO_InitStruct;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE, ENABLE);       
          GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_14|GPIO_Pin_15; //
          GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
          GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_Init(GPIOD, &GPIO_InitStruct);
          GPIO_SetBits(GPIOD, GPIO_Pin_11|GPIO_Pin_14|GPIO_Pin_15);
       
          GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;//
          GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
          GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_Init(GPIOE, &GPIO_InitStruct);
          GPIO_SetBits(GPIOE, GPIO_Pin_8|GPIO_Pin_9);
          
    LCD240128_RST_L;
    delay_ms(50);
    LCD240128_RST_H;
    delay_ms(20);
       
    delay_ms(20);
    LCD240128_WriteCommand(REST);
    delay_ms(30);

    LCD240128_WriteCommand(0X2F);        //μ??′????0 0 0 0 1 0 1 VS VC VF
    LCD240128_WriteCommand(0X3A);        //0 0 1 1 1 0 1 OSCOFF
    LCD240128_WriteCommand(0X35);        //LCD???10 0 1 1 0 BS2 BS1 BS0    30=1/7, 31=1/8, 32=1/9, 33=1/10, 34=1/11, 35=1/12, 36=1/13, 37=1/14
    LCD240128_WriteCommand(0X38);        //SLEEP  0 0 1 1 1 0 0 SLP

    LCD240128_WriteCommand(0X44);        //GRAY CONTROL 44H=MONO  45H=4GRAY áá?è??±e
    LCD240128_WriteCommand(0X6C); //??ê??y?ˉ????£?°ü਷??ò£?è??á£?·′??£?

    LCD240128_WriteCommand(0X74); //éè??êó′°μ?′1?±??ê?·??§.?ù?Y?áμ????????¨
    LCD240128_WriteCommand(0X00);        //?aê?μ??·
    LCD240128_WriteCommand(0X7F);        //?áê?μ??·Y=128

    LCD240128_WriteCommand(0X75); //éè??êó′°μ???????ê?·??§.?ù?Y?áμ????????¨
    LCD240128_WriteCommand(0X00);        //?aê?μ??·
    LCD240128_WriteCommand(0XEF);        //?áê?μ??·x=240

    LCD240128_WriteCommand(0X90);        //éè??DUTY COM×üêy
    LCD240128_WriteCommand(0X80);        //128

    LCD240128_WriteCommand(0XB1);        //éè??±??1?μ£?í¨1y′??μ?éò?μ÷????±è?è
    LCD240128_WriteCommand(0X58);        //D′è?

    LCD240128_WriteCommand(0XB2);        //Frame????£?éè????ê??¢D??μ?ê
    LCD240128_WriteCommand(0X3C);        //
    LCD240128_WriteCommand(0X01);

    LCD240128_WriteCommand(0XE1); //???è213¥?a

    LCD240128_WriteCommand(0X88);
    LCD240128_WriteCommand(0X88);
    LCD240128_WriteCommand(0X88);
    LCD240128_WriteCommand(0X88);
    LCD240128_WriteCommand(0X8A);
    LCD240128_WriteCommand(0X60);
    LCD240128_WriteCommand(0x41);                //?à???óò???èyì???á?
    LCD240128_WriteCommand(0x19);                //
    LCD240128_WriteCommand(0x2F);                //
    LCD240128_WriteCommand(0XE3); //??2ù×÷??á?
    LCD240128_WriteCommand(0X00);
    LCD240128_WriteCommand(0X7F);
    LCD240128_WriteCommand(0X75);
    LCD240128_WriteCommand(0X02);
    LCD240128_WriteCommand(0X1F);

    LCD240128_WriteCommand(0XC0); //éè??òa??ê?μ?ê×áDμ??·
    LCD240128_WriteCommand(0X02);        //μ??·D′è?

    LCD240128_WriteCommand(0X01); //éè??òa??ê?μ?ê×DDμ??·
    LCD240128_WriteCommand(0X00);        //μ??·D′è?
    delay_ms(50);

    //        LCD_CmdWrite(0xE3);

    LCD240128_WriteCommand(DIS_ON);//?a??ê?
    delay_ms(50);

}
#include "lcd240128.h"
#include "lcd240128font.h"
/************************************************
************************************************/
u8 str1[]= "baofeng";

int main(void)
{       
  delay_init();
        LCD240128_Init();
        //LCD240128_ClearDisplay(LCD240128_ClrAll);
        //DrawPicture(0, 2, logo, 1);
        ShowString(5,0,str1);
  while(1);
}
#ifndef __LCD240128FONT_H__
#define __LCD240128FONT_H__
#include "sys.h"
const u8 logo[]={
0x01,0x02,0x10,0x00,0x7D,0x01,0x67,0x80,0x05,0xF0,0x44,0x80,0x46,0x10,0x44,0x80,
0x2C,0x23,0x44,0x80,0x28,0x81,0x44,0x80,0x10,0x81,0x54,0x80,0x10,0x81,0x64,0x80,
0x29,0x41,0x45,0x80,0x29,0x41,0x04,0x00,0x42,0x21,0x04,0x00,0x04,0x12,0xFF,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
#endif


先确定屏是好的,然后再用示波器看你写的单片机的代码控制的IO是不是正常的输出的,一步一步找错。

屏是好的  这点无疑的  在其他51单片机上试过了是好的,我抓了时序,好像有点问题,我也不确定是不是stm32主频太高了,还是硬件有点问题。搞了几天了   还是不行,很奇怪

你觉得主频高就试试降低数据的速率,看看效果会不会好些,有些点阵屏的某些指令需要有严格的时序要求,详细的看看数据手册,做对应的调整。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top