打印

达人留步,液晶屏问题,急!!

[复制链接]
1825|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
szzghmcu|  楼主 | 2007-9-2 17:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
高建明| | 2007-9-2 20:09 | 只看该作者

12864的,可那个对你有帮助,我是直接在RAM开辟了一个显示缓存

/*MEGA128L 总线LCM12864调试*/


#include <avr/io.h>
#include <avr/pgmspace.h>
#define set_bit(sfr,bit) (sfr|=(1<<bit))
#define clr_bit(sfr,bit) (sfr&=~(1<<bit))
#define get_bit(sfr,bit) (sfr&(1<<bit))

#define LCM_DI    3
#define LCM_RW    4
#define LCM_E    5
#define LCM_CS1    6
#define LCM_CS2    7
#define LCM_DATA    PORTA
#define LCM_CONTROL    PORTD


//LCM缓存区
volatile static unsigned char lcm_buffer[8][128];

//LCM开机**
/*--  宽度x高度=128x64  --*/
const unsigned char PROGMEM lcm_**[]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0xCF,0x1F,0x7F,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x8F,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0x07,0xF7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x7F,0x3F,0x0F,0xC7,0xEF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x7F,0x3F,0xBF,0x9F,0xDF,0xDF,0xEF,0xEF,0xE7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF3,
0xF3,0xF7,0xF7,0x77,0xF7,0xF7,0xF7,0xF7,0xEF,0xEF,0xE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0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFE,0xFC,0xFD,0xF9,0xFB,0xFB,0xF7,0xF7,0xF7,0xE7,0xE7,0xEF,0xEF,0xEF,0xEF,
0xEF,0xEF,0xEF,0xEF,0xEF,0xE7,0xF7,0xF7,0xF7,0xF3,0xFB,0xFB,0xFD,0xFD,0xFE,0xFE,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
};



const unsigned char PROGMEM lcm_chinese_CCFB5[]={
/*系   CCFB5 */
0x00,0x00,0x02,0x22,0xB2,0xBA,0xEE,0x66,0x62,0x33,0x5D,0xCD,0x81,0x01,0x01,0x00,
0x00,0x40,0x61,0x33,0x1B,0x0D,0x45,0xC1,0xFF,0x7F,0x05,0x0D,0x1B,0x73,0x62,0x00,
};
const unsigned char PROGMEM lcm_chinese_CCDB3[]={
/*统   CCDB3 */
0x20,0x30,0x3C,0xAF,0xE3,0x70,0x94,0xC4,0xE4,0xBD,0x9F,0x86,0xA4,0xE4,0xC4,0x84,
0x20,0x22,0x23,0x33,0x12,0x92,0xD2,0x70,0x3F,0x0F,0x00,0x3F,0x7F,0x41,0x71,0x70,
};
const unsigned char PROGMEM lcm_chinese_CD7D4[]={
/*自   CD7D4 */
0x00,0x00,0x00,0xF8,0xF8,0x48,0x4C,0x4F,0x4B,0x4A,0x48,0x48,0xF8,0xF8,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0xFF,0x00,0x00,
};
const unsigned char PROGMEM lcm_chinese_CBCEC[]={
/*检   CBCEC */
0x08,0x88,0xE8,0xFF,0xFF,0x68,0x58,0x58,0x4C,0x47,0x47,0x4C,0x58,0x50,0x10,0x10,
0x02,0x03,0x01,0x7F,0x7F,0x20,0x22,0x2E,0x2D,0x2F,0x3E,0x38,0x2F,0x27,0x22,0x20,
};
const unsigned char PROGMEM lcm_chinese_CD6D0[]={
/*中   CD6D0 */
0x00,0x00,0xFC,0xFC,0x08,0x08,0x08,0xFF,0xFF,0x08,0x08,0x08,0xFC,0xFC,0x08,0x00,
0x00,0x00,0x07,0x07,0x02,0x02,0x02,0xFF,0xFF,0x02,0x02,0x02,0x07,0x07,0x00,0x00,
};
const unsigned char PROGMEM lcm_chinese_CA1A4[]={
/*·   CA1A4 */
0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0xE0,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};




//函数声明
void init_io(void);
unsigned char read_state(void);
void write_command(unsigned char temp);
unsigned char read_data(unsigned char temp_cs);
void write_data(unsigned char temp,unsigned char temp_cs);
unsigned char judge_busy(void);
void lcm_clear(void);
void lcm_check(void);
void lcm_buffer_clear(void);
void lcm_buffer_check(void);
void lcm_scan(void);

void lcm_buffer_chinese(void);

void lcm_buffer_**(void);

//主函数
int main(void)
{
    init_io();
//    lcm_check();
//    lcm_clear();

//    test_check();

    lcm_buffer_check();
    lcm_scan();
    lcm_buffer_clear();
    lcm_scan();
    lcm_buffer_**();
    lcm_scan();
    lcm_buffer_clear();
    lcm_scan();
    lcm_buffer_chinese();
    lcm_scan();

//    lcdStartLine(0);
//    lcdSetPage(0);
//    lcdSetRow(0);
//    pixel(30,30);
//    pixel(100,50);
//    pixel(15,40);
    while(1)
    {
    }
    return 0;
}


//初始化IO
void init_io(void)
{
    PORTA=0xff;
    DDRA=0xff;
    PORTC=0xff;
    DDRC=0xff;
    PORTD=0xff;
    DDRD=0xff;
    PORTG=0xff;
    DDRG=0xff;

    PORTB=0XFF;
    DDRB=0XFF;
}

//读LCM状态
unsigned char read_state(void)
{
    PORTA=0xff;
    DDRA=0x0;
    clr_bit(LCM_CONTROL,LCM_CS1);
    clr_bit(LCM_CONTROL,LCM_CS2);
    clr_bit(LCM_CONTROL,LCM_DI);
    set_bit(LCM_CONTROL,LCM_RW);
    set_bit(LCM_CONTROL,LCM_E);            //下降沿锁存数据
    clr_bit(LCM_CONTROL,LCM_E);
    return PINA;
}

//写LCM命令
void write_command(unsigned char temp)
{
    PORTA=0xff;
    set_bit(LCM_CONTROL,LCM_CS1);
    set_bit(LCM_CONTROL,LCM_CS2);
    clr_bit(LCM_CONTROL,LCM_DI);
    clr_bit(LCM_CONTROL,LCM_RW);
    LCM_DATA=temp;
    set_bit(LCM_CONTROL,LCM_E);            //下降沿锁存数据
    clr_bit(LCM_CONTROL,LCM_E);

}

//读LCM数据
unsigned char read_data(unsigned char temp_cs)
{
    PORTA=0xff;
    DDRA=0x0;
    if(temp_cs==0)
    {    //选择左半屏
    set_bit(LCM_CONTROL,LCM_CS1);
    clr_bit(LCM_CONTROL,LCM_CS2);
    }
    else if(temp_cs==1)
    {    //选择右半屏
    clr_bit(LCM_CONTROL,LCM_CS1);
    set_bit(LCM_CONTROL,LCM_CS2);
    }
    else
    {    //不选择
    clr_bit(LCM_CONTROL,LCM_CS1);
    clr_bit(LCM_CONTROL,LCM_CS2);
    }
    set_bit(LCM_CONTROL,LCM_DI);
    set_bit(LCM_CONTROL,LCM_RW);
    set_bit(LCM_CONTROL,LCM_E);            //下降沿锁存数据
    clr_bit(LCM_CONTROL,LCM_E);
    return PINA;
}

//写LCM数据
void write_data(unsigned char temp,unsigned char temp_cs)
{
    PORTA=0xff;
    if(temp_cs==0)
    {    //选择左半屏
    set_bit(LCM_CONTROL,LCM_CS1);
    clr_bit(LCM_CONTROL,LCM_CS2);
    }
    else if(temp_cs==1)
    {    //选择右半屏
    clr_bit(LCM_CONTROL,LCM_CS1);
    set_bit(LCM_CONTROL,LCM_CS2);
    }
    else
    {    //不选择
    clr_bit(LCM_CONTROL,LCM_CS1);
    clr_bit(LCM_CONTROL,LCM_CS2);
    }
    set_bit(LCM_CONTROL,LCM_DI);
    clr_bit(LCM_CONTROL,LCM_RW);
    LCM_DATA=temp;
    set_bit(LCM_CONTROL,LCM_E);            //下降沿锁存数据
    clr_bit(LCM_CONTROL,LCM_E);
}

//LCM判忙
unsigned char judge_busy(void)
{
    unsigned char temp;
    temp=read_state();
    if(temp&0x80)
    {    //忙
        return 1;
    }
    else
    {    //空闲
        return 0;
    }

}

/*
//LCM校验
void lcm_check(void)
    {
    unsigned char i,j;
    write_command(0x3e);//关显示
    write_command(0xc0);//设置显示起始行
    for(i=0;i<8;i++)
        {
        write_command(0xb8+i);//设置X地址
        write_command(0x40);//设置Y地址
        for(j=0;j<64;j++)
            {
            write_data(0xff,0);//写数据CS1
            }
        write_command(0x40);//设置Y地址
        for(j=0;j<64;j++)
            {
            write_data(0xff,1);//写数据CS2
            }
        }
    write_command(0x3f);//开显示
    }

//清屏
void lcm_clear(void)
    {
    unsigned char i,j;
    write_command(0x3e);//关显示
    write_command(0xc0);//设置显示起始行
    for(i=0;i<8;i++)
        {
        write_command(0xb8+i);//设置X地址
        write_command(0x40);//设置Y地址
        for(j=0;j<64;j++)
            {
            write_data(0x00,0);//写数据CS1
            }
        write_command(0x40);//设置Y地址
        for(j=0;j<64;j++)
            {
            write_data(0x00,1);//写数据CS2
            }
        }
    write_command(0x3f);//开显示
    }
*/

//清显示缓存
void lcm_buffer_clear(void)
    {
    unsigned char i,j;
    for(i=0;i<8;i++)
        {
        for(j=0;j<128;j++)
            {
            lcm_buffer[j]=0;
            }
        }
    }

//置显示缓存
void lcm_buffer_check(void)
    {
    unsigned char i,j;
    for(i=0;i<8;i++)
        {
        for(j=0;j<128;j++)
            {
            lcm_buffer[j]=0xff;
            }
        }
    }

//LCM扫描
void lcm_scan(void)
    {
    unsigned char i,j;
    write_command(0xc0);//设置显示起始行
    write_command(0x3f);//开显示
    for(i=0;i<8;i++)
        {
        write_command(0xb8+i);//设置X地址
        write_command(0x40);//设置Y地址
        for(j=0;j<64;j++)
            {
            write_data(lcm_buffer[j],0);//写数据CS1
            }
        write_command(0x40);//设置Y地址
        for(j=0;j<64;j++)
            {
            write_data(lcm_buffer[j+64],1);//写数据CS2
            }
        }

    }

//显示**
void lcm_buffer_**(void)
    {
    unsigned char i,j;
    unsigned int k;
    for(k=0,i=0;i<8;i++)
        {
        for(j=0;j<128;j++,k++)
            {
            lcm_buffer[j]=pgm_read_byte(lcm_**+k); 
            }
        }
    }






//LCM写汉字
void lcm_buffer_chinese(void)
    {
    unsigned char i,j;
    unsigned int k;
    //
    for(k=0,i=0;i<2;i++)
        {
        for(j=0;j<16;j++,k++)
            {
            lcm_buffer[j]=pgm_read_byte(lcm_chinese_CCFB5+k);
            }
        }
    //

    }



使用特权

评论回复
板凳
szzghmcu|  楼主 | 2007-9-2 22:07 | 只看该作者

谢谢高大哥!

使用特权

评论回复
地板
walnutcy| | 2007-9-4 22:47 | 只看该作者

我用的和你一样,显示乱码若软件无误,则硬件线反,

否则可能是你把图片区与文字区重叠起来了,,

做了或操作,,

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

15

主题

37

帖子

1

粉丝