一个用两个IO驱动LCD1206显示的超牛方案

明亮 posted @ 2011年3月16日 17:45 in 【科学综合】 , 3537 阅读
本文发表于:http://fml927.is-programmer.com

整理自:http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=4301955&bbs_page_no=1&bbs_id=9999

1、完成结果展示图:

1 

2

增加了“无线馈电及传送数据”部分的电路展示:

3 

电路图如下,仔细观察可以发现实物图中有几个贴片的阻容件,秘密就在这里,利用电容的记忆效应,把串行的数据转为并行。

6

示范程序如下比较简单,不用多注释应该都能看懂。作为演示用途,其中有些长时间延时没有没有使用定时器,在多任务系统中当然要用定时中断来代替了。

//         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); 
}   

 

后记:这个设计的突出特点部分是串并转换的思想和设计电路,虽然从运行时间上、稳定性上将不太可取,但是,这个设计方法可以在很多地方用到,还有就是这个作者敢想、敢做。要是真的需要很少的引脚来控制LCD的话,我宁肯选择一个带SPI接口的LCD,可定比这个方案稳定、快速。

  • 无匹配
  • 无匹配
boardmodelpaper.com 说:
2024年1月22日 15:34

The Board model paper" typically refers to a sample or model question paper that is designed by educational boards or institutions for various exams. These papers serve as practice material for students preparing for exams, providing them with an idea of the question format, difficulty level, and the type of content that may be covered in the actual examination. boardmodelpaper.com Model papers are usually created for specific subjects or courses. They cover a range of topics and chapters that students are expected to have studied during the academic term. Students often use these educational board model papers as an integral part of their exam preparation strategy, helping them familiarize themselves with the exam pattern and refine their understanding of the subject matter.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter