2011-03-26 2 views
1

LCD 초기화를 관리 할 수 ​​없습니다. 잘못된 것이 있습니까? 어떤 도움을 주셔서 감사합니다!hd44780 기반 LCD와 P89LPC9351 기반 마이크로 컨트롤러의 인터페이스 문제

#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(); 
    } 
+0

http://electronics.stackexchange.com/에서 더 많은 하드웨어 지향 포크가 있기 때문에이 질문을 시도해보십시오. 나는 이것이 여기에 주제 밖의 질문이라고 생각하지 않는다. – RBerteig

답변

2

초기화 시퀀스가 ​​정상적으로 보입니다. P2 및 P1 핀을 출력으로 명시 적으로 설정하는 것을 잊었습니까?

+0

나는 너를 아주 잘한다. – Oniros

관련 문제