搜索
bottom↓
回复: 16

3-wire Serial Interface to LCD

[复制链接]

出0入0汤圆

发表于 2009-11-27 00:18:45 | 显示全部楼层 |阅读模式
the typical HD44780-based LCDs require 8 data lines (4 if running in 4-bit mode), plus 2-3 control lines.

that may be a problem on mcus with limited number of output pins.

one of the solutions is to use a LCD with serial interface but that can be expensive.

here is a solution that uses shift registers (74xx164 or the equivalent). The resulting connection requires just 3 pins from the mcu (plus two for Vdd and GND).

and the code is written flexibly so you can port it to other platforms easily. the connection is defined in the header file so if you change the connection, you can just recompile.

enjoy.


(原文件名:12F675 3-wire Serial LCD.PNG)

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2009-11-27 00:29:42 | 显示全部楼层
the code base is here.

点击此处下载 ourdev_507953.rar(文件大小:12K) (原文件名:12F675 3-wire LCDDemo.rar)

出0入0汤圆

发表于 2009-11-27 08:15:41 | 显示全部楼层
Hello millwood0 ,RS引脚为什么不接到74HC164的输出端?是为了编程方便吗?

出0入0汤圆

 楼主| 发表于 2009-11-27 19:28:24 | 显示全部楼层
"RS引脚为什么不接到74HC164的输出端?是为了编程方便吗?"

so you retain the flexibility to put the LCD in 8bit or 4bit mode.

出0入0汤圆

 楼主| 发表于 2009-11-27 19:29:41 | 显示全部楼层
I was just reading the datasheet for DS18 and the 1-wire bus used there and thought it may be possible to utilize a similar system here and combine the CLK line with the Data line to create a two wire system.

出0入0汤圆

发表于 2009-11-27 23:19:52 | 显示全部楼层
可以的,不过你可能需要把芯片换成74hc595,我曾做过试验,单根混合数据线就可以传送。
http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=2243715 该贴子图中数码管模块就是单线传送。

出0入0汤圆

 楼主| 发表于 2009-11-28 20:21:49 | 显示全部楼层
here is the same program in 8-bit mode.


(原文件名:12F675 3-wire 8bit.PNG)

here is the code base

点击此处下载 ourdev_508546.rar(文件大小:12K) (原文件名:12F675 3-wire LCDDemo.rar)

出0入0汤圆

 楼主| 发表于 2009-11-28 20:40:13 | 显示全部楼层
here is a short description of this 2-wire system.

most of the shift registers work by reading the SI / DAT line when the clock goes from low to high. so if you have a r/c network linking the clock to the SI, as in the attached schematic.

so when you transmit a short low pulse on the clock line, when you pull the clock line high, the voltage on the capacitor dips just a little bit, and the dataline will read a 1.

when you transmit a long pulse on the clock line, the voltage on the capacitor will have diped enough so the dataline reads 0 when the clock transits from low to high.

in my design, I sent the total pulse length (ttotal) to 60us. a short pulse would be 1 us. As to the long pulse, I want to give enough time so that the capacitor is fully charged up so I will pull the clock line low for no more than 50% of ttotal, aka 30us.

As to the value of the R/C network: I don't want to overload the mcu pins. to design for ARM chips which output 2ma, I want the current load to be 0.5ma. so I use R=3.3v/0.5ma=6.7k, and I will pick 10k.

the time constant of the rc network should not be too short so that a short pulse will still read a 1, but shortlyn't be too long either. I want to make sure that it gets to zero by 50% of the long pulse (30us). so 15us. that means a C of 1.5n, and I will use 1.1nf.

the program goes something like this:

void send_bit(unsigned char Ton) {
  unsigned char Ttotal=60; //pulse cycle of 60us
  SPI_CLK=0;  //pull the spi_clk low;
  delay_us(Ton); //delay;
  SPI_CLK=1;  //pull the spi_clk high;
  delay_us(Ttotal-Ton);
}

so send_bit(1) will send a 1us low pulse on the clock line and shift a 1 into the shift register; send_bit(30) will send a 30us pulse on the clock line and shift a 0 into the shift registor.

obviously, this will take 60us*8=.5ms to send one byte.

you can easily implement the concept in my spi_send_byte(routine) without changing the rest of the program to create a two wire system.


(原文件名:12F675 2-wire 4bit.PNG)

出0入0汤圆

发表于 2009-11-28 23:35:43 | 显示全部楼层
按照这种方法,有个难点不能解决,就是系统的实时性。如果系统中存在中断,且中断处理时间不是很短,那么会影响这个串行数据的传输,并可能出现错误。millwood0 有没有好的方法解决这个难点?

出0入0汤圆

 楼主| 发表于 2009-11-29 00:36:10 | 显示全部楼层
cowboy, you are absolutely right.

if an interrupt is taking too long to execute, aka it is materially more than the shortest duration (for 1) and comparable to the longest duration (for 0), the output may be faulty.

a few possibilities:

1) increase the cycle time. 60us was chosen to be comparable to Maxim's 1-wire system but you can pick a longer one.
2) tristate the SPI_CLK pin in the interrupt: once you go into an interrupt, you can turn the SPI_CLK pin into a high impedance mode (aka input mode) so the capacitor doesn't get discharged.
3) make sure you write very short interrupt routines - which they should be.

yeah, that's the price you pay for eliminating one wire.

another question: can you figure out a way to eliminate the LCD_EN wire?

出0入0汤圆

发表于 2009-11-29 00:41:02 | 显示全部楼层
现在的芯片动辄上100脚,节省几个IO的场合越来越少

出0入0汤圆

发表于 2009-11-29 01:40:08 | 显示全部楼层
to millwood0:
turn the SPI_CLK pin into a high impedance mode , so the capacitor doesn't get discharged.
但是,当口线从高阻抗状态恢复时,HC164的CLK引脚可能会引入一个额外的脉冲。

one wire 模式中,我在EN中加入RC,时间常数更长。显然这会使LCD更新很慢,我的方法只适合驱动数码管。

出0入0汤圆

 楼主| 发表于 2010-1-24 09:43:09 | 显示全部楼层
here is a revised version of the 3-wire interface. This time, the demo program has an interrupt running while the lcd routines update the display.

it is confirmed to run on real hardware as well. as you can see from the simulation, it takes about 9ms to update each line of the lcd. pretty fast. the whole program takes about 750bytes, and the lcd routines themselves about 500 bytes.

This can serve as a basis for a serial lcd design, either spi/i2c or even one-wire.


(原文件名:16F675 3W-RS CLK.PNG)

点击此处下载 ourdev_527970.rar(文件大小:25K) (原文件名:12F675 3-wire LCDemo Clock.rar)

出0入4汤圆

发表于 2010-1-24 16:56:28 | 显示全部楼层
学习

出0入0汤圆

发表于 2011-10-2 12:56:23 | 显示全部楼层
好厉害啊!!!

出0入0汤圆

发表于 2011-10-2 13:06:55 | 显示全部楼层
几个神犇在谈话 我来围观

出0入0汤圆

发表于 2011-11-23 20:26:32 | 显示全部楼层
he```
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-20 20:51

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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