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.
Previous article:AVR microcontroller realizes LED flashing.
Next article:AVRNET Learning Notes UDP Part
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- This Wednesday's award-winning live broadcast: 5G conformance testing and device acceptance testing
- High-speed circuit design and simulation analysis: Cadence example design details
- I would like to ask a question about ultrasonic binary gas concentration measurement?
- Is it "reasonable..." to fly a kite made of your own photo?
- Why is the application of gallium nitride in RF electronics still so popular?
- When the MOS is turned on like 2301, is the VDS voltage 0? That is, there is no loss? The simulation shows that there is no loss.
- Battery Management System BMS Technical Data Transfer
- Looking for Elan EM78P447S microcontroller information
- Usage characteristics of current detection resistors
- 【Running posture training shoes】No.004-Sensor production and primary data processing