LCD 8位模式到4位模式

时间:2008-10-30 00:50:21

标签: lcd color-depth

我们有一个字符LCD(www.cloverlcd.com/pdf/S6A0069.pdf),我们在8位模式下工作。但是,现在我们正试图让它在4位模式下工作,但它似乎没有显示任何内容。我认为没有编写函数集指令。有人可以检查一下我是否正确接近这个问题?我将发布我的8位代码(正在运行)和我的4位代码(我正试图开始工作)

     //8 bit working
    COMPortC(0x3C);     //function set                                          
    Delay1KTCYx(10);
    COMPortC(0x0F);     //Turn on display and configure cursor settings         
    Delay1KTCYx(10);
    COMPortC(0x01);     //clear display
    Delay1KTCYx(10);
    COMPortC(0x06);     //increment mode and increment direction (entry mode set)
    Delay1KTCYx(10);
    COMPortC(0x02);     //Return Home

       //4 bit
    COMPortC(0x20);     //function set                                          
    Delay1KTCYx(10);
    COMPortC(0x20);     //function set                                          
    Delay1KTCYx(10);
    COMPortC(0x80);     //function set                                          
    Delay1KTCYx(10);

    COMPortC(0x00);     //Turn on display and configure cursor settings         
    Delay1KTCYx(10);
    COMPortC(0xF0);     //Turn on display and configure cursor settings         
    Delay1KTCYx(10);

6 个答案:

答案 0 :(得分:1)

看起来没关系,但我想知道几件事情:

1 /为什么要输出0x20两次来设置4位部分的CGRAM地址?当然这只需要一次。

2 /其他两个写入(0x00和0xf0),我从文档中无法理解。你可以修改一下评论来表明他们打算做什么吗?

3 /切换到4位模式后,是否需要重做其他指令(增量并返回原点)?可能是切换模式会重置所有数据。

4 /我注意到的一件事是busy标志表示系统还没有收到另一条指令。可能是你过快地传递它们。当您将延迟从10增加到100时会发生什么。

只需要尝试一些事情 - 让我们知道结果。

=====

响应:

感谢您的回复

1和2)我正在根据数据表的第29页(www.cloverlcd.com/pdf/S6A0069.pdf)编写这些值。

3)你是对的,我也需要做其他指令但是现在,我只是试图让光标在4位模式下闪烁(所以前两条指令就足够了)

4)我刚刚尝试了100次延迟,但没有用。

对于不好的评论感到抱歉,下次我会尝试发布更好的代码。

由于

=====

编辑:

我现在看它是如何运作的。在4位模式下,它仅使用d7,d6,d5,d4,但每条指令都是2次写操作(用于制作8位指令)。因此,它使用一个技巧来写入指令20(在8位模式下)或22(在4位模式下的2020),这两个指令都将模式设置为4位。非常聪明,三星,我印象深刻。

尝试完成整个init序列。可能是在初始化完成之前显示器没有完全启动。

所以你需要输出(hex)20,20,80,00,f0, 00,10,00,60,00,20 。大胆的是你需要添加的。

此外,我还需要再提两个问题(请回复此答案,而不是发布另一个答案)

1 / COMPortC()在输出数据之前是否实际检查忙信号?

2 /延迟10,单位是什么,毫秒,微秒等?

答案 1 :(得分:1)

我不确定你的4位是如何连接起来的,但是我的猜测是....因为你在高位半字节上发送位(0x * 0 - 那里的星是),你可能想要使用较低或最低有效半字节,即0x0 *。

COMPortCWithoutBusy(0x02);      //function set first nibble                                     
Delay1KTCYx(10);
COMPortCWithoutBusy(0x02);      //function set second nibble                                    
Delay1KTCYx(10);
BusyEnable();
Delay1KTCYx(10);
...

答案 2 :(得分:0)

这是4位模式的更好的注释代码

    COMPortC(0x20);     //function set first nibble                                     
    Delay1KTCYx(10);
    COMPortC(0x20);     //function set second nibble                                    
    Delay1KTCYx(10);
    COMPortC(0x80);     //function set  third nibble                                        
    Delay1KTCYx(10);

    COMPortC(0x00);     //Turn on display and configure cursor settings first nibble
    Delay1KTCYx(10);
    COMPortC(0xF0);     //Turn on display and configure cursor settings second nibble
    Delay1KTCYx(10);

我仍然不知道出了什么问题。此外,在数据表的第18页,它显示的时序图几乎与8位模式的时序图相同,只是有一个AC3。 AC3意味着什么?

答案 3 :(得分:0)

void LCDInitialization(void)
{

    COMPortCWithoutBusy(0x20);      //function set first nibble                                     
    Delay1KTCYx(10);
    COMPortCWithoutBusy(0x20);      //function set second nibble                                    
    Delay1KTCYx(10);
    BusyEnable();
    Delay1KTCYx(10);

    COMPortCWithoutBusy(0x80);      //function set  third nibble                                        
    Delay1KTCYx(10);
    BusyEnable();
    Delay1KTCYx(10);

    COMPortCWithoutBusy(0x00);      //Turn on display and configure cursor settings first nibble
    Delay1KTCYx(10);
    COMPortCWithoutBusy(0xF0);      //Turn on display and configure cursor settings second nibble
    Delay1KTCYx(10);
    BusyEnable();
    Delay1KTCYx(10);

    COMPortCWithoutBusy(0x00);      //disp clear first nibble                                       
    Delay1KTCYx(10);
    COMPortCWithoutBusy(0x10);      //disp clear second nibble                                  
    Delay1KTCYx(10);
    BusyEnable();
    Delay1KTCYx(10);

    COMPortCWithoutBusy(0x00);      //entry mode set first nibble                                       
    Delay1KTCYx(10);
    COMPortCWithoutBusy(0x60);      //entry mode set second nibble                                  
    Delay1KTCYx(10);
    BusyEnable();
    Delay1KTCYx(10);

    COMPortCWithoutBusy(0x20);      //20 first nibble                                       
    Delay1KTCYx(10);
    BusyEnable();
    Delay1KTCYx(10);
}

答案 4 :(得分:0)

这只是HD44780 LCD驱动程序的另一种变体,因此它可以在以下初始化程序中正常工作:

void initlcd(void)
{
    delayms(20);    // Wait for LCD to power up ( >15ms )
    RS=0;       // Set RS low for instruction 
    write4(3);  // Set interface to 8 bits 
    delayms(5); // Wait for LCD execute instruction ( >4.1ms )
    write4(3);  // Set interface to 8 bits 
    delayms(1); // Wait for LCD execute instruction ( >100us )
    write4(3);  // Set interface to 8 bits 
    delayms(5);     // Wait for LCD execute instruction (At this point 
            // we could actually start using the busy flag) 
    write4(2);  // Set the display to 4 bit interface 
    delayms(5); // Wait for LCD execute instruction 
    write8(0x28);   // Set the display to two line and ???
    delayms(5); // Wait for LCD execute instruction 
    write8(6);  // ???
    delayms(5); // Wait for LCD execute instruction 
    write8(1);  // Clear the LCD
    delayms(5); // Wait for LCD execute instruction
    write8(0xf);    // ???
    delayms(5); // Wait for LCD execute instruction
    return;
}

您需要定义自己的write4,write8和delayms函数,但它们相对容易。确保将寄存器选择(RS)设置为命令模式。 write4发送一个4位命令,而写8连续发送两个四位命令,先是高半字节,然后是低半字节:

void write8(uns8 byte)
{
    uns8 nibble;
    nibble = (byte & 0xf0) >> 4;    // Rotate the high 4 bits (7-4) of byte into bits (3-0) of nibble
    write4(nibble);         // Write the high 4 bits to the LCD
    nibble = byte & 0xf;        // Copy the low four bits of byte into the low four bits of nibble
    write4(nibble);         // Write the low 4 bits to the LCD
}

我写的code用于PIC单片机,使用免费版本的cc5x编译器。应该是可以理解的,并且可以移植到其他语言。

初始化程序通过多年的LCD初始化大量借用了许多其他程序 - 找到并克服了HD44780和变体的各种怪癖。它应该适用于大多数类似的LCD。

答案 5 :(得分:-1)

1和2)我正在根据数据表的第29页(www.cloverlcd.com/pdf/S6A0069.pdf)编写这些值。

3)你是对的,我也需要做其他指令但是现在,我只是试图让光标在4位模式下闪烁(所以前两条指令就足够了)

4)我刚刚尝试了100次延迟,但没有用。