標(biāo)題: 想用8255實(shí)現(xiàn)LCD1602的顯示,但是顯示不了。求助大家! [打印本頁(yè)]

作者: 算術(shù)平均數(shù)    時(shí)間: 2020-6-14 18:36
標(biāo)題: 想用8255實(shí)現(xiàn)LCD1602的顯示,但是顯示不了。求助大家!
對(duì)1602的設(shè)置如下:

#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 (248.78 KB, 下載次數(shù): 108)

capture_20200614183423585.jpg

作者: epson009    時(shí)間: 2020-6-15 09:11
是不是因?yàn)闆]有設(shè)置8255的工作方式。
作者: 算術(shù)平均數(shù)    時(shí)間: 2020-6-15 10:05
epson009 發(fā)表于 2020-6-15 09:11
是不是因?yàn)闆]有設(shè)置8255的工作方式?

我設(shè)置了F8255S=0x80,主要是想PA口負(fù)責(zé)控制LCD顯示,要是能用PB口或者PC口控制RS、RW、EN就好了,可是不會(huì)
作者: 算術(shù)平均數(shù)    時(shí)間: 2020-6-15 10:08
epson009 發(fā)表于 2020-6-15 09:11
是不是因?yàn)闆]有設(shè)置8255的工作方式啊?

仿真和代碼在下面,您能幫我看看嗎?
作者: 算術(shù)平均數(shù)    時(shí)間: 2020-6-15 10:09
8255LCD.rar (68.63 KB, 下載次數(shù): 33)
作者: epson009    時(shí)間: 2020-6-15 11:48
我看了下你的電路,里面的373鎖存器LE 端不能一直接地,你把它和單片機(jī)的ALE接到一塊,就可以了。


作者: epson009    時(shí)間: 2020-6-15 11:49
之前的圖里面373的LE沒問題啊~~
作者: 算術(shù)平均數(shù)    時(shí)間: 2020-6-15 18:26
epson009 發(fā)表于 2020-6-15 11:49
之前的圖里面373的LE沒問題啊~~

抱歉抱歉,可能是因?yàn)槲以趦蓮垐D上畫,導(dǎo)致圖片里的和文件里的不太一樣了,改了LE之后能顯示出來了。但是我剛剛演示的時(shí)候發(fā)現(xiàn),好像66度的時(shí)候,后面那個(gè)6顯示不出來,還有一些數(shù)字顯示也有問題。您知道這是為什么嗎?
作者: epson009    時(shí)間: 2020-6-16 06:18
是不是電路設(shè)計(jì)上的問題?看了半天也沒看出來
作者: 算術(shù)平均數(shù)    時(shí)間: 2020-6-16 11:38
epson009 發(fā)表于 2020-6-16 06:18
是不是電路設(shè)計(jì)上的問題?看了半天也沒看出來

真的好迷啊,我也沒看出啥問題
作者: 算術(shù)平均數(shù)    時(shí)間: 2020-6-16 19:50
epson009 發(fā)表于 2020-6-15 11:48
我看了下你的電路,里面的373鎖存器LE 端不能一直接地,你把它和單片機(jī)的ALE接到一塊,就可以了。

咦,是的啊,我把373的LE和單片機(jī)的ALE連在一起了,但是連完之后有的數(shù)字還是顯示不全,只顯示了一部分。
作者: 13317970316    時(shí)間: 2020-9-26 23:03
程序沒有寫完整啊
作者: gfshao    時(shí)間: 2020-9-29 15:02
373鎖存器LE 端應(yīng)該和單片機(jī)的ALE同名連接
作者: angmall    時(shí)間: 2020-9-29 20:34
我給你來個(gè)試試




  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. }


復(fù)制代碼









歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1