打印

PIC18F25驱动ST7920 LCD,问题求救

[复制链接]
2789|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
busdriver|  楼主 | 2012-9-24 13:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 busdriver 于 2012-9-24 13:13 编辑

LCD型号:LM16032DDC-0B-01,内置ST7920控制芯片
问题:LCD始终不现实。
原理图,代码,LCD资料如附件。
请懂行的朋友提供支持,谢谢!

//LCD macio define
#define LCD_RS RB5
#define LCD_RW RB4
#define LCD_EN RB3

unsigned char LcdDataOut;

void delay5ms (void) //delay about 5ms
{
    unsigned char i, j, k;

    for (i = 0; i < 14; i++)
        for (j = 0; j < 25; j++)
            for (k = 0; k < 8; k++);
}


void delay300ms (void) //delay about 300ms
{
    unsigned char i, j, k;

    for (i = 0; i < 140; i++)
        for (j = 0; j < 150; j++)
            for (k = 0; k < 8; k++);
}



void SetDatabusDirection (unsigned char direction)
{
    if (direction == 0xff) //input
    {
        TRISA0 = 1;//RA0 is configed as input,MCU_LCD_DB4
        PCFG0 = 1;
        TRISA1 = 1;//RA1 is configed as input,MCU_LCD_DB5
        PCFG1 = 1;
        TRISA2 = 1;//RA2 is configed as input,MCU_LCD_DB6
        PCFG2 = 1;
        TRISA3 = 1;//RA3 is is configed as input,MCU_LCD_DB7
        PCFG3 = 1;
    }
    else if (direction == 0x00) //output
    {
        TRISA0 = 0;//RA0 is configed as output,MCU_LCD_DB4
        PCFG0 = 1;
        TRISA1 = 0;//RA1 is configed as output,MCU_LCD_DB5
        PCFG1 = 1;
        TRISA2 = 0;//RA2 is configed as output,MCU_LCD_DB6
        PCFG2 = 1;
        TRISA3 = 0;//RA3 is is configed as output,MCU_LCD_DB7
        PCFG3 = 1;
    }
}


//-------------------------------------------------------------------------------
//unsigned char lcdrd(void).
//function:read data
//-------------------------------------------------------------------------------
unsigned char lcdrd (void)
{
    unsigned char d;
    lcdwaitidle();
    SetDatabusDirection (0xff);//input
    LCD_RS = 1;//RS=1
    LCD_RW = 1;//RW=1
    LCD_EN = 1;//E=1
    //NOP();
    //d = P1;
    //d = getdata();
    d = PORTA;
    d <<= 4;
    d |= PORTA;
    LCD_EN = 0;
    //SetDatabusDirection (0x00);
    delay5ms();
    return d;
}

//-------------------------------------------------------------------------------
//void lcdwd(unsigned char d).
//function:write data
//-------------------------------------------------------------------------------
void lcdwd (unsigned char d)
{
    lcdwaitidle();
    //P1 = d;
    SetDatabusDirection (0x00);//output
    LCD_RS = 1;//RS=1
    LCD_RW = 0;//RW=0
    LCD_EN = 0;//E=0
    //senddata (d);
    PORTA = d/16;
    NOP();
    NOP();
    PORTA = d%16;
    NOP();
    NOP();
    LCD_EN = 1;//E=1
    NOP();
    NOP();
    LCD_EN = 0;
    delay5ms();
}

TDC_LCD_V1_1_(.pdf

41.28 KB

LM16032DDC-0B-01-Manual-Rev0.2.pdf

218.25 KB

沙发
兰天白云| | 2012-9-25 14:54 | 只看该作者
我只能给你一个查问题的思路
1、查一下硬件,每个引脚是否正确?
2、背光是否有?
3、用最简单的,把整屏都显示和不显示
4、随便给一些数据,看屏上是否会出现小点

使用特权

评论回复
板凳
NE5532| | 2012-9-25 19:36 | 只看该作者
鬼影出来了没有?背光可以不要,不影响显示。

使用特权

评论回复
地板
busdriver|  楼主 | 2012-9-25 22:29 | 只看该作者
回复楼上,鬼影没有啊
引脚绝对正确
有强烈的背光,刺眼
鬼影都没有,谈何数据啊。
我郁闷啊

使用特权

评论回复
5
busdriver|  楼主 | 2012-9-25 22:30 | 只看该作者
再次把程序贴出来,请高手帮忙分析分析。谢谢!

void SetDBDirection (unsigned char direction)
{
    if (direction == 0xff) //input
    {
        TRISA0 = 1;//RA0 is configed as output,MCU_LCD_DB3
        PCFG0 = 1;
        TRISA1 = 1;//RA1 is configed as output,MCU_LCD_DB4
        PCFG1 = 1;
        TRISA2 = 1;//RA2 is configed as output,MCU_LCD_DB5
        PCFG2 = 1;
        TRISA3 = 1;//RA3 is is configed as output,MCU_LCD_DB6
        PCFG3 = 1;
        //TRISA5 = 1;//RA5 is is configed as output,MCU_LCD_DB7
        //PCFG4 = 1;
        //LATB = 0xff;
        //TRISB0 = 1;//RB0 is configed as output,MCU_LCD_DB2
        //PCFG12 = 1;
        //TRISB1 = 1;//RB1 is configed as output,MCU_LCD_DB1
        //PCFG10 = 1;
        //TRISB2 = 1;//RB2 is configed as output,MCU_LCD_DB0
        //PCFG8 = 1;
    }
    else if (direction == 0x00) //output
    {
        TRISA0 = 0;//RA0 is configed as output,MCU_LCD_DB3
        PCFG0 = 1;
        TRISA1 = 0;//RA1 is configed as output,MCU_LCD_DB4
        PCFG1 = 1;
        TRISA2 = 0;//RA2 is configed as output,MCU_LCD_DB5
        PCFG2 = 1;
        TRISA3 = 0;//RA3 is is configed as output,MCU_LCD_DB6
        PCFG3 = 1;
        //TRISA5 = 0;//RA5 is is configed as output,MCU_LCD_DB7
        //PCFG4 = 1;
        //LATB = 0xff;
        //TRISB0 = 0;//RB0 is configed as output,MCU_LCD_DB2
        //PCFG12 = 1;
        //TRISB1 = 0;//RB1 is configed as output,MCU_LCD_DB1
        //PCFG10 = 1;
        //TRISB2 = 0;//RB2 is configed as output,MCU_LCD_DB0
        //PCFG8 = 1;
    }
}


//-------------------------------------------------------------------------------
//lcdwc(unsigned char c).
//function:write instruction
//-------------------------------------------------------------------------------
void lcdwc (unsigned char c)
{
    //lcdwaitidle();
    SetDBDirection (0x00);
    LCD_RS = 0;//RS=0
    LCD_RW = 0;//RW=0
    LCD_EN = 0;//E=0
   
    DBHighByte = c/16;
    DBLowByte = c%16;
   
    PORTA &= 0xf0;//
    PORTA |= DBHighByte;
    LCD_EN = 1;//E=1
    NOP();
    NOP();
    LCD_EN = 0;//E=0
   
    PORTA &= 0xf0;//
    PORTA |= DBLowByte;
    LCD_EN = 1;//E=1
    NOP();
    NOP();
    LCD_EN = 0;
    delay5ms();
}


//-------------------------------------------------------------------------------
//lcdwc8(unsigned char c).
//function:write instruction
//-------------------------------------------------------------------------------
void lcdwc8 (unsigned char c)
{
    //lcdwaitidle();
    SetDBDirection (0x00);
    LCD_RS = 0;//RS=0
    LCD_RW = 0;//RW=0
    LCD_EN = 0;//E=0
   
    DBHighByte = c/16;
    DBLowByte = c%16;
   
    PORTA &= 0xf0;//
    PORTA = DBHighByte;
    //NOP();
    //NOP();
    //PORTA |= DBLowByte;
    NOP();
    NOP();
    LCD_EN = 1;//E=1
    NOP();
    NOP();
    LCD_EN = 0;
    delay5ms();
}


//-------------------------------------------------------------------------------
//void lcdreset(void)
//function:LCD controller init
//-------------------------------------------------------------------------------
void lcdreset (void)                    //LCD controller init
{
    delay300ms();
    delay300ms();
    delay300ms();
    newline();
    puts ("initializing LCD controller...", 0);
    //lcdwc (0x30);//function set:8 bit interface,basic instruction
    lcdwc8 (0x30);//function set: 8 bit interface,basic instruction
    lcdwc8 (0x30);//function set: 8 bit interface,basic instruction
    lcdwc (0x20);//function set: 4 bit interface,basic instruction
    delay5ms();
    //lcdwc (0x30);//function set:8 bit interface,basic instruction
    lcdwc (0x20);//function set:4 bit interface,basic instruction
    delay5ms();
    lcdwc (0x06);//I/D=1,cursor move right,AC  increase by 1;S=0,no toggle
    delay5ms();
    lcdwc (0x0f);//D=1,display on;C=1,cursor on;B=0,blink off
    //lcdon();//D=1,display on;C=1,cursor on;B=0,blink off
    delay5ms();
    //lcdon();//D=1,display on;C=0,cursor off;B=0,blink off
    lcdwc (0x01);//clear
    delay5ms();
    delay5ms();
    lcdwc (0x02);//set cursor to home
    delay5ms();
    lcdwc (0x80);//set DDRAM address as 0x00
    //delay5ms();
    //lcdwd ('a');
    //lcdwd ('a');
    //delay5ms();
    puts ("done!", 0);
}

使用特权

评论回复
6
airwill| | 2012-9-26 06:36 | 只看该作者
记得还有那个好象是 V0 脚, 调整对比度的.
通过电位器调节到适当位置, 才有好的显示.
我试的结果: 调出不多就会"鬼影都没有"

使用特权

评论回复
7
NE5532| | 2012-9-26 12:49 | 只看该作者
鬼影没有肯定没显示,而且不是程序的问题。

使用特权

评论回复
8
busdriver|  楼主 | 2012-10-13 09:21 | 只看该作者
问题检查出来了。硬件对比度部分接线错误,电位器不应该接地,至V0电压不足。谢谢 大家的回复!

使用特权

评论回复
9
兰天白云| | 2012-10-13 15:10 | 只看该作者
这种属低级错误,有时候这种问题会郁闷死21高手

使用特权

评论回复
10
ZRL700424| | 2012-10-13 15:59 | 只看该作者
回复楼上
引脚绝对正确
busdriver 发表于 2012-9-25 22:29


:L

使用特权

评论回复
11
busdriver|  楼主 | 2012-10-15 14:13 | 只看该作者
惭愧惭愧啊。
呵呵,当初只关注数据线,控制线了。没想到对比度电位器的连接问题。

使用特权

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

本版积分规则

44

主题

416

帖子

0

粉丝