我正在尝试连接 16*2 LCD 和 tm4c123gxl,但它不起作用

问题描述 投票:0回答:0

我尝试将 tm4c123gxl 微控制器与 16*2 LCD 连接以打印一些字母。但是由于某种原因,我的液晶显示器不工作,只在第一行显示黑框。

enter image description here 如您所见,我使用 PORT A 的 3 针连接 RS、R/W、EN。并且我使用了PORT B的所有8个引脚来连接LCD(数据)的7~14个引脚。

这是我在 CCS 上写的代码

//rcgcgpio
#define RCGCGPIO (*((volatile unsigned long *) 0x400FE608))

//LCD
//PORTA 2,3,4
#define GPIODEN_PORTA (*((volatile unsigned long *) 0x4000451C))
#define GPIODIR_PORTA (*((volatile unsigned long *) 0x40004400))
#define GPIODATA_PORTA (*((volatile unsigned long*) 0x40004070))//1110000

//PORTB 0,1,2,3,4,5,6,7
#define GPIODEN_PORTB (*((volatile unsigned long *) 0x4000551C))
#define GPIODIR_PORTB (*((volatile unsigned long *) 0x40005400))
#define GPIODATA_PORTB (*((volatile unsigned long *) 0x400053FC))//11111111

//instruction, put this into portB
#define LCD_clear_display 0x1
#define LCD_return_home 0x2
#define LCD_display_shift_right 0x5
#define LCD_cursor_line1_position0 0x80


void LCD_setup();
void LCD_write_IR(unsigned char inst);
void LCD_write_DR(unsigned char data);
void Keypad_setup();
char Keypad_read();
void Delay(unsigned int t);

/**
 * main.c
 */
int main(void)
{
    LCD_setup();
    LCD_write_IR(LCD_cursor_line1_position0);
    LCD_write_IR(LCD_clear_display);
    while(1){
    LCD_write_DR('A');
    }
}

void LCD_setup(){
    RCGCGPIO |= 0x3;//000011 Port A and Port B
    GPIODEN_PORTA |= 0x1C;//11100
    GPIODIR_PORTA |= 0x1C;//11100
    GPIODEN_PORTB |= 0xFF;//11111111
    GPIODIR_PORTB |= 0xFF;//11111111
}

void Delay(unsigned int t){//ms delay
    int i;
    int j;
    for(i=0;i<t;i++){
        for(j=0;j<16000;++j){
        }
    }
}

void LCD_write_IR(unsigned char inst){
    GPIODATA_PORTA = 0x10;//EN:1, R/W:0, RS:0, 0, 0
    GPIODATA_PORTB = inst;
    Delay(2);

    /*
    if(inst < 4){//clear display
        Delay(2);
    }else{
        Delay(1)//entry mode set
    }
    */
}

void LCD_write_DR(unsigned char data){
    GPIODATA_PORTA = 0x14;//10100
    GPIODATA_PORTB = data;
    Delay(2);

}

不幸的是,LCD 并没有像这张图片那样工作 enter image description here

我应该怎么做才能在LCD上打印一些字母?

c embedded microcontroller
© www.soinside.com 2019 - 2024. All rights reserved.