位置:51电子网 » 技术资料 » 单 片 机

ICCAVR->8515和LCD的接口源程序

发布时间:2007/9/10 0:00:00 访问次数:822

AVR8515 和 HD74480字符LCD的接口程序
//
//    硬件连接方式:LCD的D0-D7接8515的c口,
//                  LCD的 RS ->PA0
//                  LCD的 RW ->PA1
//                  LCD的 E  ->PA0
//    !!!注意VEE,有时需要接负电源
---------------------------------------------------------------------
#include

#define RS_H  asm("sbi 0x1B,0")
#define RS_L  asm("cbi 0x1B,0")
#define RW_H  asm("sbi 0x1B,1")
#define RW_L  asm("cbi 0x1B,1")
#define E_H   asm("sbi 0x1b,2")
#define E_L   asm("cbi 0x1b,2")

//******************************************
void Delay()
{
     unsigned char di;
     for(di=0;di<20;di++);
}

//判断lcd是否是内部操作状态
char Lcd_Busy()
{
        char rb;
    
        DDRC=0x0;   //端口c设为输入方式
        E_L;
     RS_L;
    RW_H;
    Delay();
    E_H;
    Delay();
    rb=PINC;
    rb=rb&0x80;
    E_L;
    DDRC=0xff;  //端口c设为输出方式

    return rb;
}


//向Lcd发送命令程序
void Lcd_Command(unsigned char bComm)
{
    while(Lcd_Busy());
    E_L;
     RS_L;
    RW_L;
    Delay();
    E_H;
    PORTC=bComm;
    Delay();
    E_L;
    Delay();

}

//向lcd写入一个字符
void Lcd_Write(char wb)
{
    while(Lcd_Busy());
    E_L;
     RS_H;
    RW_L;
    Delay();
    E_H;
    PORTC=wb;
    Delay();
    E_L;
    Delay();
}

//初始化时用的写命令程序,和Lcd_Command的区别是不判断忙标志
void Lcd_InitCommand(unsigned char bComm)
{
    E_L;
     RS_L;
    RW_L;
    Delay();
    E_H;
    PORTC=bComm;
    Delay();
    E_L;
}

//初始化:8位接口,2行x16字符的工作方式
void Lcd_Init()
{
  char i;
  Lcd_InitCommand(0x30);
  for(i=0;i<100;i++) Delay();
  Lcd_InitCommand(0x30);
  for(i=0;i<10;i++) Delay();
  Lcd_InitCommand(0x30);

  Lcd_Command(0x38);
  Lcd_Command(0x08);
  Lcd_Command(0x01);
  Lcd_Command(0x06);
  Lcd_Command(0x02);
  Lcd_Command(0x0E);
}

//一个测试LCD的小程序
int main()
{
  
  const char *str="Hello,This is Dai in HIT.";

  DDRA=0xFF;
  DDRC=0xFF;
  
  Lcd_Init();

  while(*str)   Lcd_Write( *str++ );

  while(1);

AVR8515 和 HD74480字符LCD的接口程序
//
//    硬件连接方式:LCD的D0-D7接8515的c口,
//                  LCD的 RS ->PA0
//                  LCD的 RW ->PA1
//                  LCD的 E  ->PA0
//    !!!注意VEE,有时需要接负电源
---------------------------------------------------------------------
#include

#define RS_H  asm("sbi 0x1B,0")
#define RS_L  asm("cbi 0x1B,0")
#define RW_H  asm("sbi 0x1B,1")
#define RW_L  asm("cbi 0x1B,1")
#define E_H   asm("sbi 0x1b,2")
#define E_L   asm("cbi 0x1b,2")

//******************************************
void Delay()
{
     unsigned char di;
     for(di=0;di<20;di++);
}

//判断lcd是否是内部操作状态
char Lcd_Busy()
{
        char rb;
    
        DDRC=0x0;   //端口c设为输入方式
        E_L;
     RS_L;
    RW_H;
    Delay();
    E_H;
    Delay();
    rb=PINC;
    rb=rb&0x80;
    E_L;
    DDRC=0xff;  //端口c设为输出方式

    return rb;
}


//向Lcd发送命令程序
void Lcd_Command(unsigned char bComm)
{
    while(Lcd_Busy());
    E_L;
     RS_L;
    RW_L;
    Delay();
    E_H;
    PORTC=bComm;
    Delay();
    E_L;
    Delay();

}

//向lcd写入一个字符
void Lcd_Write(char wb)
{
    while(Lcd_Busy());
    E_L;
     RS_H;
    RW_L;
    Delay();
    E_H;
    PORTC=wb;
    Delay();
    E_L;
    Delay();
}

//初始化时用的写命令程序,和Lcd_Command的区别是不判断忙标志
void Lcd_InitCommand(unsigned char bComm)
{
    E_L;
     RS_L;
    RW_L;
    Delay();
    E_H;
    PORTC=bComm;
    Delay();
    E_L;
}

//初始化:8位接口,2行x16字符的工作方式
void Lcd_Init()
{
  char i;
  Lcd_InitCommand(0x30);
  for(i=0;i<100;i++) Delay();
  Lcd_InitCommand(0x30);
  for(i=0;i<10;i++) Delay();
  Lcd_InitCommand(0x30);

  Lcd_Command(0x38);
  Lcd_Command(0x08);
  Lcd_Command(0x01);
  Lcd_Command(0x06);
  Lcd_Command(0x02);
  Lcd_Command(0x0E);
}

//一个测试LCD的小程序
int main()
{
  
  const char *str="Hello,This is Dai in HIT.";

  DDRA=0xFF;
  DDRC=0xFF;
  
  Lcd_Init();

  while(*str)   Lcd_Write( *str++ );

  while(1);

相关IC型号

热门点击

 

推荐技术资料

硬盘式MP3播放器终级改
    一次偶然的机会我结识了NE0 2511,那是一个远方的... [详细]
版权所有:51dzw.COM
深圳服务热线:13751165337  13692101218
粤ICP备09112631号-6(miitbeian.gov.cn)
公网安备44030402000607
深圳市碧威特网络技术有限公司
付款方式


 复制成功!