elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Informática
| |-+  Electrónica
| | |-+  18F452 ejemplos con lcd??
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: 18F452 ejemplos con lcd??  (Leído 5,683 veces)
juanjuan19

Desconectado Desconectado

Mensajes: 5


Ver Perfil
18F452 ejemplos con lcd??
« en: 5 Febrero 2012, 22:39 pm »

hola amigos como estan??estaba haciendo un proyecto en el pic 16F877A, en css compiler, pero ahora estoy llegando al limite de la memoria de programa, asi que me pase al 18f452, observe que los pines en ambos pics son los mismos, mi duda es que se me entro a compilar, en css el codigo compila, y en proteus arranca tambien, el tema es que el lcd que conecte no muestra los caracteres, alguien tendria un ejemplo con este pic y que use un lcd hecho en css compiler para partir de ahi y ver como salgo de estas, gracias y un gran abrazo


En línea

juanjuan19

Desconectado Desconectado

Mensajes: 5


Ver Perfil
Re: 18F452 ejemplos con lcd??
« Respuesta #1 en: 5 Febrero 2012, 22:49 pm »

Esta es la libreria que use para manejar el lcd (funcionaba de 10 en pic 16F877A)
pero qui no se muestra ningun caracter en la pantalla LCD[/img]


//include LCD para CCS

// La ventaja de este codigo es que puedes trabajar si lo quieres con pines
// dispersos es decir no estas sujeto a la mitad de un puerto. Además no se usa el pin R/W,
// se conecta a masa

// Registros de Puertos A & B
#define PORTA 0x05 // Puerto A
#define PORTB 0x06 // Registro de direccionamiento Puerto A
#define TRISA 0x85 // Puerto B
#define TRISB 0x86 // Registro de direccionamiento Puerto B
#define PORTC 0x07 // Registro de direccionamiento Puerto C
#define TRISC 0x87 // Puerto C

// Definición de Puertos Pantalla LCD 40x20 Hitachi 44780
/*
#bit lcd_db4 = PORTC.0
#bit tris_lcd_db4 = TRISC.0
#bit lcd_db5 = PORTC.1
#bit tris_lcd_db5 = TRISC.1
#bit lcd_db6 = PORTC.2
#bit tris_lcd_db6 = TRISC.2
#bit lcd_db7 = PORTC.3
#bit tris_lcd_db7 = TRISC.3

#bit lcd_en = PORTA.0
#bit tris_lcd_en = TRISA.0
#bit lcd_rs = PORTA.1
#bit tris_lcd_rs = TRISA.1
*/

#bit lcd_db4 = PORTB.4
#bit tris_lcd_db4 = TRISB.4
#bit lcd_db5 = PORTB.5
#bit tris_lcd_db5 = TRISB.5
#bit lcd_db6 = PORTB.6
#bit tris_lcd_db6 = TRISB.6
#bit lcd_db7 = PORTB.7
#bit tris_lcd_db7 = TRISB.7

#bit lcd_en = PORTA.0
#bit tris_lcd_en = TRISA.0
#bit lcd_rs = PORTA.1
#bit tris_lcd_rs = TRISA.1

// lcd_init() Inicialización del LCD (debe utilizarse al principio,
// antes de trabajar con el LCD).
//
// lcd_putc(c) Imprime un caracter en el LCD.
//
// lcd_gotoxy(x,y) Selecciona la nueva posicion de escritura en el LCD.
// (la esquina superior izquierda es 1,1)
//
// lcd_getc(x,y) Devuelve el caracter de la posicion x,y del LCD.
//
// void lcd_erase_line(x) Borra una cantidad de caracter hacia la derecha

// Conexion a la pantalla LCD 40x4
// RC0 <---> LCD DB4
// RC1 <---> LCD DB5
// RC2 <---> LCD DB6
// RC3 <---> LCD DB7
// RC5 <---> LCD ENABLE
// RC4 <---> LCD RS
//

#define LCD_DATO 1
#define LCD_INST 0

#define LCD_LINEA1 0x80 // Direccion de memoria para la 1 linea
#define LCD_LINEA2 0xc0 // Direccion de memoria para la 2 linea
#define LCD_LINEA3 0x94 // Direccion de memoria para la 3 linea
#define LCD_LINEA4 0xd4 // Direccion de memoria para la 4 linea



// 7 6 5 4 3 2 1 0
// Function Set 0b 0 0 1 B L F 0 0
// Bus size, B:0=4 bits, B:1=8 bits
// Line Number, L:0=1 Line, L:1=2 Lines
// Font size F:0=5x8, F:1=5x10
#define LCD_FUNCTION_SET 0b00101000 // Bus=4bit, Line=2, Font=5x8

// 7 6 5 4 3 2 1 0
// Display/Cursor 0b 0 0 0 0 1 D U B
// Set Display on/off, D:0=off, D:1=on
// Underline cursor, U:0=off, U:1=on
// Blinking cursor, B:0=off, B:1=on
#define LCD_DISPLAY_CURSOR 0b00001100 // Display=on, Scroll=off, Blinkin=off

// 7 6 5 4 3 2 1 0
// Entry Mode 0b 0 0 0 0 0 1 M S
// Cursor direction, M:0=left, 1=right
// Display Scroll, S:0=no scroll, S:1=scroll
#define LCD_ENTRY_MODE 0b00000110 // Increment cursor, no disp shift

void lcd_set_write() {
tris_lcd_db4 = 0; //
tris_lcd_db5 = 0; //
tris_lcd_db6 = 0; //
tris_lcd_db7 = 0; //---> Set portb RB0-RB3 mode output
}


void lcd_send_nibble(int8 n) {
if (bit_test(n,0)) //
lcd_db4 = 1; //
else //
lcd_db4 = 0; //

if (bit_test(n,1)) //
lcd_db5 = 1; //
else //
lcd_db5 = 0; //

if (bit_test(n,2)) //
lcd_db6 = 1; //
else //
lcd_db6 = 0; //

if (bit_test(n,3)) //
lcd_db7 = 1; //
else //
lcd_db7 = 0; //---> Set data nibble
delay_cycles(5); // nop
lcd_en = 1; // Habilita LCD Eneable __
delay_us(20); // Espera 2 uSeg. | |
lcd_en = 0; // Desabilita LCD Eneable __| |__
}

void lcd_send_byte (int1 select, int8 n) {
lcd_rs = 0; // Modo de instruccion
lcd_rs = select; // Escoje entre RS=0 : Instruccion & RS=1 : Data
delay_cycles(5); // nop
lcd_en = 0; // Desabilita LCD Eneable
lcd_send_nibble(n >> 4); // Envia los datos superiores MSB
lcd_send_nibble(n); // Envia los datos inferiores LSB
}

void lcd_init() {
int8 i, count=0;
lcd_set_write(); // Prepara el puerto DB4-DB7 como salida
tris_lcd_en = 0; //
tris_lcd_rs = 0; //---> Set porta RA0, RA1 & RA2 mode output
lcd_en = 0; //
lcd_rs = 0; //---> Clear LCD_EN, LCD_RW & LCD_RS
delay_ms(100);
retry:
for(i=1; i<=3; ++i) {
lcd_send_nibble(0b0011); // 8 bit mode 3 times
delay_ms(30);
}
lcd_send_nibble(0b0010); // 4 bit mode
lcd_send_byte(LCD_INST, LCD_FUNCTION_SET); // Function Set
lcd_send_byte(LCD_INST, LCD_DISPLAY_CURSOR); // Display Cursor
lcd_send_byte(LCD_INST, LCD_ENTRY_MODE); // Entry Mode
}

void lcd_gotoxy(int8 x, int8 y)
{
int8 const address[4]={LCD_LINEA1,LCD_LINEA2,LCD_LINEA3,LCD_LINEA4};
int8 pos;
pos=address[y-1]+(x-1);
lcd_send_byte (LCD_INST, pos);
}


void lcd_putc(char c) {
lcd_send_byte(LCD_DATO,c);
}

void lcd_clear() {
lcd_send_byte(LCD_INST,0x01);
}

void lcd_home() {
lcd_send_byte(LCD_INST,0x02);
}

void lcd_erase_line(int8 x) {
int8 i;
for(i=1;i<=x;++i) {
lcd_send_byte(LCD_DATO,32);
}
}


En línea

juanjuan19

Desconectado Desconectado

Mensajes: 5


Ver Perfil
Re: 18F452 ejemplos con lcd??
« Respuesta #2 en: 5 Febrero 2012, 22:53 pm »

Esta es la libreria que use para manejar el lcd (funcionaba de 10 en pic 16F877A)
pero qui no se muestra ningun caracter en la pantalla LCD[/img]


//include LCD para CCS

// La ventaja de este codigo es que puedes trabajar si lo quieres con pines
// dispersos es decir no estas sujeto a la mitad de un puerto. Además no se usa el pin R/W,
// se conecta a masa

// Registros de Puertos A & B
#define PORTA 0x05 // Puerto A
#define PORTB 0x06 // Registro de direccionamiento Puerto A
#define TRISA 0x85 // Puerto B
#define TRISB 0x86 // Registro de direccionamiento Puerto B
#define PORTC 0x07 // Registro de direccionamiento Puerto C
#define TRISC 0x87 // Puerto C

// Definición de Puertos Pantalla LCD 40x20 Hitachi 44780
/*
#bit lcd_db4 = PORTC.0
#bit tris_lcd_db4 = TRISC.0
#bit lcd_db5 = PORTC.1
#bit tris_lcd_db5 = TRISC.1
#bit lcd_db6 = PORTC.2
#bit tris_lcd_db6 = TRISC.2
#bit lcd_db7 = PORTC.3
#bit tris_lcd_db7 = TRISC.3

#bit lcd_en = PORTA.0
#bit tris_lcd_en = TRISA.0
#bit lcd_rs = PORTA.1
#bit tris_lcd_rs = TRISA.1
*/

#bit lcd_db4 = PORTB.4
#bit tris_lcd_db4 = TRISB.4
#bit lcd_db5 = PORTB.5
#bit tris_lcd_db5 = TRISB.5
#bit lcd_db6 = PORTB.6
#bit tris_lcd_db6 = TRISB.6
#bit lcd_db7 = PORTB.7
#bit tris_lcd_db7 = TRISB.7

#bit lcd_en = PORTA.0
#bit tris_lcd_en = TRISA.0
#bit lcd_rs = PORTA.1
#bit tris_lcd_rs = TRISA.1

// lcd_init() Inicialización del LCD (debe utilizarse al principio,
// antes de trabajar con el LCD).
//
// lcd_putc(c) Imprime un caracter en el LCD.
//
// lcd_gotoxy(x,y) Selecciona la nueva posicion de escritura en el LCD.
// (la esquina superior izquierda es 1,1)
//
// lcd_getc(x,y) Devuelve el caracter de la posicion x,y del LCD.
//
// void lcd_erase_line(x) Borra una cantidad de caracter hacia la derecha

// Conexion a la pantalla LCD 40x4
// RC0 <---> LCD DB4
// RC1 <---> LCD DB5
// RC2 <---> LCD DB6
// RC3 <---> LCD DB7
// RC5 <---> LCD ENABLE
// RC4 <---> LCD RS
//

#define LCD_DATO 1
#define LCD_INST 0

#define LCD_LINEA1 0x80 // Direccion de memoria para la 1 linea
#define LCD_LINEA2 0xc0 // Direccion de memoria para la 2 linea
#define LCD_LINEA3 0x94 // Direccion de memoria para la 3 linea
#define LCD_LINEA4 0xd4 // Direccion de memoria para la 4 linea



// 7 6 5 4 3 2 1 0
// Function Set 0b 0 0 1 B L F 0 0
// Bus size, B:0=4 bits, B:1=8 bits
// Line Number, L:0=1 Line, L:1=2 Lines
// Font size F:0=5x8, F:1=5x10
#define LCD_FUNCTION_SET 0b00101000 // Bus=4bit, Line=2, Font=5x8

// 7 6 5 4 3 2 1 0
// Display/Cursor 0b 0 0 0 0 1 D U B
// Set Display on/off, D:0=off, D:1=on
// Underline cursor, U:0=off, U:1=on
// Blinking cursor, B:0=off, B:1=on
#define LCD_DISPLAY_CURSOR 0b00001100 // Display=on, Scroll=off, Blinkin=off

// 7 6 5 4 3 2 1 0
// Entry Mode 0b 0 0 0 0 0 1 M S
// Cursor direction, M:0=left, 1=right
// Display Scroll, S:0=no scroll, S:1=scroll
#define LCD_ENTRY_MODE 0b00000110 // Increment cursor, no disp shift

void lcd_set_write() {
tris_lcd_db4 = 0; //
tris_lcd_db5 = 0; //
tris_lcd_db6 = 0; //
tris_lcd_db7 = 0; //---> Set portb RB0-RB3 mode output
}


void lcd_send_nibble(int8 n) {
if (bit_test(n,0)) //
lcd_db4 = 1; //
else //
lcd_db4 = 0; //

if (bit_test(n,1)) //
lcd_db5 = 1; //
else //
lcd_db5 = 0; //

if (bit_test(n,2)) //
lcd_db6 = 1; //
else //
lcd_db6 = 0; //

if (bit_test(n,3)) //
lcd_db7 = 1; //
else //
lcd_db7 = 0; //---> Set data nibble
delay_cycles(5); // nop
lcd_en = 1; // Habilita LCD Eneable __
delay_us(20); // Espera 2 uSeg. | |
lcd_en = 0; // Desabilita LCD Eneable __| |__
}

void lcd_send_byte (int1 select, int8 n) {
lcd_rs = 0; // Modo de instruccion
lcd_rs = select; // Escoje entre RS=0 : Instruccion & RS=1 : Data
delay_cycles(5); // nop
lcd_en = 0; // Desabilita LCD Eneable
lcd_send_nibble(n >> 4); // Envia los datos superiores MSB
lcd_send_nibble(n); // Envia los datos inferiores LSB
}

void lcd_init() {
int8 i, count=0;
lcd_set_write(); // Prepara el puerto DB4-DB7 como salida
tris_lcd_en = 0; //
tris_lcd_rs = 0; //---> Set porta RA0, RA1 & RA2 mode output
lcd_en = 0; //
lcd_rs = 0; //---> Clear LCD_EN, LCD_RW & LCD_RS
delay_ms(100);
retry:
for(i=1; i<=3; ++i) {
lcd_send_nibble(0b0011); // 8 bit mode 3 times
delay_ms(30);
}
lcd_send_nibble(0b0010); // 4 bit mode
lcd_send_byte(LCD_INST, LCD_FUNCTION_SET); // Function Set
lcd_send_byte(LCD_INST, LCD_DISPLAY_CURSOR); // Display Cursor
lcd_send_byte(LCD_INST, LCD_ENTRY_MODE); // Entry Mode
}

void lcd_gotoxy(int8 x, int8 y)
{
int8 const address[4]={LCD_LINEA1,LCD_LINEA2,LCD_LINEA3,LCD_LINEA4};
int8 pos;
pos=address[y-1]+(x-1);
lcd_send_byte (LCD_INST, pos);
}


void lcd_putc(char c) {
lcd_send_byte(LCD_DATO,c);
}

void lcd_clear() {
lcd_send_byte(LCD_INST,0x01);
}

void lcd_home() {
lcd_send_byte(LCD_INST,0x02);
}

void lcd_erase_line(int8 x) {
int8 i;
for(i=1;i<=x;++i) {
lcd_send_byte(LCD_DATO,32);
}
}
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ejemplos de C#
.NET (C#, VB.NET, ASP)
aca_brond 3 6,968 Último mensaje 18 Octubre 2005, 19:02 pm
por Kpax
Ejemplos de crackmes
Ingeniería Inversa
XPLOIT80 7 2,963 Último mensaje 18 Febrero 2006, 06:46 am
por XPLOIT80
Uso del fotoshop con ejemplos
Diseño Gráfico
[:: MoRoCHio ::] 1 1,754 Último mensaje 12 Junio 2006, 18:57 pm
por ka0s
ejemplos buenos de vb
Programación Visual Basic
yense 4 1,753 Último mensaje 2 Septiembre 2008, 19:19 pm
por byway
ejemplos que no me sale
Programación C/C++
mapers 3 2,308 Último mensaje 25 Julio 2010, 11:14 am
por Eternal Idol
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines