这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » LCD 帮我看看LCD为什么没显示

共3条 1/1 1 跳转至

LCD 帮我看看LCD为什么没显示

院士
2006-09-17 18:14:16     打赏
LCD 帮我看看LCD为什么没显示



关键词: 帮我     看看     为什么     显示    

院士
2006-12-22 22:43:00     打赏
2楼
问 128×64的LCD屏,搞了一天了,写了个简单的测试程序,大家帮我看看是不是程序的问题,实在是想不到什么会出问题。


#include "config.h"




//-------------------------------------------------------------------
//LCD Interface
//-------------------------------------------------------------------
#define LCD_DB       P0

sbit sbLCD_E     = P2^4;  // LCD使能
sbit sbLCD_RW    = P2^6;  // 1-读,0-写
sbit sbLCD_RS    = P2^7;  // 1-数据,0-指令
sbit sbLCD_CS1    = P2^3;  // 左半屏使能
sbit sbLCD_CS2     = P2^2;  // 右半屏使能




uint8 code hanzi[][16]={
//*取子方式:纵向,字节倒序*//

/*--  文字:  正  --*/
{0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0x02,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00},// 0
{0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x00},// 1
/*--  文字:  确  --*/
{0x00,0x84,0xE4,0x5C,0x44,0xC4,0x10,0xF8,0x97,0x92,0xF2,0x9A,0x96,0xF2,0x00,0x00},// 2
{0x01,0x00,0x3F,0x08,0x88,0x4F,0x30,0x0F,0x04,0x04,0x3F,0x44,0x84,0x7F,0x00,0x00},// 3
};

//-------------------------------------------------------------------
// 短延时
void Delay10ns(void)
{
    uint8  i;
    
       for(i=0; i<10; i++)
    {
        _nop_();
         _nop_();
       }
}

// 长延时
void Delay100ms(void)
{
    uint8 i = 0x50;
    uint8 j;

    do
    {
        i--;
        j=0xFD;

        do
        {
            _nop_();
            _nop_();

            j--;
        }while(j);

    }while(i);
}


// 等待左
void Wait1(void)
{
    uint8 readstatus;     

    LCD_DB=0xFF;       // P0口写1,确保输入数据的正确性
    sbLCD_CS1 = 1;    
    sbLCD_CS2 = 0;    
    sbLCD_RW = 1;     
    sbLCD_RS = 0;
    sbLCD_E = 1;

    do
    {
            
        readstatus = LCD_DB;  // 读状态
        _nop_();
        _nop_();
    }
    while (readstatus & 0x80);  // 若bit7不为0,则一直读状态
}


// 等待右
void Wait2(void)
{
    uint8 readstatus;

    P0=0xFF;
    sbLCD_CS1 = 0;
    sbLCD_CS2 = 1;
    sbLCD_RW = 1;
    sbLCD_RS = 0;
    sbLCD_E = 1;

    do
    {
            
        readstatus = LCD_DB;
        _nop_();
        _nop_();
    }
    while (readstatus & 0x80);
}


// 写左命令
void W_Com1(uint8 com)
{
     Wait1();
     sbLCD_RW = 0;
     sbLCD_RS = 0;

     LCD_DB = com;

     sbLCD_E = 1;   // 下降沿
     Delay10ns();
     sbLCD_E = 0;
}


// 写右命令
void W_Com2(uint8 com)
{
     Wait2();
     sbLCD_RW = 0;
     sbLCD_RS = 0;

     LCD_DB = com;

     sbLCD_E = 1;
     Delay10ns();
     sbLCD_E = 0;
}


// 写左数据
void W_Dat1(uint8 dat)
{
    Wait1();

    sbLCD_RW = 0;
    sbLCD_RS = 1;

    LCD_DB = dat;

    sbLCD_E = 1;
    Delay10ns();
    sbLCD_E = 0;
}



// 写右数据
void W_Dat2(uint8 dat)
{
    Wait2();

    sbLCD_RW = 0;
    sbLCD_RS = 1;

    LCD_DB = dat;

    sbLCD_E = 1;
    Delay10ns();
    sbLCD_E = 0;
}



// 定点纵向写一字节
// yPos为页寄存器地址(0-7)
// xPos为列(0-63)
void SetPos(uint8 yPos, uint8 xPos, uint8 value)
{
    yPos &= 0x07;  // yPos低3位有效
    yPos += 0xB8;  // B8为页起始地址设置

    if (xPos <= 63)
    {
        xPos &= 0x3F;  // xPos低6位有效
        xPos |= 0x40;  // 列起始地址设置

        W_Com1(xPos);
        W_Com1(yPos);
        W_Dat1(value);
    }
    else
    {
        xPos &= 0x3F;
        xPos |= 0x40;

        W_Com2(xPos);
        W_Com2(yPos);
        W_Dat2(value);
    }
}



// 全屏填充
void Fulfill(uint8 value)
{
    uint8 xPos;
    uint8 yPos;

    yPos = 0;

    do
    {
        xPos = 0;

        do
        {
            SetPos(yPos, xPos, value);
            xPos += 1;
            if (xPos == 128)
            {
                xPos = 0;
            }
        }
        while (xPos);

        yPos &= 0x07;
        yPos += 1;
        if (yPos == 0x08)
        {
            yPos = 0;
        }
    }
    while (yPos);
}



// 显示一16×16汉字
// type为非0时,显示16×16汉字
// yPos为第几行(0—7)
// xPos为第几列(0-63)
// value 为字模的序号
void Display_Data(uint8 type, uint8 yPos, uint8 xPos, uint8 value)
{
    uint8 a;
    uint8 b;
    uint8 i = 0;

    xPos *= 8;
    yPos *= 2;

    if (type)   // 写汉字
    {
        for (a=0; a<2; a++)   // 写上半部分,每个汉字2行
        {
            for (b=0; b<16; b++)   // 写横向
            {
                SetPos(yPos, xPos, hanzi[value][i]);
                i++;
                xPos++;
            }
            xPos -= 16;    //写一行起始地址
            yPos++;
        }
        yPos -= 2;         // 下一个字的起始地址
        xPos += 16;
        value += 1;
    }
}
        
                    
    
//-------------------------------------------------------------------
void main(void)
{
    uint8 i;

    for (i=0; i<10; i++)
    {
        Delay100ms();
    }

    Fulfill(0x00);    // 清屏
    
    for (i=0; i<10; i++)
    {
        Delay100ms();
    }
    Display_Data(1, 0, 0, 2);   // 在第0行第0列写汉字“确”
}
1: 自己顶个先~ 2: ~~~~~~~ 3: .会不会也是IO驱动问题?改成强推挽试试。 4: 测试时最好确保LCD引脚的接触是正常的 5: rt引脚接触都是正常的,也找人帮哦检查了下~
I0用P0也接了10K的上拉电阻了 6: 可以找厂家要一段测试程序的,一般他们都有我就试过这样的事情后来发觉还是程序问题,早点找他要就早点知道原因拉 7: 有个RST引脚要接高,或用IO控制下试试

高工
2022-08-19 22:50:16     打赏
3楼

学习


共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]