LCD的Pic16f1829接口问题

时间:2018-11-06 00:59:25

标签: c interface microcontroller pic lcd

您好,我想将LCD与PIC控制器接口,我的代码可以很好地编译,但是屏幕什么也没显示,只有第五格偶尔闪烁,我正在使用MPLAB X IDE并通过XC8进行了编译。 1.- LCD的标题代码

    void Lcd_Port(char a)
    {
        if (a & 1)
            D4 = 1;
        else
            D4 = 0;
        if (a & 2)
            D5 = 1;
        else
            D5 = 0;
        if (a & 4)
            D6 = 1;
        else
            D6 = 0;
        if (a & 8)
            D7 = 1;
        else
           D7 = 0;
    }

    void Lcd_Cmd(char a)
    {
        RS = 0;             // D0 to D7 interpreted as 
        Lcd_Port(a);
        EN  = 1;            // LCD Enable
        __delay_ms(4);
        EN  = 0;             // LCD Disable
        a = a<<4   
        Lcd_Port(a);
        EN  = 1;            // LCD Enable
        __delay_ms(4);
        EN  = 0;             // LCD Disable
    }

    Lcd_Clear()
    {
        Lcd_Cmd(0);
        Lcd_Cmd(1);
    }

    void Lcd_Set_Cursor(char a, char b)
    {
        char temp,z,y;
        if (a == 1)
        {
            temp = 0x80 + b - 1;
             z = temp>>4;
             y = temp & 0x0F;
             Lcd_Cmd(z);
             Lcd_Cmd(y);
         }
         else if (a == 2)
         {
             temp = 0xC0 + b - 1;
             z = temp>>4;
             y = temp & 0x0F;
             Lcd_Cmd(z);
             Lcd_Cmd(y);
         }
     }

     void Lcd_Init()
     {
         Lcd_Port(0x00);
         __delay_ms(20);
         Lcd_Cmd(0x03);
         __delay_ms(5);
         Lcd_Cmd(0x03);
         __delay_ms(11);
         Lcd_Cmd(0x03);
         Lcd_Cmd(0x02);
         Lcd_Cmd(0x02);
         Lcd_Cmd(0x08);
         Lcd_Cmd(0x00);
         Lcd_Cmd(0x0C);
         Lcd_Cmd(0x00);
         Lcd_Cmd(0x06);
     }

     void Lcd_Write_Char(char a)
     {
         RS = 1;
         char temp,y;
         temp = a&0x0F;
         y = a&0xF0;
         RS = 1;             // D to D7 interpreted as 
         Lcd_Port(y>>4);     //Data transfer
         EN = 1;
         __delay_us(40);
         EN = 0;
         Lcd_Port(temp);
         EN = 1;
         __delay_us(40);
         EN = 0;
     }

     void Lcd_Write_String(char *a)
     {
         int i;
         for (i=0; a[i]!='\0'; i++)
             Lcd_Write_Char(a[i]);
     }

不确定这最后一部分

    void Lcd_Shift_Right()
    {
        Lcd_Cmd(0x01);
        Lcd_Cmd(0x0C);
    }

    void Lcd_Shift_Left()
    {
        Lcd_Cmd(0x01);
        Lcd_Cmd(0x08);
    }

我确定问题出在头文件中,因为所有内容均正确连接,并且代码编译没有问题。 我试图弄清楚延迟和频率,我问我的教授,他说问题可能与位的顺序有关,尽管我不太确定那是怎么回事。 帮助将不胜感激

0 个答案:

没有答案