This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TM4C123GH6PM:8位模式下具有 LCD 16x2的 Tiva C launchpad

Guru**** 2032800 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/675235/tm4c123gh6pm-tiva-c-launchpad-with-lcd-16x2-in-8-bits-mode

器件型号:TM4C123GH6PM

大家好、我已经花了2周时间进行三次测试、以8位模式将我的 launchpad 连接到 LCD 16x2 (我也尝试了4位、但我认为在8位模式下应该更容易)、 我迷路了,我尝试改变一切,再次,阅读有关这方面的论坛,找不到任何解决方案:/

连接
D0-D7 --> B0-B7

E --> D0

RS --> D1

RW-->GND

我连接了对比度,因此我可以调节它。


我的代码(有一些与其他内容无关的内容):

#define target_in_blizzard_RA1
#include
#include "stdlib.h"
#include
//#include "inc/hw_ca.h"
//#include "inc/hw_ints.h"
//#include "driverlib/fpu.h"
//#include "driverlib/CAN.h"
//#include "grlib/grlib.h"
//#include "drivers/cfal96x64x16.h"
//#include "utils/uartstdio.h"
//#include "driverlib/interrupt.h"

//#define target_is_blizzard_RA1
#include
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
//#include "driverlib/rom.h"
//#include "driverlib/uart.h"
//#include "driverlib/adc.h"
//#include "utils/uartstdio.h"
//#include "driverlib/pin_map.h"
//#include //se utiliza para imprimir los valores uint32_t


#include "math.h"


//
//
//驱动程序库遇到错误时调用的错误例程。
//
//
#ifdef 调试
无效
_error__(char * pcFilename、uint32_t ui32Line)


#endif
//declarations

#define LCD_DATA GPIO_PORTB_BASE //LCD 数据端口至 PORTb
#define CTRL Porte //LCD 控制端口连接到 Porte
#define RS GPIO_PIN_1 //寄存器选择信号到 RE0

#define EN GPIO_PIN_2 //将信号发送到 RE2

//函数原型
void init_lcd (void);//函数初始化 LCD
void lcd_command (unsigned char cmd);//function to pass command to the LCD
void lcd_data (unsigned char data);//函数将字符写入 LCD
void lcd_write_string (char *str);//function to write string to the LCD
void msdelay (unsigned int time);//函数生成延迟


// Puertos 定义
#define perifericoData SYSCTL_Periph_GPIOB
#define writeData GPIO_PORTB_BASE
#define B0 GPIO_PIN_0
#define B1 GPIO_PIN_1
#define B2 GPIO_PIN_2
#define B3 GPIO_PIN_3
#define B4 GPIO_PIN_4
#define B5 GPIO_PIN_5
#define B6 GPIO_PIN_6
#define B7 GPIO_PIN_7
#define 数据引脚 B0|B1|B2|B3|B4|B5|B6|B7

#define perifericoControl SYSCTL_Periph_GPIOD
#define writeControl GPIO_PORTD_base
#define E GPIO_PIN_0
#define RS GPIO_PIN_1
#define controlPins E|RS

#define perifericoLed SYSCTL_Periph_GPIOF
#define writeLed GPIO_PORTF_BASE
#define LED1 GPIO_PIN_1
#define LED2 GPIO_PIN_2
#define LED3 GPIO_PIN_3
#define LED LED3|LED2|LED1
#define Cian 0x0C
#define azul 0x04
#define rojo 0x02
#define Verde 0x08
#define off 0x00


int delayms (int tiempo){
int resultado = 1000 *(tiempo /(0.0000625*1000));
返回结果 ado;

int delayus (int tiempo){
int resultado = 1000 *(tiempo /(0.0625*1000));
返回结果 ado;

//Start of Main Program
int main (空)

char var1[]="i";//declare message to be displayed

/*将时钟设置为以16MHz*/直接从晶体运行
SysCtlClockSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHz | SYSCTL_OSC_MAIN);

/*设置 GPIO 端口 B y D 的时钟*/
SysCtlPeripheralEnable (perifericoControl);
SysCtlPeripheralEnable (perifericoData);
SysCtlPeripheralEnable (perifericoLed);
/*设置 GPIO 引脚的类型*/
SysCtlDelay (8000000);

GPIOPinTypeGPIOOutput (GPIO_PORTB_BASE、B0|B1|B2|B3|B4|B5|B6|B7);
GPIOPinTypeGPIOOutput (GPIO_PORTD_BASE、E|RS);
GPIOPinTypeGPIOOutput (GPIO_PORTF_BASE、LED3|LED2|LED1);
SysCtlDelay (8000000);


init_lcd();//调用函数来初始化 LCD
SysCtlDelay (8000000);


/*
LCD_COMMAND (0xC0);//将光标初始化到第二行0b1100 0000
LCD_WRITE_string (var2);//在第二行显示消息
*
while (1){//此处循环
LCD_WRITE_string (var1);//在第一行显示消息
GPIOPinWrite (writeLed、LED3|LED2|LED1、azul);//LED Azul

SysCtlDelay (delayms (1000));
GPIOPinWrite (writeLed、LED3|LED2|LED1、off);//LED Azul

}//主页末尾

//函数定义
void msdelay (unsigned int time)//函数生成延迟

unsigned int i、j;
对于(I = 0;I <时间;I++)
对于(j = 0;j < 275;j++);//在 MPLAB 中针对1ms 的延迟进行校准

void init_LCD (void)//函数用于初始化 LCD

//16MHz -- 62.5ns
SysCtlDelay (8000000);// 550000 ciclos
GPIOPinWrite (writeControl、RS | E、0x00);//COLOCO RS Y E en 0 POR las dudas Rs = 0 para instructiones E = 1 cuando se comienza a escribir

//清除显示0b 0 0 0 0 0 0 0 0 1
//返回主页0b 0 0 0 0 0 0 0 1 x
//进入模式设置0b 0 0 0 0 0 1 I/D S I/D = 1 mueve el Cursor A la derecha S = 1 mueve el display
//显示开/关0b 0 0 0 1 D C B D 显示 C 光标 B 闪烁
//光标或显示位移0b 0 0 1 S/C R/L x S/C = 0 mueve Cursor R/L = 1 derecha
//函数设置0b 0 1 DL N F x DL = 1 - 8位模式 N = 1 - 2行显示 F = 1 - 5x11点

//首先  

GPIOPinWrite (writeLed、LEDs、rojo);
LCD_COMMAND (0x3F);
GPIOPinWrite (writeLed、LED、off);
SysCtlDelay (delayms (5));

//秒

GPIOPinWrite (writeLed、LEDs、rojo);
LCD_COMMAND (0x3F);
GPIOPinWrite (writeLed、LED、off);
SysCtlDelay (delayus (110));

//第三

GPIOPinWrite (writeLed、LEDs、rojo);
LCD_COMMAND (0x3F);
GPIOPinWrite (writeLed、LED、off);
SysCtlDelay (delayus (110));

//四

GPIOPinWrite (writeLed、LEDs、rojo);
LCD_COMMAND (0x30);
GPIOPinWrite (writeLed、LED、off);
SysCtlDelay (delayms (2));

// FIVETH

GPIOPinWrite (writeLed、LEDs、rojo);
LCD_COMMAND (0x08);
GPIOPinWrite (writeLed、LED、off);
SysCtlDelay (delayms (2));

//six

GPIOPinWrite (writeLed、LEDs、rojo);
LCD_COMMAND (0x01);
GPIOPinWrite (writeLed、LED、off);
SysCtlDelay (delayms (2));

//Sevent

GPIOPinWrite (writeLed、LEDs、rojo);
LCD_COMMAND (0x06);
GPIOPinWrite (writeLed、LED、off);
SysCtlDelay (delayms (2));

 光标上的第8个//第8个显示闪烁

GPIOPinWrite (writeLed、LEDs、rojo);
LCD_COMMAND (0x0F);
GPIOPinWrite (writeLed、LED、off);
SysCtlDelay (delayms (2));

void lcd_command (unsigned char cmd)//function to pass command to the LCD


GPIOPinWrite (writeData、B7|B6|B5|B4|B3|B2|B1|B0、cmd);

GPIOPinWrite (writeControl、RS | E、0x00);
SysCtlDelay (delayus (3));

GPIOPinWrite (writeControl、RS | E、0x01);//在 EN 上生成高到低脉冲
SysCtlDelay (delayus (3));
GPIOPinWrite (writeControl、RS | E、0x00);
SysCtlDelay (delayus (110));

void lcd_data (unsigned char data)//函数将数据写入 LCD

/*在端口 B*///在 LCD 数据总线上发送数据
GPIOPinWrite (writeControl、RS | E、0x02);//RS = 1、因为数据已写入 LCD
GPIOPinWrite (writeData、dataPins、data);
GPIOPinWrite (writeLed、LED3|LED2|LED1、Verde);//LED Verde

SysCtlDelay (delayus (3));


GPIOPinWrite (writeControl、RS | E、0x03);//RS = 1、因为数据已写入 LCD
SysCtlDelay (delayus (3));

GPIOPinWrite (writeControl、RS | E、0x02);
GPIOPinWrite (writeLed、LED3|LED2|LED1、0x00);//LED
SysCtlDelay (delayus (110));

//将字符串写入 LCD 的函数
void lcd_write_string (char *str)

int i = 0;
while (str[i]!= 0)

LCD_DATA (str[i]);//逐字节发送 LCD 上的数据
SysCtlDelay (8000000);
i++;

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    开箱后的大多数字符 LCD 将默认为闪烁光标。 你明白了吗?

    如果没有、您是否驱动背光? 是否有对比度引脚?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我的朋友-您是  '123 LPAD 将引脚 PD0/PD1 直接连接  到 PB6/PB7的"受害者#1xxx"!    这种有害的-通常是破坏性的但肯定会延迟-意外的" MCU 引脚交叉连接-肯定会"导致您的问题!    (然而-也许 "不是独立的"-我几乎没有努力"审查您的代码"。)

    查看 '123 LPAD 的原理图-(如果/何时)您按下-(可能)显示交叉连接-如上所述。   您尤其不幸的是、您使用了 GPIO 的两个"配对集"来驱动基于 Char 的 LCD!   因此,你的努力注定要失败。

    要克服这一"短暂"的障碍,就必须清除"鼠疫-抗议者 R9、R10。"   (MCU 正下方)  我们更喜欢"这些"(移除后-将一根电阻引线粘在焊盘上-垂直方向(类似于墓碑)-因为这清楚地提醒我们、现在-该电路板(可能)可以正常工作!

    如果您使用论坛的搜索框(在论坛页面顶部)、我以前的几个"Char LCD 模块"解决方案应该会显示出来。   我提供了"原始"HD44780规格-所有基于 Char 的 LCD 控制器的"祖父"。   初始化是最重要的-实际上-您选择8位而不是4位是明智的选择。   只有在8位成功后-应该尝试4位模式。

    如果您删除了那些"鼠疫-抗议者"、然后重复并报告您的测试、那么这里的人肯定能够提供进一步的帮助。   (现在执行代码审查毫无意义、而那些"鼠疫-抗议者"继续"对无患的用户客户造成痛苦"。

    供应商一再被告知这一"弱点"、并且(在过去五年内)(减去任何供应商纠正/强化警告)海报"超越了 LPAD (标记不佳的悬崖)"、并且"迅速下降到远远低于的深度"。   (小心行事——避免骨折和流血——在你面前的人……)

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    这些电阻器是一种威胁。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    事实上、Peter 和所说的一样、我和其他一些人一再敦促一些(轻微)供应商 重新思考。    (或者 先考虑-如果我是直接下属!)

    曾经有人声称,"鼠疫-抗议者"提高了(长期) MSP 用户的兼容性。   而从这种兼容性中获益的“2,也许3”(间接地)在这里给数百(或许数千)人带来了“痛苦/痛苦”!     (请注意 、"并非所有人都对"这一不明智的供应商决策感到不安-花时间/精力"报告他们的苦难和失败的项目!")

    我本人曾建议,“鼠疫”要“缠绕”——又要“2”或“3”(也许)——他们要“兼容”。

    相反-供应商不采取行动(这是有礼貌的-不是)将海报贴在悬崖顶上-从上面"令人发指的风"-确保他们的流血跌落!   据估计,通过一项经证实的、明显不明智的供应商决定,"阻碍者与帮助者"的比率(很容易)存在" 100:1"。   (用悬崖边的石头铸造-显然!)

    没有人期望"供应商完美!"     然而、"供应商纠正"-针对一个相当严重且持续存在的问题-不应避免!   (这里就是这种情况-是不是吗?)

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    非常感谢、我不能相信我已经花了2周时间来做这个事情了! 我只是将端子 PB6-PB7切换为 PC4和 PC5、并对代码进行了一些更改。
    现在、LCD 已初始化、但它在显示屏中未显示它应该显示的内容。 我将致力于这方面的工作、谢谢
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    很好!
    非常感谢
    如果有人有兴趣使用该代码、请附上最终代码。

    /*
    *拉塔罗·达皮诺
    * 2018年3月27日
    *

    #define target_in_blizzard_RA1
    #include
    #include "stdlib.h"
    #include
    //#include "inc/hw_ca.h"
    //#include "inc/hw_ints.h"
    //#include "driverlib/fpu.h"
    //#include "driverlib/CAN.h"
    //#include "grlib/grlib.h"
    //#include "drivers/cfal96x64x16.h"
    //#include "utils/uartstdio.h"
    //#include "driverlib/interrupt.h"

    //#define target_is_blizzard_RA1
    #include
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    //#include "driverlib/rom.h"
    //#include "driverlib/uart.h"
    //#include "driverlib/adc.h"
    //#include "utils/uartstdio.h"
    //#include "driverlib/pin_map.h"
    //#include //se utiliza para imprimir los valores uint32_t


    #include "math.h"


    //
    //
    //驱动程序库遇到错误时调用的错误例程。
    //
    //
    #ifdef 调试
    无效
    _error__(char * pcFilename、uint32_t ui32Line)


    #endif

    //函数原型
    void init_lcd (void); //初始化 LCD 的函数
    void lcd_command (unsigned char cmd);//function to pass command to the LCD
    void lcd_data (unsigned char data); //将字符写入 LCD 的函数
    void lcd_write_string (char *str);//function to write string to the LCD
    void msdelay (unsigned int time); //函数生成延迟


    /*
    *连接
    * LaunchPad Tiva C
    * TM4C123G
    * Rs e D0 D1 D2 D3 D4 D5. D6. D7. VSS VDD V0 RW A k
    * PD0 PD1 PB0 PB1. PB2. Pb3. PB4. Pb5. PC4. PC5. GND +5V 电阻器 GND +5V GND
    *

    // Puertos 定义
    #define perifericoData SYSCTL_PERIPH_GPIOB
    #define writeData GPIO_PORTB_BASE
    #define B0 GPIO_PIN_0
    #define B1 GPIO_PIN_1
    #define B2 GPIO_PIN_2
    #define B3 GPIO_PIN_3
    定义 B4 GPIO_PIN_4
    #define B5 GPIO_PIN_5

    #define perifericoDataC SYSCTL_PERIPH_GPIOC
    #define writeDataC GPIO_PORTC_BASE
    #define B6 GPIO_PIN_4
    #define B7 GPIO_PIN_5


    #define perifericoControl SYSCTL_PERIPH_GPIOD
    #define writeControl GPIO_PORTD_BASE
    #define E GPIO_PIN_0
    #define Rs GPIO_PIN_1
    #define controlPins e|RS

    #define perifericoLed SYSCTL_PERIPH_GPIOF
    #define writeLed GPIO_PORTF_BASE
    #define LED1 GPIO_PIN_1
    #define LED2 GPIO_PIN_2
    #define LED3 GPIO_PIN_3
    #define LED LED3|LED2|LED1
    #define Cian 0x0C
    #define azul 0x04
    #define rojo 0x02
    #define Verde 0x08
    #define off 0x00


    int delayms (int tiempo){
    int resultado = 1000 *(tiempo /(0.0000625*1000));
    返回结果 ado;

    int delayus (int tiempo){
    int resultado = 1000 *(tiempo /(0.0625*1000));
    返回结果 ado;


    //Start of Main Program
    int main (空)

    char var1[]="hola";//declare message to be displayed

    /*将时钟设置为以16MHz*/直接从晶体运行
    SysCtlClockSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHz | SYSCTL_OSC_MAIN);

    //启用端口 B C D
    SysCtlPeripheralEnable (perifericoControl);
    SysCtlPeripheralEnable (perifericoData);
    SysCtlPeripheralEnable (perifericoDataC);
    SysCtlPeripheralEnable (perifericoLed);
    /*设置 GPIO 引脚的类型*/
    SysCtlDelay (8000000);

    GPIOPinTypeGPIOOutput (GPIO_PORTB_BASE、B0|B1|B2|B3|B4|B5);
    GPIOPinTypeGPIOOutput (GPIO_PORTC_BASE、B6|B7);
    GPIOPinTypeGPIOOutput (GPIO_PORTD_BASE、E|RS);
    GPIOPinTypeGPIOOutput (GPIO_PORTF_BASE、LED3|LED2|LED1);
    SysCtlDelay (8000000);




    init_lcd(); //调用函数来初始化 LCD
    SysCtlDelay (8000000);


    lcd_write_string (var1); //在第一行显示消息

    while (1){ //此处循环
    GPIOPinWrite (writeLed、LED3|LED2|LED1、azul);//LED Azul

    SysCtlDelay (delayms (1000));
    GPIOPinWrite (writeLed、LED3|LED2|LED1、off);//LED Azul

    } //End of Main

    //函数定义
    void init_lcd (void) //函数来初始化 LCD

    //16MHz -- 62.5ns
    SysCtlDelay (8000000);// 550000 ciclos
    GPIOPinWrite (writeControl、RS | E、0x00);//COLOCO RS Y E en 0 POR las dudas Rs = 0 para instructiones E = 1 cuando se comienza a escribir

    //清除显示 0b 0 0 0 0 0 0 0 0 0 1
    //返回主页 0b 0 0 0 0 0 0 0 0 1倍
    //进入模式设置 0b 0 0 0 0 0 0 1 I/D S I/D = 1 mueve el cursor a la derecha S = 1 mueve el display
    //显示开/关 0b 0 0 0 0 0 1 D C B D 显示 C 光标 B 闪烁
    //光标或显示 Shift 0b 0 0 1 S/C R/L x S/C = 0 mueve Cursor R/L = 1 derecha
    //功能集 0b 0 1 DL N F x x x DL = 1 - 8位模式 N = 1 - 2行显示 F = 1 - 5x11点

    GPIOPinWrite (writeLed、LEDs、rojo);
    LCD_COMMAND (0x38);
    GPIOPinWrite (writeLed、LED、off);
    SysCtlDelay (delayms (5));

    GPIOPinWrite (writeLed、LEDs、rojo);
    LCD_COMMAND (0x38);
    GPIOPinWrite (writeLed、LED、off);
    SysCtlDelay (delayus (110));

    GPIOPinWrite (writeLed、LEDs、rojo);
    LCD_COMMAND (0x38);
    GPIOPinWrite (writeLed、LED、off);
    SysCtlDelay (delayus (110));

    GPIOPinWrite (writeLed、LEDs、rojo);
    LCD_COMMAND (0x38);
    GPIOPinWrite (writeLed、LED、off);
    SysCtlDelay (delayms (2));

    GPIOPinWrite (writeLed、LEDs、rojo);
    LCD_COMMAND (0x0F);
    GPIOPinWrite (writeLed、LED、off);
    SysCtlDelay (delayms (2));

    GPIOPinWrite (writeLed、LEDs、rojo);
    LCD_COMMAND (0x01);
    GPIOPinWrite (writeLed、LED、off);
    SysCtlDelay (delayms (2));

    GPIOPinWrite (writeLed、LEDs、rojo);
    LCD_COMMAND (0x06);
    GPIOPinWrite (writeLed、LED、off);
    SysCtlDelay (delayms (2));


    void lcd_command (unsigned char cmd)//function to pass command to the LCD



    GPIOPinWrite (writeData、B5|B4|B3|B2|B1|B0、cmd & 0x3F);
    GPIOPinWrite (writeDataC、B7|B6、(cmd & 0xC0)>> 2);

    GPIOPinWrite (writeControl、RS | E、0x00);
    SysCtlDelay (delayus (3));

    GPIOPinWrite (writeControl、RS | E、0x01);//在 EN 上生成高到低脉冲
    SysCtlDelay (delayus (3));
    GPIOPinWrite (writeControl、RS | E、0x00);
    SysCtlDelay (delayus (110));


    void lcd_data (unsigned char data)//函数将数据写入 LCD

    /*在端口 B*///在 LCD 数据总线上发送数据
    GPIOPinWrite (writeControl、RS | E、0x02);//RS = 1、因为数据已写入 LCD
    GPIOPinWrite (writeData、B5|B4|B3|B2|B1|B0、data & 0x3F);
    GPIOPinWrite (writeDataC、B7|B6、(data & 0xC0)>> 2);

    GPIOPinWrite (writeLed、LED3|LED2|LED1、Verde);//LED Verde

    SysCtlDelay (delayus (3));


    GPIOPinWrite (writeControl、RS | E、0x03);//RS = 1、因为数据已写入 LCD
    SysCtlDelay (delayus (3));

    GPIOPinWrite (writeControl、RS | E、0x02);
    GPIOPinWrite (writeLed、LED3|LED2|LED1、0x00);//LED
    SysCtlDelay (delayus (110));

    //将字符串写入 LCD 的函数
    void lcd_write_string (char *str)

    int i = 0;
    while (str[i]!= 0)

    LCD_DATA (str[i]); //逐字节发送 LCD 上的数据
    SysCtlDelay (8000000);
    i++;

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    再次感谢您、(否则)优秀的"123 LPAD"继续"困扰"那些(合理地)"不要期望多个 MCU GPIO "交叉连接"的用户。

    很抱歉您的"痛苦/痛苦"(也许是被允许的供应商-会在某个时候-把那些瘟疫的人包起来。)

    你坚持坚持"辅导"并成功、这是很好的。

    [引用 user="Dapino Lautaro"]我只需将终端 PB6-PB7切换为 PC4和 PC5[/quot]

    现在、这(混合端口数据总线:端口 B 和 C)不是纠正电路板灾难的最有效方法。   您必须采用两个单独的"端口写入"-将8位数据显示到 LCD。   相反-通过,“删除 R9/R10”... 或者... 通过使用2 个其它端口 GPIO (用于"E"和"RS"),您可以将端口 B 单独用作数据总线,并从单独(不受干扰)的端口/引脚驱动2个控制引脚。