RA8802液晶驱动程序

液晶屏为LM6065,控制芯片为RA8802。
最基本的显示程序,显示一行字:
"型号:LM6065    芯片:RA8802  "

使用P2端口作为数据口,P0的5个脚作为控制口,需要注意的是,P0端口需要加上拉电阻。

 

#include  < regX52.h >
#include 
< intrins.h >

#define  uchar unsigned char  //  0~255
#define  uint unsigned int      //  0~65535    

#define  _LED0    P0_0
#define  _LED1    P0_1

#define  lcd_bus P2

#define  _RST     P0_2
#define  _WR     P0_3
#define  _RD     P0_4 
#define  _CS     P0_5
#define  _FS        P0_6

//  厂家: http://www.topwaydisplay.com     型号:LM6065     芯片:RA8802
uchar code logo[] = {"型号:LM6065    芯片:RA8802  "} ;

// ====================================================================
//  写命令
// ====================================================================
void  display_command_sent(uchar command)
{   
        _WR 
= 1;
        _FS 
= 0;
        lcd_bus 
= command;
        _CS 
= 0;
        _nop_();
        _WR 
= 0;
        _nop_();
        _WR 
= 1;
        _nop_();
        _CS 
= 1;  
        _nop_(); _nop_();
        _nop_(); _nop_();
        _nop_(); _nop_();
        _nop_(); _nop_(); 
        _nop_(); _nop_();
}


// ====================================================================
//  写数据
// ====================================================================
void  display_data_sent(uchar disdata)
{  
        _WR 
= 1;
        _FS 
= 1;
        lcd_bus 
= disdata;
        _CS 
= 0;
        _nop_();
        _WR 
= 0;
        _nop_();
        _WR 
= 1;
        _nop_();
        _CS 
= 1;  
        _nop_(); _nop_();
        _nop_(); _nop_();
        _nop_(); _nop_();
        _nop_(); _nop_(); 
        _nop_(); _nop_(); 
}
 

// ====================================================================
//  清屏
// ====================================================================
void  LCD_clean( void )
{
    
uint i,j;
    display_command_sent(
0x60);display_command_sent(0x00);
    display_command_sent(
0x70);display_command_sent(0x00);
    
for(i = 0;i<64; i++)
    
{
        
for(j = 0;j < 30; j++
        display_data_sent(
0x00);
    }

}


void  delay_ms(unsigned  int  m)         //  11.0592MHz晶振,1.0us周期
{
    unsigned 
int j;
    unsigned 
int i;

    
for(i=0;i<m;i++)
        
for(j=0;j<109;j++);
}


// =====================================================================
//  初始化
// =====================================================================
void  LCD_mode_set( void )
{   
    _RST 
= 1;
    _RST 
= 0;
    delay_ms(
500);
    _RST 
= 1;
    delay_ms(
200); 
    
    
    display_command_sent(
0x00);display_command_sent(0xcd);  //LCD控制寄存器
    display_command_sent(0x08);display_command_sent(0x73);  //通用寄存器
    display_command_sent(0x10);display_command_sent(0xe9);  //光标控制寄存器
    display_command_sent(0x18);display_command_sent(0x20);  //光标大小控制寄存器
    display_command_sent(0x20);display_command_sent(0x1d);  //工作窗右边界寄存器
    display_command_sent(0x28);display_command_sent(0x1d);  //显示窗右边界寄存器
    display_command_sent(0x30);display_command_sent(0x3f);  //工作窗底部边界寄存器
    display_command_sent(0x38);display_command_sent(0x3f);  //显示窗底部边界寄存器
    display_command_sent(0x40);display_command_sent(0x00);  //工作窗左边界寄存器
    display_command_sent(0x50);display_command_sent(0x00);  //工作窗顶部边界寄存器
    display_command_sent(0x48);display_command_sent(0x00);  //显示窗左边界寄存器
    display_command_sent(0x58);display_command_sent(0x00);  //显示窗顶部边界寄存器
    display_command_sent(0x60);display_command_sent(0x00);  //X方向光标寄存器
    display_command_sent(0x70);display_command_sent(0x00);  //Y方向光标寄存器
    display_command_sent(0x80);display_command_sent(0x23);  //闪烁时间寄存器
    display_command_sent(0x90);display_command_sent(0x3e);  //移位时钟控制寄存器
    display_command_sent(0xe0);display_command_sent(0x00);  //数据模式寄存器
    display_command_sent(0xf0);display_command_sent(0xa0);  //字体控制寄存器
    delay_ms(20);
}
 
// ========================================================================
//  初始化,闪亮LED
// ========================================================================
void  initport( void )
{
    uchar i;
    
for(i=0; i<20; i++)
    
{
        _LED0 
= ~_LED0;
        delay_ms(
100);
    }

    _LED1 
= 0;

    _CS 
= 1;
    _RD 
= 1;
    _WR 
= 1;
    _FS 
= 1
    lcd_bus 
= 0xff;      
}


// ========================================================================
//  LCD显示LOGO
// ========================================================================
uchar code  * txtdata;
void  LOGO_display( void )
{
    uchar i,j,tempdata;
    txtdata 
= &logo[0];
    display_command_sent(
0x60);display_command_sent(0x00);
    display_command_sent(
0x70);display_command_sent(0x00);
    display_command_sent(
0x00);display_command_sent(0xcd);
    
    
for(j = 0;j < 1; j++)
    
{
        
for(i = 0;i < 30; i++)
        
{
            tempdata 
= (*(txtdata+(j*30)+i));
            display_data_sent(tempdata); 
        }
 
    }
  
}


// =====================================================================
//  主程序
// =====================================================================
void  main( void )
{   
  initport( );
  LCD_mode_set( );
  LCD_clean( );
  
while(1)
  
{
      LOGO_display( );
    delay_ms(
2000);
  }

}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值