#include <16f877a.h>
#fuses HS, NOWDT, RC, PUT, NOPROTECT,NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay (clock = 4000000)
#byte TRISA = getenv("SFR:TRISA") //
#byte TRISB = getenv("SFR:TRISB") //
#byte TRISC = getenv("SFR:TRISC") //
#byte TRISD = getenv("SFR:TRISD") //
#byte TRISE = getenv("SFR:TRISE") //
#byte PORTA = 0x05 //Address del PORTA
#byte PORTB = 0x06 //Address del PORTB
#byte PORTC = 0x07 //Address del PORTC
#byte PORTC = 0x08 //Address del PORTD
#byte PORTC = 0x09 //Address del PORTE
#byte OPTION_REG = 0x81 //Address del registro OPTION_REG
#define LCD_ENABLE_PIN PIN_E0 //Configuración del PIN ENABLE (E)
#define LCD_RS_PIN PIN_E1 //Configuración del PIN REGISTER SELECT (RS)
#define LCD_RW_PIN PIN_E2 //Configuración del PIN READ/WRITE (RW)
#define LCD_DATA4 PIN_A0 //Configuración del PIN DATA4
#define LCD_DATA5 PIN_A1 //Configuración del PIN DATA5
#define LCD_DATA6 PIN_A2 //Configuración del PIN DATA6
#define LCD_DATA7 PIN_A3 //Configuración del PIN DATA7
#include "lcd.c"
void main(){
bit_set(OPTION_REG,7); //Resistencia Pullout desactivada 0=Activada 1=Desactivada
setup_psp(PSP_DISABLED); //Configura el Modo PSP 0=Desactivado 1=Activado
set_TRIS_A(0x00); //Todos los pines del Puerto A configurados como salidas
set_TRIS_B(0xFF); //Todos los pines del Puerto B configurados como entradas
set_TRIS_C(0x00); //Todos los pines del Puerto C configurados como salidas
set_TRIS_D(0x00); //Todos los pines del Puerto D configurados como salidas
set_TRIS_E(0xFF); //Todos los pines del Puerto E configurados como entradas
//output_b(0xff); //Limpia el registro del Puerto B
output_c(0x00); //Limpia el registro del Puerto C
output_d(0x00); //Limpia el registro del Puerto D
lcd_init(); //Llamada a LCD_INIT
lcd_gotoxy(1,1); //Puntero Posicion 1, Linea 1
lcd_putc("Hola Pablo"); //Escribe texto
lcd_gotoxy(1,2); //Puntero Posicion 1, Linea 2
lcd_putc("Bienvenido..."); //Escribe texto
delay_ms(850);
lcd_putc("\f"); //Limpia LCD
int in=0; //
while(TRUE) //
{
if(bit_test(PORTB,0) == 1) //
{
for (in=0; in<=44; in++) //
{
lcd_putc("\f"); //Limpia LCD
lcd_gotoxy(1,1); //Puntero Posicion 1, Linea 1
lcd_putc("M-1 Derecha"); //Escribe texto
output_c(0b00001000); //Paso 1
delay_ms (25); //Retardo 25ms
output_c(0b00000100); //Paso 2
delay_ms (25); //Retardo 25ms
output_c(0b00000010); //Paso 3
delay_ms (25); //Retardo 25ms
output_c(0b00000001); //Paso 4
delay_ms (25); //Retardo 25ms
break; //Break
}
}
else if(bit_test(PORTB,1) == 1) //
{
for (in=0; in<=44; in++) //
{
lcd_putc("\f"); //Limpia LCD
lcd_gotoxy(1,1); //Puntero Posicion 1, Linea 1
lcd_putc("M2 - Derecha"); //Escribe texto
output_c(0b10000000); //Paso 1
delay_ms (25); //Retardo 25ms
output_c(0b01000000); //Paso 2
delay_ms (25); //Retardo 25ms
output_c(0b00100000); //Paso 3
delay_ms (25); //Retardo 25ms
output_c(0b00010000); //Paso 4
delay_ms (25); //Retardo 25ms
break; //Break
}
}
else if(bit_test(PORTB,2) == 1) //
{
for (in=0; in<=44; in++) //
{
lcd_putc("\f"); //Limpia LCD
lcd_gotoxy(1,1); //Puntero Posicion 1, Linea 1
lcd_putc("M-3 Derecha"); //Escribe texto
output_d(0b00001000); //Paso 1
delay_ms (25); //Retardo 25ms
output_d(0b00000100); //Paso 2
delay_ms (25); //Retardo 25ms
output_d(0b00000010); //Paso 3
delay_ms (25); //Retardo 25ms
output_d(0b00000001); //Paso 4
delay_ms (25); //Retardo 25ms
break; //Break
}
}
else if(bit_test(PORTB,3) == 1) //
{
for (in=0; in<=44; in++) //
{
lcd_putc("\f"); //Limpia LCD
lcd_gotoxy(1,1); //Puntero Posicion 1, Linea 1
lcd_putc("M4 - Derecha"); //Escribe texto
output_d(0b10000000); //Paso 1
delay_ms (25); //Retardo 25ms
output_d(0b01000000); //Paso 2
delay_ms (25); //Retardo 25ms
output_d(0b00100000); //Paso 3
delay_ms (25); //Retardo 25ms
output_d(0b00010000); //Paso 4
delay_ms (25); //Retardo 25ms
break; //Break
}
}
else //Si no se da ninguna condición
{ //Ejecuta este codigo
lcd_putc("\f"); //Limpia LCD
lcd_gotoxy(1,1); //Puntero Posicion 1, Linea 1
lcd_putc("STOP!"); //Escribe texto
delay_ms (250); //Retardo 25ms
output_c(0x00); //Puerto C = 0
output_d(0x00); //Puerto D = 0
continue; //
}
}
}