首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于HD44780的LCD与基于P89LPC9351的微控制器的接口问题

基于HD44780的LCD与基于P89LPC9351的微控制器的接口问题
EN

Stack Overflow用户
提问于 2011-03-26 09:02:14
回答 1查看 1.1K关注 0票数 1

我无法让我的液晶显示器初始化,我是不是做错了什么?感谢任何人的帮助!

代码语言:javascript
复制
    #include <stdio.h>
    #include <stdlib.h>
    #include <p89lpc9351.h>

    #define XTAL 7373000L
    #define BAUD 115600L

    #define LCD_data P2
    #define LCD_rs   P1_4
    #define LCD_rw   P1_6
    #define LCD_en   P1_7

    void putchar (char c)
    {
        while (!TI);
        TI=0;

        SBUF=c;
    }

    char getchar (void)
    {
        while (!RI);
        RI=0;
        return SBUF;
    }

    void InitSerialPort(void)
    {
        BRGCON=0x00;                    //Make sure the baud rate generator is off
        BRGR1=((XTAL/BAUD)-16)/0x100;
        BRGR0=((XTAL/BAUD)-16)%0x100;
        BRGCON=0x03;                    //Turn-on the baud rate generator
        SCON=0x52;                      //Serial port in mode 1, ren, txrdy, rxempty
        P1M1=0x00;                      //Enable pins RxD and Txd
        P1M2=0x00;                      //Enable pins RxD and Txd
    }

    void delay_ms(long ms)
    {
        long i;

        while (ms--)
            for (i=0; i < 330; i++)
                ;
    }

    void command(char i)
    {
        LCD_data = i;                   //put data on output Port
        LCD_rs =0;                      //D/I=LOW : send instruction
        LCD_rw =0;                      //R/W=LOW : Write
        LCD_en = 1;
        delay_ms(1);                    //enable pulse width >= 300ns
        LCD_en = 0;
    }

    void write(char i)
    {
        LCD_data = i;                   //put data on output Port
        LCD_rs =1;                      //D/I=LOW : send data
        LCD_rw =0;                      //R/W=LOW : Write
        LCD_en = 1;
        delay_ms(1);                    //enable pulse width >= 300ns
        LCD_en = 0;                     //Clock enable: falling edge
    }

    void LCD_init()
    {
        LCD_en  = 0;
        delay_ms(100);                  //Wait >15 msec after power is applied
        command(0x30);                  //command 0x30 = Wake up
        delay_ms(30);                   //must wait 5ms, busy flag not available
        command(0x30);                  //command 0x30 = Wake up #2
        delay_ms(10);                   //must wait 160us, busy flag not available
        command(0x30);                  //command 0x30 = Wake up #3
        delay_ms(10);                   //must wait 160us, busy flag not available
        command(0x38);                  //Function set: 8-bit/2-line
        command(0x10);                  //Set cursor
        command(0x0c);                  //Display ON; Cursor ON
        command(0x06);                  //Entry mode set 
    }

    void main (void)
    {
        InitSerialPort();
        LCD_init();
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-26 09:07:47

初始化序列看起来没问题。您是否忘记显式地将P2和P1引脚设置为输出?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5439662

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档