⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcddrive.c

📁 实现了dsPIC30f6012a通过SPC3与PLC通信
💻 C
字号:
#include "Headfiles.h"


void LCD_Write(unsigned char data)
{
    unsigned int tmp, tmp_1, tmp_2;

    while (PORTBbits.RB10 == 1);
    tmp = (PORTB & 0xFCC0);
    tmp_1 = data;
    tmp_2 = (tmp_1 & 0x003F) + ((tmp_1 << 2) & 0x0300);
    tmp |= tmp_2;
    LATB = tmp;
    
    _LATD4 = 1;

    while (PORTBbits.RB10 == 0);
    _LATD4 = 0;
}

void LCD_Ascii(unsigned char x, unsigned char y, unsigned char Code)
{
    LCD_Write(0xF9);
    LCD_Write(x);
    LCD_Write(y << 4);
    LCD_Write(Code);
}

void LCD_Character(unsigned char x, unsigned char y, unsigned char Code_HSB, unsigned char Code_LSB)
{
    LCD_Write(0xF0);
    LCD_Write(x >> 1);
    LCD_Write(y);
    LCD_Write(Code_HSB - 0xA0);
    LCD_Write(Code_LSB - 0xA0);
}
//--------------------------------------------------------------------------------------
void LCD_Horizontal_Line(unsigned char x_start, unsigned char x_end, unsigned char y)
{
    unsigned char tmp_x;
    
    for (tmp_x = x_start; tmp_x <= x_end; tmp_x++)
    {
        LCD_Write(0xF2);
        LCD_Write(tmp_x);
        LCD_Write(y);
    }
}

void LCD_Vertical_Line(unsigned char x, unsigned char y_start, unsigned char y_end)
{
    unsigned char tmp_y;

    for (tmp_y = y_start; tmp_y <= y_end; tmp_y++)
    {
        LCD_Write(0xF2);
        LCD_Write(x);
        LCD_Write(tmp_y);
    }
}

void LCD_Rectangle(unsigned char left_up_x, unsigned char left_up_y,
                   unsigned char right_down_x, unsigned char right_down_y,
                   unsigned char shadow_control)
{
    unsigned char tmp_left_up_x, tmp_left_up_y,
                  tmp_right_down_x, tmp_right_down_y;
    unsigned char i;
    
    tmp_left_up_x = (left_up_x << 3) + 0x04;
    tmp_left_up_y = (left_up_y << 4) + 0x08;
    tmp_right_down_x = (right_down_x << 3) + 0x04;
    tmp_right_down_y = (right_down_y << 4) + 0x08;
    
    LCD_Horizontal_Line(tmp_left_up_x, tmp_right_down_x, tmp_left_up_y);
    LCD_Vertical_Line(tmp_right_down_x, tmp_left_up_y, tmp_right_down_y);
    LCD_Horizontal_Line(tmp_left_up_x, tmp_right_down_x, tmp_right_down_y);
    LCD_Vertical_Line(tmp_left_up_x, tmp_left_up_y, tmp_right_down_y);
   
    if (shadow_control == 1)
    {
        for (i = 1; i <= 2; i++)
        {
            LCD_Vertical_Line(tmp_right_down_x + i, tmp_left_up_y + i, tmp_right_down_y + i);
            LCD_Horizontal_Line(tmp_left_up_x + i, tmp_right_down_x + i, tmp_right_down_y + i);
       }
    }
}
//---------------------------------------------------------------------------------------------

void LCD_Clear(void)
{
    
    unsigned char y, x;
    for(y = 0; y < 5; y++)
    for(x = 0; x < 20; x++)
    {
        Code_Buffered[y][x] = ' ';
    }
    
    LCD_Write(0xF4);
}

void LCD_Drive(void)
{
    unsigned char y, x;

    for(y = 0; y < 5; y++)
    for(x = 0; x < 20;)
    {
        if (Code[y][x] < 0xA0)
        {
            if (Code_Buffered[y][x] != Code[y][x])
            {
                Code_Buffered[y][x] = Code[y][x]; 
                LCD_Ascii(x, y, Code[y][x]);
                x++;
            }
            else
            {
                x++;
            }
        }
        else
        {
            if ((Code_Buffered[y][x] != Code[y][x]) ||
               (Code_Buffered[y][x+1] != Code[y][x+1]))
            {
                Code_Buffered[y][x] = Code[y][x];
                Code_Buffered[y][x+1] = Code[y][x+1];
                LCD_Character(x, y, Code[y][x], Code[y][x+1]);
                x += 2;
            }
            else
            {
                x += 2;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -