Está en la página 1de 2

1. //#include <16f877A.

h>
//pic a utilizar
2. #use delay (clock=4000000)
//Fosc=4Mhz
3. #byte puerto_A = 05
4. #byte puerto_B = 06
5. #byte puerto_C = 07
6. #byte puerto_D = 8
7. #define use_portb_lcd TRUE
//definir portb lcd
8. #include<lcd.c>
//libreria manejo lcd
9. #include<Lib_Int_EEProm.c>
10.
11. //inicio del programa
12. void main(void)
13. {
14.
15. long int cont;
16. long int cont2=0;
17. long int LAST_VOLUME=0,volume; //variables de direccion
escritura eeprom y mensaje
18. long int valor_leido;
19. int direccion = 0;
20. set_tris_A (0b11111111);
21. set_tris_D (0b11111111);
22. puerto_D = 0;
23. puerto_A = 0;
24.
25. lcd_init(); //inicializa lcd
26.
27.
28.
29. WHILE (TRUE)
30.
{
31.
32.
lcd_gotoxy(4,1);
33.
printf(lcd_putc,"INGRESOS:");
34.
lcd_gotoxy(4,2);
35.
printf(lcd_putc,"NRO:%Lu",cont);
//muestra por
pantalla el mensaje
36.
37.
if(input(pin_D0))
38.
{
39.
cont=cont+1;
40.
cont2=cont2+1;
41.
delay_ms(250);
42.
}
43.

44.
45.
46.
47.
48.
49.
50.
51.
52.

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

53.
54. ////////////////////////////////////////////////////////////////
////////////
55.
56. //grabar y mostrar el dato en la eeprom
57. if(input(pin_A0))
58. {
59.
60. cont=0;
61. lcd_putc("\f" ); //borra pantalla lcd
62. write_eeprom(direccion,cont2>>8); //Escribes primer byte (parte
m&#38;#225;s significativa del int16)
63. write_eeprom(direccion+1,cont2); //Escribes segundo byte (parte
menos significativa del int16)
64. valor_leido = read_eeprom(direccion);
65. valor_leido = valor_leido<<8;
66. valor_leido = read_eeprom(direccion+1);
67. printf(lcd_putc, "Dato: %Lu",[b]valor_leido[/b]);
68. delay_ms(2000);
69. lcd_putc("\f" ); //borra pantalla lcd
70. }
71. ////////////////////////////////////////////////////////////////
//////////////////////
72.
}
73.
}
74.

setup_adc_ports(NO_ANALOGS);

También podría gustarte