Programación LCD móvil
* * * * * * * * * * * * * * * * Archivo de encabezado LCD.h * * * * * * * * * * * * * * * * * * * * * */# ifndef _ LCD _ h _
#define _LCD_H_
# include & ltreg 51 .extern void LCD_init(); p >
vacío externo LCD_busy();
vacío externo lcd_write_dat(dat de caracteres sin firmar);
vacío externo lcd_write_com(dat de caracteres sin firmar);
extern void lcd_xy(carácter x sin firmar, char y sin firmar);# endif/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *.
reg 51.h>
#Contiene "lcd.h"
main()
{
LCD_init( ); p>
LCD_busy();
lcd_xy(6,0);
LCD_write_dat(' b ');
mientras(1);
* * * * * * * * * * * * * * * * * * Archivo LCD.c * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "Contiene " LCD.h "
//#Definir caracteres uchar sin firmar
//# Definir uint int no extraído
#Definir puerto P0
Tabla de caracteres sin firmar []= "0123456789";
Tabla de caracteres sin firmar 1[]= "abcdefABCDEF";
sbit rs=p2 ^0;
sbit rw=p2^1;
sbit e=p2^2;/*** *************** *********************
* * * 00000 5 * 7->0xff
***** 0** /5*8 0x40
* * * * * 0 * * 0x 40->I
* * * * * 0 * * 0x 40-& gt;
*****0** 0x40
*****0** 0x40
***00000 0x1f
Agregue su propio rol personalizado
************************ ************* /
Código carácter sin firmar ziku[]=
{
0x0f, 0x09, 0x09, 0x0f, 0x09, 0x09, 0x09, 0x0f, 0x00, // Carácter chino "日"
0x0f, 0x09, 0x0f, 0x09, 0x0f, 0x09, 0x11, 0x00, //Carácter chino "luna"
0x001, 0x02, 0x03, 0x05, 0x09, 0x03, 0x00, 0x00, //La mitad izquierda del carácter chino "año"
0x00, 0x00, 0x1e, 0x08, 0x08, 0x1e, 0x08, 0x 08//La mitad derecha del Carácter chino "año"
};/* * * * * * * * * * * * * * * Lee el estado de lcd1602.
************************/
Carácter sin firmar lcd_read()
{
Temperatura de carácter sin firmar;
e = 0;
puerto = 0xff
RS = 0;
rw = 1 ;
e = 1;
temp = puerto;
e = 0;
Temperatura de retorno; >
}
/*************************************** *****
Compruebe si la pantalla LCD está ocupada.
******************************************/
void lcd_busy()
{
Temperatura de carácter sin firmar;
do {
temp = LCD _ leer( );
} while((temp & amp; 0x 80)= = 0x 80);
}
/****** ** **********************************
Escribe el comando en lcd
************************************************ **/
void lcd_write_com (datos de caracteres sin firmar)
{
LCD _ ocupado();
e = 0;
puerto = dat
RS = 0
rw = 0
e = 1; = 0;
}
/******************************* ***********
Leer los datos correspondientes a la dirección LCD
****************** ******************* *************/
Carácter sin firmar lcd_read_dat()
{
Temperatura de carácter sin firmar;
LCD_busy();
e = 0;
puerto = 0xff
RS = 1;
rw = 1;
e = 1;
temp = puerto
e = 0;
Temperatura de retorno
}
/************************ **************** *
Escribir datos en lcd
*************** *************** **********/
void lcd_write_dat (datos de caracteres sin firmar)
{ p>
LCD _ ocupado();
e = 0;
puerto = dat
RS = 1; rw = 0;
e = 1 ;
e = 0;
}
/******** ************** *******************
Escribir cadena en lcd
************ *******************************/
void lcd_gets(char *dat)
{
mientras(*dat! =0)
{
LCD _ escribir _ dat(* dat++); p>}
/*************************************** * **
Determina la ubicación a escribir, que son las coordenadas x y.
******************************************/
void lcd_xy(carácter sin firmar x, carácter sin firmar y)
{
Interruptor (y)
{
Caso 0: LCD _ write _ com (0x 8x); //Posición X de la primera línea
Caso 1: LCD _ write _ com (0xc x); ; //0xc0==0x80x50 posición de la segunda línea tres: LCD _ write _ com (0xd 4+x); //4*20
}
}
/***** **************************************** ***********
Visualización de una sola línea solo 5*10 otros modos 5*8 = 1 modo 5*8 = 0 5*10.
********************************************* *** *********/
add_custom_word(carácter sin firmar *dat, carácter sin firmar len, modo de carácter sin firmar)
{
Caracteres sin signo n, m;
for(n = 0; n & ltlenn++)
{
if (patrón)
{
LCD _ write _ com(0x 48 * n);
for(m = 0; m & lt8;m++)
{< / p>
LCD _ write _ dat(* dat);
dat++
}
}
Otros
{
LCD _ write _ com(0x 410 * n
for(m = 0; m & lt10; m++)
);{
LCD _ escribir _ dat(*dat);
dat++
}
}
}
}
/****************************** *******************
Inicializar lcd
*************** ******* *************************/
void lcd_init()
{
LCD_write_com(0x 01); //Borrar pantalla
LCD_write_com(0x 03);
LCD_write_com(0x3c);
LCD_write_com(0x40);
LCD_write_com(0x0c);
add_custom_word(ziku, 4, 1); // Inicializa caracteres personalizados
}
/********************************************* *
1 ms se utiliza como unidad básica de la función de retardo.
********************************************* *** */
Retraso no válido (carácter sin firmar z)
{
Carácter sin firmar x, y, a;
para ( x = z; x & gt0; );
}