锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

用最少的线实现LCD1602的驱动_过路老熊_新浪博客

时间:2023-11-12 03:37:02 xy贴片二极管

先上图:

用最少的线实现LCD1602的驱动


说明,连接LCD除了红黑电源外,1602的四条引线中有两条是黄色的信号线,其中一条是传输的RS另一个和E信号传输D4~D7信号由四位总线驱动。

再减少一根线,还是好用的,但是要加一个电容和一个二极管。 如图:

再次挑战:无线馈电和数据传输

下面是仿真图,秘密就在这里面,细心的朋友会发现实物图中有几个贴片的阻容件,秘密就在这里,利用电容的记忆效应,把并行的数据转为串行。

程序如下:

演示程序非常简单,不需要更多的注释就可以理解。作为演示的目的,有些长时间延迟不使用定时器,当然,在多任务系统中使用定时中断。
// 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);
}

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章