狂人呓语

LCD12864液晶显示屏驱动程序-Atmega16驱动

编译环境:GCC+AVR Studio
晶体:12Mhz
编译环境:GCC+AVR Studio
晶体:12Mhz

#include "util/delay.h"
/*

    数据口:PB
    RS        PD3
    R/W        PD4
    EN        PD6
    PSB        PC6
    NC
    RST        PD7
*/

#define LCD_RS_H    PORTD |= BIT(3)        //H:数据模式
#define LCD_RS_L    PORTD &= ~BIT(3)    //L:命令模式

#define LCD_RW_H PORTD |= BIT(4)        //H:读
#define LCD_RW_L PORTD &= ~BIT(4)        //L:写

#define LCD_EN_H PORTD |= BIT(6)
#define LCD_EN_L PORTD &= ~BIT(6)

#define LCD_PSB_H PORTC |= BIT(6)
#define LCD_PSB_L PORTC &= ~BIT(6)

#define LCD_RST_H PORTD |= BIT(7)
#define LCD_RST_L PORTD &= ~BIT(7)

#define LCD_DB PORTB

#define LCD_DB_IN    DDRB=0x00        //输入模式
#define LCD_DB_OUT    DDRB=0xFF        //输出模式


void init_LCD12864()    //初始化LCD12864
{
    _delay_ms(10);
    DDRB = 0xFF;    //输出
    DDRD = 0xFF;
    DDRC = 0xFF;
    LCD_PSB_H;        //并行模式
    LCD_RST_L;
    _delay_ms(10);
    LCD_RST_H;
    LCD_Cmd(0x30);        //基本指令集
    LCD_Cmd(0x0C);        //开显示
    LCD_Cmd(0x01);        //清屏
}

void check_busy()
{
    uchar tmp;
    LCD_RS_L;
    LCD_RW_H;
    LCD_DB_IN;
    do{
        LCD_EN_H;
        //_delay_us(1);
        LCD_EN_L;        
        tmp=PINB;    //读PB口
    }while(tmp & 0x80);
    LCD_DB_OUT;
}

void LCD_Cmd(uchar cmd)
{
    check_busy();
    LCD_RS_L;
    LCD_RW_L;
    LCD_EN_H;
    LCD_DB=cmd;
    //_delay_us(1);
    LCD_EN_L;
}

void LCD_Data(uchar szData)
{
    check_busy();
    LCD_RS_H;
    LCD_RW_L;
    LCD_EN_H;
    LCD_DB=szData;
    //_delay_us(1);
    LCD_EN_L;
}

void Disp_ch(char sz,int pos)
{
    if(pos<0x80)
    {
        switch(pos)
        {
            case 1:
                pos=0x80;break;
            case 2:
                pos=0x90;break;
            case 3:
                pos=0x88;break;
            case 4:
                pos=0x98;break;
        }
    }
    
    LCD_Cmd(pos);
    LCD_Data(sz);
}

Disp_str(char *array,int pos)
{
    if(pos<0x80)
    {
        switch(pos)
        {
            case 1:
                pos=0x80;break;
            case 2:
                pos=0x90;break;
            case 3:
                pos=0x88;break;
            case 4:
                pos=0x98;break;
        }
    }
    LCD_Cmd(pos);
    while(*array>0)
    {
        LCD_Data(*array);
        array++;
    }
}
未经允许不得转载:狂人呓语 » LCD12864液晶显示屏驱动程序-Atmega16驱动

评论 2

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. Hоw to eаrn оn Forex dо nоt hаvе аdequаtе eхperiencе!?!? ... It appеars vеry simрlе! Just usе thе sеrviсе аutоmatiсаlly cору thе tradеs оf suсcеssful tradеrs trаdе - http://tinyurl.com/yayy28jq
    https://www.tinyurl.com/yayy28jq

    PhileSniple (2020-09-27) 回复
  2. How to еаrn оn Forex dо not have adеquate еxpеriеncе!?!? ... It аppеars vеry simрlе! Just use the sеrvicе аutomaticаlly сoрy the trаdes of successful trаders tradе - https://tinyurl.com/yayy28jq
    http://www.copyfx.com/?a=kkw

    Vaniinfenty (2020-10-23) 回复