Está en la página 1de 3

LCD.

h
#include
#include
#include
#include

<xc.h>
<stdint.h>
<stdbool.h>
"system.h"

#define LCD_delay 5 DEFINICION DE LOS RETARDOS DEFINIDOS POR LA HOJA DE DATOS US


ADO PARA EL CONTROLADOR
#define LCD_startup 15
#define LCD_CLEAR 0x01
#define LCD_HOME 0x02
#define LCD_CURSOR_BACK Ox10
#define LCD_CURSOR_FWD 0x14
#define LCD_PAN_LEFT 0x18
#define LCD_PAN_RIGHT 0x1C
#define LCD_CURSOR_OFF 0x0C
#define LCD_CURSOR_ON Ox0E
#define LCD_CURSOR_BLINK Ox0F
#define LCD_CURSOR_LINE2 0xC0
#define FUNCTION_SET 0x28
#define ENTRY_MODE 0x06
#define DISPLAY_SETUP Ox0C
#define LCDLine1() LCD PutCmd (LCD_HOME)
#define LCDLine2() LCD PutCmd (LCD_CURSOR_LINE2)
#define shift_cursor() LCD PutCmd (LCD_CURSOR_FWD)
#define cursor_on() LCD PutCmd (LCD_CURSOR_ON)
#define display Clr() LCD PutCmd (LCD_CLEAR)
FUNCIONES CONTRUIDAS PARA LA PANTALLA LCD, SOLO SE ESTAN RENOMBRANDO
#define instr 0
///REGISTRO DE DATOS Y COMUNICION
#define data 1
///REGISTRO DE DATOS Y COMUNICION

///

#define LCD_PORT PORTB


//DEFINIENDO LOS PUERTOS QUE
VAMOS A USAR Y LOS PINES ESPECIFICOS PARA LA APLICACION QUE SE VA AREALIZAR
#define LCD_PWR PORTB bits.RB7
#define LCD_EN PORTB bits.RB4
#define LCD_RW PORTB bits.RB6
#define LCD_RS PORTB bits.RB5
#define NB_LINES 2
///ESTAMOS DEFINIENDO EL TAMAO DE NUES
TRA PANTALLA, EN ESTE CASO ES DE 2 LINEAS Y DE 16 CARACTERES
#define NB_COL 16
void LCD_initialize(void);
//ESTAMOS DEFINIENDO LAS FUNCIONES. INI
CIANDO MODULO LCD
void LCDPutChar (uint 8_t ch);
///ESTAMOS DEFINIENDO EL PUNTO D
EL CURSOR
void LCDPutCmd (uint 8_t ch);
///SIRVE PARA ENVIAR UN COM
ANDO AL CONTROLADOR Y ENVIARLO A LA PANTALLA LCD
void LCDPutStr (Const char*);
///ESTA FUNCION NOS ENVIA
UNA CADENA NO MAYOR A LOS 16 CARACTERES QUE DEFINIMOS ANTERIORMENTE
void LCD Write Nibble (uint 8_t ch, uint8_t rs);
////NIBBLE PALABRA QYE DEFIN
E 4 BITS
void LCDGoto (uint 8_t pos, uint8_t ln);
///CON ESTA PODEM
OS DEFINIR EL CURSOR EN ALGUNA DE LAS DOS LINEAS DE PANTALLA
///DEFINIMOS CONSTANTES Y DECLARAMOS FUNCIONES
LCD.C

///VAMOS DE DESARROLLAR LAS FUNCIONES


#include <xc.h>
#include "LCD.h"
void LCD_initializer()
{
LCD_PORT=0;
TRISB=0x00;
LCD_PWR=1;
_delay_ms (LCD_Startup);
LCD PutCmd (0x32);
LCD PutCmd (FUNCTION_SET);
LCD PutCmd (DISPLAY_SETUP);
Display CLr ();
LCD PutCmd (ENTRY_MODE);
}
void LCD Write Nibble (uint 8_t ch, uint 8_t rs);
{
ch=(ch>>4);
ch=(ch& 0x0F);
LCD_PORT= (LCD_PORT & OxF0);
LCD_PORT= (LCD_PORT | ch);
LCD_RS=rs;
LCD_RW=0;
LCD_EN=1;
LCD_EN=0;
}
void LCD Put Char(uint 8_t ch)
{
_delay_ms (LCD_delay);
LCD Write Nibble (ch,data);
ch=(ch<<4);
LCD Write Nibble (ch, data);
}
void LCD Put Cmd (uint 8_t ch)
{
_delay_ms (LCD_delay);
ch=(ch<<4);
_delay_ms (I);
LCD Write Nibble (ch,instr);
}
void LCD Put Str (const char *str)
{
uint 8_t i=0;
while (str[i])
{
LCD Put Char (str[i++]);
}
}
void LCD Goto (uint 8_t pos, uint 8_t ln)
{

if ((ln>(NB_LINES-1))|| (Pos >(NB_COL-1)))


{
return;
}
LCD Put Cmd ((ln==I)? (0xC0|pos): (0x80|pos));
_delay_ms (LCD_delay);
}
MAIN.c
#include
#include
#include
#include
#include

<stdio.h>
<stdlib.h>
"system.h"
"user.h"
"LCD.h"

void Delay_Seconds (unsigned char2)


{
unsigned char x,y;
for (y=0; y<z: y++)
{
for (x=0; x<100; x++) _delay_ms (10);
}
}
void main(void)
{
//initialize the device
Init App();
//initialize the LCD
LCD_initialize ();
LCD PutStr ("Hello World");
LCD Goto (8,1);
LCD Put Char (1);
Delay_Seconds (1);
LCD Goto (8,1);
LCD Put Char (2);
Delay_Seconds (1);
LCD Goto (8,1);
LCD Put Char (3);
Delay_Seconds (1);
Display Clr();
While (1)
{
//add your application code
}
SYSTEM.H
FRECUENCIA DEL CRISTAL/4
DEFINIR BITS
SISTEM.C
USER.H
USER.C
CHECAR CONEXION DEL LCD Y PIC

También podría gustarte