2x16lcd.h

来自「attendace system on 8051 chipset from in」· C头文件 代码 · 共 161 行

H
161
字号
#ifndef _2x16LCD
#define _2x16LCD

#include "delay\delay.h"

sfr LCD_DATA = 0x80;
sbit RS = 0xA0;
sbit ENABLE = 0xA1;
#define DELAY 10
#define SEL_LCD()

void init2x16lcd()
{
        SEL_LCD();
        RS = 0;
        LCD_DATA = 0x38; /*Dual lined / 8 bits*/
        ENABLE = 1;
        delay(DELAY);
        ENABLE = 0;
        delay(DELAY);      

        RS = 0;
        LCD_DATA = 0x0e; /*Init display*/
        ENABLE = 1;
        delay(DELAY);
        ENABLE = 0;                   
        delay(DELAY);
                
        RS = 0;
        LCD_DATA = 0x01; /*Clear display*/
        ENABLE = 1;
        delay(DELAY);
        ENABLE = 0;
        delay(DELAY);
        
        RS = 0;
        LCD_DATA = 0x06;
        ENABLE = 1;
        delay(DELAY);
        ENABLE = 0;
        delay(DELAY);

        RS = 0;
        LCD_DATA = 0x80;
        ENABLE = 1;
        delay(DELAY);
        ENABLE = 0;
        delay(DELAY);
}

void gotoxy(unsigned char x,unsigned char y)
{
        SEL_LCD();
        if(y == 1)
        {
                RS = 0;
                LCD_DATA = 0x80;
                ENABLE = 1;
                delay(DELAY);
                ENABLE = 0;
        }
        else
        {
                RS = 0;
                LCD_DATA = 0xC0;
                ENABLE = 1;
                delay(DELAY);
                ENABLE = 0;
        }
        for(; x >= 1; x--)
        {
                RS = 0;
                LCD_DATA = 0x14;
                ENABLE = 0;
                delay(DELAY);
                ENABLE = 1;
                delay(DELAY);
        }
}

void putch(char ch)
{
        SEL_LCD();
        RS = 1;
        LCD_DATA = ch;

        ENABLE = 1;
        delay(DELAY);
        ENABLE = 0;
        delay(DELAY);
        return;
}

void putstring(unsigned char vi1,unsigned char vi2,char* string)
{
        for(; vi1 < vi2; vi1++)
        {
                putch(string[vi1]);
        }
}

/*
void __putstring(unsigned char vi1,unsigned char vi2,char* string)
{
        for(; vi1 < vi2; vi1++)
        {
                putch(string[vi1]);
        }
}
*/

void clearlcd()
{
        gotoxy(1,1);
        putstring(0,16,"                ");
        gotoxy(1,2);
        putstring(0,16,"                ");
}

void ____puts(char *str)
{
        while(*str)
        {
                putch(*str);
                str++;
        }
}

void __puts(char *str)
{
        while(*str)
        {
                putch(*str);
                str++;
        }
}

void puts(char *str)
{
        while(*str)
        {
                putch(*str);
                str++;
        }
}

/*
void delline(int line)
{
        if(line > 2)
        return;
        else
        {
                gotoxy(1,line);
                putstring(0,16,"                ");
        }
}
*/

#endif

⌨️ 快捷键说明

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