#include <16f877a.h>
#use delay(crystal = 4MHz)
#define LCD_ENABLE_PIN PIN_A0
#define LCD_RS_PIN PIN_A1
#define LCD_RW_PIN PIN_A2
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#include "lcd420ap.c"
#include <kbd_lib.c>
#define LED_1 PIN_D0
#define LED_2 PIN_D1
#define LED_3 PIN_D2
#define LED_4 PIN_D3
#define LED_5 PIN_D4
#define LED_6 PIN_D5
#define LED_7 PIN_D6
#define LED_8 PIN_D7
#define ENTRADA1 PIN_C0
#define ENTRADA2 PIN_C1
#define ENTRADA3 PIN_C2
#define ENTRADA4 PIN_C3
#define ENTRADA5 PIN_C4
#define ENTRADA6 PIN_C5
void mostrar_menu(){
lcd_gotoxy(1,1);
printf(lcd_putc,"\f>A ENTRADA ANALOGICA\r");
lcd_gotoxy(1,2);
printf(lcd_putc,">B CONTROL PWM");
lcd_gotoxy(1,3);
printf(lcd_putc,">C ENTRADAS DIGITALES");
lcd_gotoxy(1,4);
printf(lcd_putc,">D SALIDAS DIGITALES");
}
void funcion_lectura_entradas_analogas(){
lcd_gotoxy(1,1);
printf(lcd_putc,"\fpendiente entradas");
lcd_gotoxy(1,2);
printf(lcd_putc,"analoga y visualizar");
}
void funcion_pwm(){
printf(lcd_putc,"\fpendiente el PWM");
}
void funcion_control_salidas_digitales(){
lcd_gotoxy(1,1);
printf(lcd_putc,"\fFalta panel de");
lcd_gotoxy(1,2);
printf(lcd_putc,"Control para los led");
}
void funcion_led_1(){
output_toggle(LED_1);
if (input_state(LED_1))
printf(lcd_putc,"\fLed 1 encendido");
else
printf(lcd_putc,"\fLed 1 apagado");
}
void funcion_led_2(){
output_toggle(LED_2);
if (input_state(LED_2))
printf(lcd_putc,"\fLed 2 encendido");
else
printf(lcd_putc,"\fLed 2 apagado");
}
void funcion_led_3(){
output_toggle(LED_3);
if (input_state(LED_3))
printf(lcd_putc,"\fLed 3 encendido");
else
printf(lcd_putc,"\fLed 3 apagado");
}
void funcion_led_4(){
output_toggle(LED_4);
if (input_state(LED_1))
printf(lcd_putc,"\fLed 4 encendido");
else
printf(lcd_putc,"\fLed 4 apagado");
}
void funcion_led_5(){
output_toggle(LED_5);
if (input_state(LED_5))
printf(lcd_putc,"\fLed 5 encendido");
else
printf(lcd_putc,"\fLed 5 apagado");
}
void funcion_led_6(){
output_toggle(LED_6);
if (input_state(LED_6))
printf(lcd_putc,"\fLed 6 encendido");
else
printf(lcd_putc,"\fLed 6 apagado");
}
void funcion_led_7(){
output_toggle(LED_7);
if (input_state(LED_7))
printf(lcd_putc,"\fLed 7 encendido");
else
printf(lcd_putc,"\fLed 7 apagado");
}
void funcion_led_8(){
output_toggle(LED_8);
if (input_state(LED_8))
printf(lcd_putc,"\fLed 8 encendido");
else
printf(lcd_putc,"\fLed 8 apagado");
}
void funcion_lectura_entradas_digitales(){
lcd_gotoxy(1,1);
printf(lcd_putc,"\fINPUT1=%u",input(ENTRADA1));
lcd_gotoxy(1,2);
printf(lcd_putc,"INPUT2=%u",input(ENTRADA2));
lcd_gotoxy(1,3);
printf(lcd_putc,"INPUT3=%u",input(ENTRADA3));
lcd_gotoxy(11,1);
printf(lcd_putc,"INPUT4=%u",input(ENTRADA4));
lcd_gotoxy(11,2);
printf(lcd_putc,"INPUT5=%u",input(ENTRADA5));
lcd_gotoxy(11,3);
printf(lcd_putc,"INPUT6=%u",input(ENTRADA6));
lcd_gotoxy(1,4);
printf(lcd_putc,"REGRESO MENU PULSE #");
}
void main ()
{
CHAR k;
lcd_init();
kbd_init();
port_b_pullups(TRUE);
output_low(LED_1),(LED_2),(LED_3),(LED_4),(LED_5),(LED_6),(LED_7),(LED_8);
lcd_gotoxy(2,2);
printf(lcd_putc,"Bienvenidos (^^,)");
lcd_gotoxy(1,3);
printf(lcd_putc,"Pulsa # para ir menu");
while (kbd_getc()!='#'){};
mostrar_menu();
while (true)
{
k = kbd_getc();
if (k!=0)
switch(k)
{
case 'A':
funcion_lectura_entradas_analogas();
break;
case 'B':
funcion_pwm();
break;
case 'C':
funcion_lectura_entradas_digitales();
break;
case 'D':
funcion_control_salidas_digitales();
break;
case '1':
funcion_led_1();
break;
case '2':
funcion_led_2();
break;
case '3':
funcion_led_3();
break;
case '4':
funcion_led_4();
break;
case '5':
funcion_led_5();
break;
case '6':
funcion_led_6();
break;
case '7':
funcion_led_7();
break;
case '8':
funcion_led_8();
break;
case '#':
mostrar_menu();
break;
}
}
}