|
本帖最后由 leorio 于 2025-8-2 16:29 编辑
本人最近在Linux上学习51单片机(STC 89C52RC),通过使用PlatformIO跨平台,和sdcc编译烧录代码。在学习LCD1602时存在一个问题,无法显示字符。
我尝试在Stack Overflow寻求答案并采用给出的答案,但是依旧无法显示正确的字符。我怀疑是否与我采用的51单片机有关,但是我对硬件方面并不是太熟悉,该产品的开发原理图我亦看不太懂。
具体原理图如下:
烧录后结果图片如下:
具体代码如下:
- /* utils.h */
- #include <8052.h>
- #include <stdint.h>
- __sbit __at(0xA5) LCD_RW;
- __sbit __at(0xA6) LCD_RS;
- __sbit __at(0xA7) LCD_EN;
- #define LCD_PORT P0
- /* utils.c */
- void
- lcd_write_command(const uint8_t command) {
- LCD_RW = 0;
- LCD_RS = 0;
- LCD_PORT = command;
- LCD_EN = 1;
- delay(1000);
- LCD_EN = 0;
- delay(1000);
- }
- void
- lcd_write_data(const char _data) {
- LCD_RW = 0;
- LCD_RS = 1;
- LCD_PORT = _data;
- LCD_EN = 1;
- delay(1000);
- LCD_EN = 0;
- delay(1000);
- }
- void
- lcd_init() {
- lcd_write_command(0x38);
- lcd_write_command(0x0c);
- lcd_write_command(0x06);
- lcd_write_command(0x01);
- }
- void
- lcd_show_char(const uint8_t row, const uint8_t col, const char c) {
- lcd_set_cursor(row, col);
- lcd_write_data(c);
- }
- /* main.c */
- int8_t
- main() {
- lcd_init();
- lcd_show_char(1, 1, 'a');
- while (true){}
- }
复制代码
|
|