找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2274|回复: 13
收起左侧

想用8255实现LCD1602的显示,但是显示不了。求助大家!

[复制链接]
ID:744425 发表于 2020-6-14 18:36 | 显示全部楼层 |阅读模式
对1602的设置如下:

#include <REG51.h>
#include <ABSACC.h>
#define uchar unsigned char
#define uint unsigned int
#define F8255S XBYTE[0xdfff]
#define PA XBYTE[0xdffc]
#define PB XBYTE[0xdffd]
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
void write_com(uchar com)
{
  PA=com;
  RS=0;RW=0;EN=1;
  delay(10);
  EN=0;
}

void write_dat(uchar dat)
{
  PA=dat;  
  RS=1;RW=0;EN=1;
  delay(10);  
  EN=0;
}

void init_LM1602()
{
  write_com(0x01);
  write_com(0x38);
  write_com(0x0c);
  write_com(0x06);
}
仿真图:

capture_20200614183423585.jpg
回复

使用道具 举报

ID:24758 发表于 2020-6-15 09:11 | 显示全部楼层
是不是因为没有设置8255的工作方式啊?
回复

使用道具 举报

ID:744425 发表于 2020-6-15 10:05 | 显示全部楼层
epson009 发表于 2020-6-15 09:11
是不是因为没有设置8255的工作方式啊?

我设置了F8255S=0x80,主要是想PA口负责控制LCD显示,要是能用PB口或者PC口控制RS、RW、EN就好了,可是不会
回复

使用道具 举报

ID:744425 发表于 2020-6-15 10:08 | 显示全部楼层
epson009 发表于 2020-6-15 09:11
是不是因为没有设置8255的工作方式啊?

仿真和代码在下面,您能帮我看看吗?
回复

使用道具 举报

ID:744425 发表于 2020-6-15 10:09 | 显示全部楼层
8255LCD.rar (68.63 KB, 下载次数: 33)
回复

使用道具 举报

ID:24758 发表于 2020-6-15 11:48 | 显示全部楼层
我看了下你的电路,里面的373锁存器LE 端不能一直接地,你把它和单片机的ALE接到一块,就可以了。

1.png

评分

参与人数 1黑币 +20 收起 理由
admin + 20 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

ID:24758 发表于 2020-6-15 11:49 | 显示全部楼层
之前的图里面373的LE没问题啊~~
回复

使用道具 举报

ID:744425 发表于 2020-6-15 18:26 | 显示全部楼层
epson009 发表于 2020-6-15 11:49
之前的图里面373的LE没问题啊~~

抱歉抱歉,可能是因为我在两张图上画,导致图片里的和文件里的不太一样了,改了LE之后能显示出来了。但是我刚刚演示的时候发现,好像66度的时候,后面那个6显示不出来,还有一些数字显示也有问题。您知道这是为什么吗?
回复

使用道具 举报

ID:24758 发表于 2020-6-16 06:18 | 显示全部楼层
是不是电路设计上的问题啊?看了半天也没看出来
回复

使用道具 举报

ID:744425 发表于 2020-6-16 11:38 | 显示全部楼层
epson009 发表于 2020-6-16 06:18
是不是电路设计上的问题啊?看了半天也没看出来

真的好迷啊,我也没看出啥问题
回复

使用道具 举报

ID:744425 发表于 2020-6-16 19:50 | 显示全部楼层
epson009 发表于 2020-6-15 11:48
我看了下你的电路,里面的373锁存器LE 端不能一直接地,你把它和单片机的ALE接到一块,就可以了。

咦,是的啊,我把373的LE和单片机的ALE连在一起了,但是连完之后有的数字还是显示不全,只显示了一部分。
回复

使用道具 举报

ID:683360 发表于 2020-9-26 23:03 | 显示全部楼层
程序没有写完整啊
回复

使用道具 举报

ID:106821 发表于 2020-9-29 15:02 | 显示全部楼层
373锁存器LE 端应该和单片机的ALE同名连接
回复

使用道具 举报

ID:155507 发表于 2020-9-29 20:34 | 显示全部楼层
我给你来个试试
8255LCD1602.jpg



  1. #include < reg51.h >

  2. char xdata PORTA _at_ 0x4000; //by making PORTA with address 4000H we are selecting Port A of the 8255
  3. // and the CS low (select the 8255)
  4. char xdata PORTB _at_ 0x4001; //by making PORTB with address 4001H we are selecting Port B of the 8255
  5. // and the CS low (select the 8255)

  6. void send_command(unsigned char i);
  7. void send_data(unsigned char i);
  8. void delay();

  9. void main(void)
  10. {
  11.         unsigned int i=0;
  12.         unsigned char line_1[] = "51HEI Hello ";
  13.         unsigned char line_2[] = "MICROCONTROLLER";

  14.         send_command(0x38); // Initialize LCD in 16x2 matrix mode
  15.         send_command(0x0E); // Display ON and cursor ON
  16.         send_command(0x01); // Clear the LCD
  17.         send_command(0x83); // Select first line and position of the cursor to 83H + position

  18.         // Display the dat on LCD's first line
  19.         for (i = 0; i < 11; i++)
  20.         {
  21.                 send_data(line_1[i]);
  22.         }

  23.         send_command(0xC0); // Select the second line

  24.         // Display the dat on LCD's second line
  25.         for (i = 0; i < 16; i++)
  26.         {
  27.                 send_data(line_2[i]);
  28.         }

  29.         while(1); //Loop forever to display the dat until the power is switched OFF
  30. }

  31. //Function to send command
  32. void send_command(unsigned char i)
  33. {
  34.         PORTA = i; //put data into 4000H

  35.         // Port B is connected to the command pins i.e. RS, R/W, and E
  36.         PORTB = 0x04; //4001H = 04H (00000100B) implies E = 1, RW = 0 (Write to LCD), RS = 0 (Command to be wriiten)
  37.         delay();

  38.         PORTB = 0x00; //4001H = 00H (00000000B) implies E = 0 (High to low pulse), RW = 0 (Write to LCD), RS = 0 (Command to be wriiten)
  39.         delay();
  40.         return;
  41. }

  42. //Function to send dat
  43. void send_data (unsigned char i)
  44. {
  45.         PORTA = i; //put data into 4000H

  46.         // Port B is connected to the command pins i.e. RS, R/W, and E
  47.         PORTB = 0x05; // 4001H = 05H (00000101B) implies E = 1, RW = 0 (Write to LCD), RS = 1 (Data to be wriiten to LCD)
  48.         delay();

  49.         PORTB = 0x01; // 4001H = 01H (0000 0001B) implies E = 0 (High to low pulse), RW = 0 (Write to LCD), RS = 1 (Data to be wriiten to LCD)
  50.         delay();
  51.         return;
  52. }

  53. // Function to generate delay
  54. void delay()
  55. {
  56.         unsigned int i =0;
  57.         for (i = 0; i < 100; i++);
  58. }


复制代码




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表