Any two IOs can directly drive LCD1602 without external chip

Publisher:陈书记Latest update time:2017-02-20 Keywords:LCD1602 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This is the circuit. Careful friends will find that there are several chip resistors and capacitors in the actual picture. The secret is here. The memory effect of the capacitor is used to convert parallel data into serial data.

(Original file name: 2wire_1602.PNG) 

The demonstration program is very simple and should be understandable without much comment. For demonstration purposes, some of the long delays do not use timers. In a multi-tasking system, timer interrupts should be used instead.

// Drive a LCD1602 with 2 wire
//================================================
//ICC-AVR application builder : 2010-10-3 19:30:02
// Target : M16
// Crystal: 4.0000Mhz

#include
#include

#define Set_E PORTB|=2
#define Clr _E PORTB&=~2
#define Set_D PORTB|=1
#define Clr_D PORTB&=~1
#define Set_xy(y,x) Send(0,(y<<6)|(x&15)|0x80)

//==================================================
void init_devices(void)
{
  CLI(); //disable all interrupts
  DDRB = 0x03;
  MCUCR = 0x00;
  GICR = 0x00;
  SEI(); //re-enable interrupts
}

//================================================
void Delay (unsigned int i)
{
  while(i--);
}        

//========================================================
void Send(unsigned char RS, unsigned char dat)
{
  unsigned char i;
  for (i = 2; i > 0; i--)
  {
    if (dat & 0x80) Set_D; else Clr_D;
    Delay(10608);//14520us
    if (RS) Set_E;
    if (dat & 0x40) Set_D; else Clr_D;
    Delay(462); //660us
    if (dat & 0x20) Set_D; else Clr_D;
    Delay(18); //30us
    Set_E;
    if (dat & 0x10) Set_D; else Clr_D;
    _NOP(); //0.5us < t < 1.36us
    Clr_E;
    dat <<= 4;
  }        
}

//====================================== ==============
void init_1602(void)
{
  unsigned char i = 3;
  Clr_D;
  Clr_E;
  Delay(10608);
  do{
    Clr_D;
    Delay(462);
    Set_D;
    Set_E;
    Delay( 18);
    if (i == 0) Clr_D;
    _NOP();_NOP();_NOP();
    Clr_E;
    }while(i--);
  Send(0,0x28);
  Send(0,0x01);
  Send(0,0x0f);
}

//================================== ==================
void Send_S(unsigned char *p)
{
  while(*p) Send(1,*p++);
}        

//======= ============================================
void main(void)
{
  unsigned char i;
  init_devices();
  init_1602();
  
  Set_xy(0,2);
  Send_S("Hello world!");
  Set_xy(1,3);
  Send_S("I'm COWBOY.");
  for (i= 0;i<255;i++) Delay(10000);
  
  Send(0,0x01);
  Set_xy(0,3);
  Send_S("Welcome to");
  Set_xy(1,1);
  Send_S("www.ourdev.cn");
  while(1);
}

 

/****************************************************** *************************************************/

Reply to [13th floor] zhonghua_li Blue Sky
It is a bit dangerous to use one pin to realize 4 ports through RC. 
It is recommended to change it to 3 pins.
-----------------------------------------------------------------------

Reply to [25th floor] longquan Dian
So that's it, it is realized by using time constants with large differences
-----------------------------------------------------------------------

Reply to [26th floor] millwood0 
"It is realized by using time constants with large differences" 
yes. that points to the problem with this approach: the time to send multi-bits gets exponentially longer. 

-----------------------------------------------------------------------

    Everyone above has seen the door. In order to ensure the reliability of data transmission, the RC time constants of two adjacent bits of data need to differ greatly. I set it to about 22 times here. The larger the difference, the higher the reliability. In fact, I tried 12 times the interval and it still worked normally, but considering the error and temperature drift of resistance and capacitance, as well as electromagnetic interference and other factors, I chose 22 times the interval. Too long geometric intervals will lead to the problem of slow data transmission speed. For example, the RC parameters in the original post require about 32ms to transmit one byte of data. As millwood0 said, when sending multiple bytes continuously, the communication line will be too busy and must wait. To solve this problem, I wrote another program to set up a sending buffer and a ring FIFO structure to temporarily store the content to be displayed, and use a timer interrupt to complete the automatic transmission. IO is saved, but it brings dozens of bytes of memory overhead and occupies a timer. A
    more practical solution, as zhonghua_li Blue Sky said, is to use one more IO, so that each IO only drives two PINs of LCD1602, and the above problems can be perfectly solved, including the selection of RC time constants, which greatly relaxes the requirements, and the transmission speed is equivalent to the ordinary driving method.
    Most people will have doubts, with just a few resistors and capacitors, can it work reliably? I have also considered this problem. In actual applications, it is often seen that there are low-pass filter networks composed of small resistors and small capacitors on the data line to improve the reliability of data transmission. The usage of RC here is similar. Using a larger RC is theoretically more effective in resisting external EMC interference. In terms of design, as long as the falling edge of the clock pulse is guaranteed, the upper level of each data line meets the requirements of LCD1602 (VH>4V, VL<1V). How is the actual test performance? A simple method was used for simulation: 1. Continuously send data, and then when the mobile phone is connected, put the mobile phone antenna close to the data line, and no abnormality was found. 2. Use the ground wire of the working oscilloscope signal line to continuously touch the relevant pins of LCD1602, and no abnormality was found. Of course, this test is not standardized, so this driving method can be played with, but it must be carefully considered before using it in products.

 

 

/****************************************************** *************************************************/

Challenge the limit and reduce one more line. It still works well, but you need to add another capacitor and a diode

. 3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.7755371807143092',width:img.width,height:im g.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0">

 

/****************************************************** *************************************************/

Reply to [63F] 

Should WinMCU be more ruthless and use only one IO and one ground line? It seems that Sony already has this technology for data communication (data communication based on chips). 
-----------------------------------------------------------------------

WinMCU is talking about a communication method similar to the fire bus, which directly modulates the serial data on the power line, but this requires a dedicated chip to demodulate, and it cannot be done with just a few RCs. I did a similar method two years ago. I wonder if you are familiar with the following picture. This is a picture in a post I posted before. Refer to:
    http://www.amobbs.com/forum.php?mod=viewthread&tid=2243715
The demonstration program mentioned the driver of the One Wire bus, and the chip used for the display module demodulation is not a dedicated chip, but just a 74HC595 that we are most familiar with, which can complete the task.




At that time, for the convenience of not loading data on the power supply, a separate data line was led, so there are three leads (VCC, GND, DAT), in fact, the data can be loaded on the power supply.
Post a bottom view of the display module, you can see the use of a 74HC595 to demodulate OneWire communication and drive three digital tubes.
The modulation of the transmitter (MCU) is also very simple, with just one IO output and a transistor to expand the current.
If you are interested, I can open another thread to discuss it when I have time.
However, I still can't think of a good way to use this method on LCD1602 without adding another chip, unless the peripheral circuit is very complicated, but then it loses its meaning.





Keywords:LCD1602 Reference address:Any two IOs can directly drive LCD1602 without external chip

Previous article:AVR microcontroller realizes LED flashing.
Next article:AVRNET Learning Notes UDP Part

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号