四线1602液晶显示(51单片机)
昨天在网上看到了用4线操作1602,我就试了一下,果然可以!程序: {:victory:}好像很不错,试试 没错,可以的。最早我是在Xilinx的开发板上看到的 {:titter:} 你这个实际还是7线,,,+2线电源地
如果 撸主 看到cowboy 的2线(2个io+2个电源地){:titter:}+ 甚至”无线“or “人肉” 驱动,,,还不 震 精 出来,,,, 不错,好。 jetli 发表于 2013-5-13 12:49 static/image/common/back.gif
你这个实际还是7线,,,+2线电源地
如果 撸主 看到cowboy 的2线(2个io+2个电源地){:tit ...
四根数据线。有两根线控制的吗?共享出来学习一下呗! ding_ding0304 发表于 2013-5-13 13:09 static/image/common/back.gif
四根数据线。有两根线控制的吗?共享出来学习一下呗!
http://www.amobbs.com/thread-4301955-1-1.html Tliang 发表于 2013-5-13 14:11 static/image/common/back.gif
http://www.amobbs.com/thread-4301955-1-1.html
看了,好牛啊!
示范程序很简单,不用多注释应该都能看懂。作为演示用途,其中有些长时间延时没有没有使用定时器,在多任务系统中当然要用定时中断来代替了。
// Drive a LCD1602 with 2 wire
//===================================================
//ICC-AVR application builder : 2010-10-3 19:30:02
// Target : M16
// Crystal: 4.0000Mhz
#include <iom16v.h>
#include <macros.h>
#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);
} 第一次听说还可以这样用哦 benqme 发表于 2013-5-13 16:52 static/image/common/back.gif
第一次听说还可以这样用哦
还有人肉 驱动,,去搜索cowboy的帖子吧{:titter:} 看着不错呀, 呵 本坛前辈 都研究过 还有2线的 很赞LZ的编程风格!! l769109884 发表于 2013-5-15 19:52 static/image/common/back.gif
很赞LZ的编程风格!!
谢谢,有本《高质量程序设计指南——C++/C语言》讲的不错!
http://pan.baidu.com/share/link?shareid=450557&uk=540516030 这个是1602的串行模式吧! 这节省了好多的引脚了哦
页:
[1]