【问题标题】:init codes not working on sitronix' st7920 LCD12864B初始化代码不适用于 sitronix\' st7920 LCD12864B
【发布时间】:2022-12-14 18:27:33
【问题描述】:

在学习如何从 PIC16F84A 控制 LCD 12864B 时,我在初始化代码中发现了一个意想不到的行为。我最好在提交的代码中的评论中解释问题。 希望有人能给个明确的答复。 这是我的 LCD.c 文件:

`#include "Includes.h"`


void ToggleEpinOfLCD(void)
{
    LCD_E = 1;                // Give a pulse on E pin
    __delay_us(E_Delay);      // so that LCD can latch the
    LCD_E = 0;                // data from data bus
    __delay_us(E_Delay);    
}


void WriteCommandToLCD(unsigned char Command)  
{
    LCD_RS = 0;               // It is a command

    PORTB &= 0xF0;            // Make Data pins zero
    PORTB |= ((Command>>4)&0x0F); // Write Upper nibble of data
    ToggleEpinOfLCD();        // Give pulse on E pin    

    PORTB &= 0xF0;            // Make Data pins zero
    PORTB |= (Command&0x0F); // Write Lower nibble of data
    ToggleEpinOfLCD();        // Give pulse on E pin
}

void WriteDataToLCD(char LCDChar)  
{
    LCD_RS = 1;               // It is data
    PORTB &= 0xF0;            // Make Data pins zero
    PORTB |= ((LCDChar>>4)&0x0F);  // Write Upper nibble of data
    ToggleEpinOfLCD();        // Give pulse on E pin    

    PORTB &= 0xF0;            // Make Data pins zero
    PORTB |= (LCDChar&0x0F); // Write Lower nibble of data
    ToggleEpinOfLCD();        // Give pulse on E pin
}


void InitLCD(void)
{ 
    // Firstly make all pins output
    LCD_E                = 0;   // E  = 0
    LCD_RS               = 0;   // RS = 0
    LCD_Data_Bus_D0      = 0;   // Data bus = 0
    LCD_Data_Bus_D1      = 0;   // Data bus = 0
    LCD_Data_Bus_D2      = 0;   // Data bus = 0
    LCD_Data_Bus_D3      = 0;   // Data bus = 0
    LCD_E_Dir            = 0;   // Make Output
    LCD_RS_Dir           = 0;   // Make Output
    LCD_Data_Bus_Dir_D0  = 0;   // Make Output
    LCD_Data_Bus_Dir_D1  = 0;   // Make Output
    LCD_Data_Bus_Dir_D2  = 0;   // Make Output
    LCD_Data_Bus_Dir_D3  = 0;   // Make Output

    ///////////////// Reset process //////////////

// On page 29 of the Sitronix' ST7920 datasheet, the display init procedure for 4 bits communication is the following:
//      Wait 40 ms after power on
// labels here  RS  R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0     HEX
// function set  0   0   0   0   1   0   X   X   X   X      20
//      Wait > 100 us
// function set  0   0   0   0   1   0   X   X   X   X      20
//               0   0   X   0   X   X   X   X   X   X      00
// this to me sounds correct, as 20h it's the code that sets the display on 4-bit mode
// but this doesn't work... WHY??
// Other people at this point suggest to send a 0x03 twice and then a 0x02, separated by a 500 us delay
// but I found it suffices to send a single 0x02 as below.
// Can someone please explain this, mainly as the official sitronix codes are involved?
__delay_ms(40);

    WriteCommandToLCD(0x02); //select DDRAM, cursor move to dx address counter +1

    /////////////////// Reset process end //////////


    WriteCommandToLCD(0x20);    //function set 4 bits mode
    WriteCommandToLCD(0x0c);    //display on,cursor off,blink off
    WriteCommandToLCD(0x01);    //clear display
    __delay_ms(2);  // 
    WriteCommandToLCD(0x06);    //entry mode, set increment
}



void ClearLCDScreen(void)       // Clear the Screen and return cursor to zero position
{
    WriteCommandToLCD(0x01);    // Clear the screen
    __delay_ms(2);              // Delay for cursor to return at zero position
}

为了完整起见,我添加了示意图。 身体健康!

【问题讨论】:

    标签: lcd


    【解决方案1】:

    我正在尝试使用与您相同的显示器,但我无法运行它。你让它运行了吗?谢谢

    【讨论】:

    猜你喜欢
    • 2021-12-06
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 2015-01-04
    • 2015-11-12
    • 2015-03-26
    • 2015-11-22
    相关资源
    最近更新 更多