0% found this document useful (0 votes)
100 views

LCD 1

Lcd_init() Must be called before any other function. This source code may only be used by licensed users of the CCS C compiler. No other use, reproduction or distribution is permitted without written permission.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

LCD 1

Lcd_init() Must be called before any other function. This source code may only be used by licensed users of the CCS C compiler. No other use, reproduction or distribution is permitted without written permission.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Programa para mostrar nombre en LCD

/////////////////////////////////////////////////////////////////////////// //// //// //// RR_LCD.C Driver for common LCD modules //// //// //// ////

//// lcd_init() Must be called before any other function. //// ////

//// lcd_putc(c) Will display c on the next position of the LCD. //// //// //// //// //// The following have special meaning: \f Clear display \n Go to start of second line \b Move back one position //// //// //// //// ////

////

//// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1) //// ////

////

//// lcd_getc(x,y) Returns character at position x,y on LCD //// ////

////

///////////////////////////////////////////////////////////////////////////

////

(C) Copyright 1996,2007 Custom Computer Services

////

//// This source code may only be used by licensed users of the CCS C //// //// compiler. This source code may only be distributed to other ////

//// licensed users of the CCS C compiler. No other use, reproduction //// //// or distribution is permitted without written permission. //// ////

//// Derivative programs created using this software in object code //// form are not restricted in any way. /////////////////////////////////////////////////////////////////////////// ////

// As defined in the following structure the pin connection is as follows: // // // // // // // // // // // E0 rs E1 enable E2 rw D0 D0 D1 D1 D2 D2 D3 D3 D4 D4 D5 D5 D6 D6 D7 D7 // Para que pueda trabajar con nuestro modulo

//

#include <16f877A.h>

// PIC utilizado // Configuramos los fuses // Oscilador a 4Mhz

#fuses XT,NOWDT,NOPROTECT,NOLVP #use delay (clock=4000000)

struct lcd_pin_control { BOOLEAN rs; BOOLEAN enable; BOOLEAN rw; } lcd_c;

// Estructura para puerto de control

struct lcd_pin_datos { int data : 8;

// Estructura para puerto de datos

} lcd_d;

//#byte lcd_d = 0xF81 //#byte lcd_c = 0xF83 #byte lcd_d = 0x08 #byte lcd_c = 0x09 #byte adcon1 = 0x9F

// direccin de la estructura "lcd_d" // direccin de la estructura "lcd_c" // direccin del puerto de datos D // direccin del puerto de control E // direccin del registro ADCON1

#define set_tris_puerto(x) set_tris_d(x) // Para definir sentido en puerto de datos #define set_tris_control(x) set_tris_e(x) // Para definir sentido en puerto de control #define lcd_line_two 0x40 // Define direccin de inicio de segunda lnea

struct lcd_pin_datos const LCD_WRITE_D = {0x00}; // Para escribir en puerto de datos struct lcd_pin_datos const LCD_READ_D = {0xFF}; // Para leer en puerto de datos struct lcd_pin_control const LCD_WRITE_C = {0x00}; // Para escribir en puerto de control

BYTE lcd_read_byte() { BYTE datos_leidos; set_tris_puerto(LCD_READ_D); // define puerto D como entrada

set_tris_control(LCD_WRITE_C); // define puerto E como salida lcd_c.rw = 1; delay_cycles(1); lcd_c.enable = 1; delay_cycles(1); datos_leidos = lcd_d.data; lcd_c.enable = 0; delay_cycles(1); // lee datos del mdulo LCD // Deshabilita mdulo LCD // Habilita mdulo LCD // r=1. Habilita lectura de datos del LCD

set_tris_puerto(LCD_WRITE_D);

// define puerto D como salida

return (datos_leidos); }

// Entrega datos ledos del LCD

void lcd_enviar( BYTE n ) { lcd_d.data = n; delay_cycles(1); lcd_c.enable = 1; delay_us(2); lcd_c.enable = 0;

// n es el byte a enviar al LCD // enva n al puerto D

// Habilita al mdulo LCD

// Deshabilita el mdulo LCD

void lcd_send_byte( BYTE ins_dat, BYTE n ) {

lcd_c.rs = 0;

// selecciona registro de instrucciones

while ( bit_test(lcd_read_byte(),7) ) ; // Espera hasta que LCD est libre lcd_c.rs = ins_dat; delay_cycles(1); lcd_c.rw = 0; delay_cycles(1); lcd_c.enable = 0; lcd_enviar(n); // Deshabilita mdulo LCD // Funcin que enva el byte n // habilita escritura de datos // rs=0, instruccin rs=1, dato

void lcd_init() { adcon1 = 0x82; // define puerto E como digital

set_tris_control(LCD_WRITE_C); // define puerto E como salida set_tris_puerto(LCD_WRITE_D); // define puerto D como salida

lcd_c.rs = 0; lcd_c.rw = 0; lcd_c.enable = 1; delay_ms(15);

// selecciona registro de instrucciones // selecciona accin de escritura // mdulo deshabilitado?????

lcd_send_byte(0, 0x38); delay_ms(5); lcd_send_byte(0, 0x38); delay_ms(1); lcd_send_byte(0, 0x38);

// define interfaz de 8 bits

// define interfaz de 8 bits, 2 lineas

lcd_send_byte(0, 0x0F);

// D=1, C=1, B=1

lcd_send_byte(0, 0x06); // lcd_send_byte(0, 0x07);

// I/D=1, S=0 Escribe a la derecha // I/D=1, S=1 Escribe a la izquierda

void lcd_gotoxy( BYTE x, BYTE y) { BYTE address;

if(y!=1) address=lcd_line_two; else address=0; // hace address=0x40, inicio de lnea 2

address+=x-1; lcd_send_byte(0,0x80|address); // Enva instruccin

void lcd_putc( char c) { switch (c) { case '\f' : lcd_send_byte(0,1); delay_ms(2); break; case '\n' : lcd_gotoxy(1,2); break;

case '\b' : lcd_send_byte(0,0x10); break; default : lcd_send_byte(1,c); break;

} }

char lcd_getc( BYTE x, BYTE y) { char value;

lcd_gotoxy(x,y); while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low lcd_c.rs=1; value = lcd_read_byte(); lcd_c.rs=0; return(value); } // Habilita lectura del LCD // lee dato del LCD

void main() { lcd_init(); set_tris_d(0x00); // puerto D como salida.

lcd_putc("\f"); lcd_gotoxy(1,1);

lcd_putc("Microcontroladores"); delay_ms(1000); }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy