标题: 关于使用PlatformIO和sdcc在Linux上使用stc89c52rc单片机问题 [打印本页]

作者: leorio    时间: 2025-8-2 11:47
标题: 关于使用PlatformIO和sdcc在Linux上使用stc89c52rc单片机问题
本帖最后由 leorio 于 2025-8-2 16:29 编辑

本人最近在Linux上学习51单片机(STC 89C52RC),通过使用PlatformIO跨平台,和sdcc编译烧录代码。在学习LCD1602时存在一个问题,无法显示字符。

我尝试在Stack Overflow寻求答案并采用给出的答案,但是依旧无法显示正确的字符。我怀疑是否与我采用的51单片机有关,但是我对硬件方面并不是太熟悉,该产品的开发原理图我亦看不太懂。

具体原理图如下:


烧录后结果图片如下:


具体代码如下:
  1. /* utils.h */
  2. #include <8052.h>
  3. #include <stdint.h>
  4. __sbit __at(0xA5) LCD_RW;
  5. __sbit __at(0xA6) LCD_RS;
  6. __sbit __at(0xA7) LCD_EN;
  7. #define LCD_PORT P0

  8. /* utils.c */
  9. void
  10. lcd_write_command(const uint8_t command) {
  11.     LCD_RW = 0;
  12.     LCD_RS = 0;
  13.     LCD_PORT = command;
  14.     LCD_EN = 1;
  15.     delay(1000);
  16.     LCD_EN = 0;
  17.     delay(1000);
  18. }

  19. void
  20. lcd_write_data(const char _data) {
  21.     LCD_RW = 0;
  22.     LCD_RS = 1;
  23.     LCD_PORT = _data;
  24.     LCD_EN = 1;
  25.     delay(1000);
  26.     LCD_EN = 0;
  27.     delay(1000);
  28. }

  29. void
  30. lcd_init() {
  31.     lcd_write_command(0x38);
  32.     lcd_write_command(0x0c);
  33.     lcd_write_command(0x06);
  34.     lcd_write_command(0x01);
  35. }

  36. void
  37. lcd_show_char(const uint8_t row, const uint8_t col, const char c) {
  38.     lcd_set_cursor(row, col);
  39.     lcd_write_data(c);
  40. }

  41. /* main.c */
  42. int8_t
  43. main() {
  44.     lcd_init();
  45.     lcd_show_char(1, 1, 'a');
  46.     while (true){}
  47. }
复制代码



普中-7开发板原理图.pdf

232.57 KB, 下载次数: 0






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1