#include <16f877a.h> //pic a utilizar
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP //ordenes para el programador
#use delay (clock=4000000) //Fosc=4Mhz
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_RS PIN_D2
#define LCD_E PIN_D3
#include<lcd1.c> //libreria manejo lcd
#byte portb=6
short sensor = 0;
int personas = 0;
void main(){
while(1){
//-------------------------------------------------------------lcd---------
lcd_init ();
lcd_gotoxy(1,1);
printf (lcd_putc,"datos ");
lcd_gotoxy(1,2);
printf (lcd_putc,"%u:%u:%u ",sensor,personas,pe);
//---------------------------------------------------------------lcd---
if (input(pin_b0)){
sensor = 1;}
else{
sensor = 0;}
if (sensor == 1){
personas++;
delay_ms(100); }
}
}#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=4000000)
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_RS PIN_D2
#define LCD_E PIN_D3
#include<lcd1.c> //libreria manejo lcd
//---------------variables----------------------------------------------------//
short sensor = 0;
LONG personas = 0;
short alarma = 0;
int vuelta;
//----------------Fin variables-----------------------------------------------//
#int_TIMER1
void TIMER1_isr(void)
{
vuelta++; /// aumenta la vuelta cada .5 seg
set_timer1(3036);
clear_interrupt(int_timer1); // limpio flag
if(vuelta==60) //si la vuelta da 60, en segundos 30,
{alarma++;} //se activa la alarma porque el sensor esta siendo tapado
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(1){
//------------------------lcd----------------------------------------------
lcd_init ();
lcd_gotoxy(1,1);
printf (lcd_putc,"datos ");
lcd_gotoxy(1,2);
printf (lcd_putc,"%u:%Lu:%u ",sensor,personas,alarma);
//-----------------------lcd fin--------------------------------------------
//------------------------sensor--------------------------------------------
if(input(pin_b0)){
sensor = 1;}
else{
sensor = 0;}
//---------------------------sensor fin---------------------------------------
if (input(pin_b0)) // Si esta en 1 entra
{
while(input(pin_b0)); // Si sigue en 1 se mantiene aca, sale cuando se pone a 0 y cuenta una persona.
personas++;
write_eeprom(01,personas);
}
if (input(pin_b0)==0) // Si esta en 1 entra
{
vuelta=0;
}
}
}
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=4000000)
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_RS PIN_D2
#define LCD_E PIN_D3
#include<lcd1.c> //libreria manejo lcd
#include<KBD1.c>
#rom 0x2100={'2','6','1','2'} // escribir en la memoria eeprom
#define use_portb_kbd TRUE
//---------------variables----------------------------------------------------//
LONG personas = 0,personas1=0, pasajeros=0;
short alarma=0, inicio;
int vuelta;
int a;
int i;
int j=0; // contador
char k; // lectura del teclado
char dato[4],clave[4]; //dato: almacena los digitos, clave: es la contraseña
int ingresos;
//----------------Fin variables-----------------------------------------------//
#int_TIMER1
void TIMER1_isr(void)
{
vuelta++; /// aumenta la vuelta cada .5 seg
set_timer1(3036);
clear_interrupt(int_timer1); // limpio flag
if(vuelta==60) //si la vuelta da 60, en segundos 30,
{alarma=1;} //se activa la alarma porque el sensor esta siendo tapado
}
void todo (void){
while(1){
//------------------------lcd----------------------------------------------//
lcd_gotoxy(1,1);
printf (lcd_putc,"Sensor:%lu ",personas);
lcd_gotoxy(1,2);
printf (lcd_putc,"Pasa:%lu A:%u %lu ",pasajeros,alarma,personas1);
//-----------------------lcd fin--------------------------------------------//
pasajeros = personas / 2;
personas1=read_eeprom(01);
//---------------este deberia ser 0, es para el apagado de emergencia--------//
if (input(pin_e1)) // Si esta en 1 entra
{ write_eeprom(01,personas);
delay_ms(200);}
//---------------------------------------fin----------------------------------//
if(input(pin_e2)){
alarma = 0;
personas= 0;
pasajeros = 0;
}
}
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
while(1){
lcd_init ();
kbd_init();
port_b_pullups(TRUE);
if (input(pin_e0)) //El sensor detecto algo
{
set_timer1(3036); // Cargo el timer con el valor correspondiente, limpio flags y activo su interrupcion
clear_interrupt(int_timer1);
enable_interrupts(INT_TIMER1);
while(input(pin_b0)); // Mientras este atrapado en este bucle, es decir mientras no se suelte el sensor va a estar atrapado aca y va a funcionar la interrupcion
personas++; // Si se solto cuento como que atravezo una persona, vera si luego cuando se activa la alarma si cuenta exactametne como persona o no.
}
else
{
disable_interrupts(INT_TIMER1); // Se solto el boton? entonces deshabilito las interrupciones del TIMER1 ya que no las necesito mas
vuelta=0; // Y Pongo a 0 mi variable vueltas por si llega a ocurrir de nuevo y quiero que comienze de 0
}
if (input(pin_e1))
{inicio=1;}
if(inicio==1)
{
//-----------------------clave-----------------------------------------------
printf(LCD_putc, "\f");
lcd_putc("\fINGRESE SU CLAVE ");
i=0;
while(i<4){
k=kbd_getc(); // leer la tecla presiono
if(k!=0){
dato[i]=k;
i++;
lcd_gotoxy(i,2); // posicion i de la segunda linea
lcd_putc('*');
}
}
for(i=0;i<4;i++)
clave[i]=read_eeprom(i); //guarda la constraseña en el vector clave
if( dato[0]==clave[0] && dato[1]==clave[1] && dato[2]==clave[2] && dato[3]==clave[3])
{
lcd_gotoxy(1,1);
printf (lcd_putc,"\fClave correcta");
lcd_gotoxy(1,2);
printf (lcd_putc,"Adelante!");
ingresos = ingresos +1;
delay_ms(200);
lcd_gotoxy(1,1);
printf (lcd_putc,"\fHas entrado %u",ingresos);
lcd_gotoxy(1,2);
printf (lcd_putc,"veces");
delay_ms(500);
todo ();
}
else{
lcd_putc("\fClave incorrecta ");
lcd_putc("\n ");
j++;
if(j==3){
lcd_putc("\fTecladoBloqueado ");
lcd_putc("\n ");
delay_ms(60000);
j=0;
}
delay_ms(2000);
}
//---------------clave fin------------------------------------------------------
}
}
}
setup_timer_0(RTCC_EXT_H_TO_L|RTCC_DIV_4);#int_TIMER0
void TIMER0_isr(void)
{
personas++;
set_timer0(255);
}#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=4000000)
#FUSES
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_RS PIN_D2
#define LCD_E PIN_D3
#include<lcd1.c> //libreria manejo lcd
#include<KBD1.c>
#rom 0x2100={'2','6','1','2'} // escribir en la memoria eeprom
#define use_portb_kbd TRUE
//---------------variables----------------------------------------------------//
LONG personas = 0, pasajeros=0;
short alarma=0;
unsigned int r=1;
int vuelta, ingresos, personastmr, conteo, tmrviejo;
int a, i, j=0;
short enter;
char k; // lectura del teclado
char dato[4],clave[4]; //dato: almacena los digitos, clave: es la contraseña
//----------------Fin variables-----------------------------------------------//
#int_TIMER1
void TIMER1_isr(void)
{
if (input(pin_a4) == 1 && get_timer0() == tmrviejo )
{
vuelta++;
set_timer1(3036);
if(vuelta==60) //si la vuelta da 60, en segundos 30,
{alarma=1;} //se activa la alarma porque el sensor esta siendo tapado
}
else
{
vuelta=0; // Pongo a 0 la varaible para contar los 30seg
}
tmrviejo = get_timer0(); // Actualizo los valores, sino habian cambiado quedan iguales. Si cambiaron aqui asi se actualizan, y los proximas entradas a esta interrupcion se utiliza el ultimo valor del TMR0.
}
#int_TIMER0
void TIMER0_isr(void)
{
conteo++;
}
void menu(){
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_EXT_H_TO_L|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
lcd_init ();
kbd_init();
port_b_pullups(TRUE);
set_timer0(0);
set_timer1(3036);
while(1){
printf(LCD_putc, "\f");
inicio:
//-----------------------clave-----------------------------------------------
printf(LCD_putc, "\f");
lcd_putc("\fIngrese su clave ");
i=0;
while(i<4){
k=kbd_getc(); // leer la tecla presiono
if(k!=0){
dato[i]=k;
i++;
lcd_gotoxy(i,2); // posicion i de la segunda linea
lcd_putc('*');
}
}
for(i=0;i<4;i++)
clave[i]=read_eeprom(i); //guarda la constraseña en el vector clave
if( dato[0]==clave[0] && dato[1]==clave[1] && dato[2]==clave[2] && dato[3]==clave[3])
{
lcd_gotoxy(1,1);
printf (lcd_putc,"\fClave correcta");
lcd_gotoxy(1,2);
printf (lcd_putc,"Adelante!");
ingresos = ingresos +1;
delay_ms(2000);
lcd_gotoxy(1,1);
printf (lcd_putc,"\fHas entrado %u",ingresos);
lcd_gotoxy(1,2);
printf (lcd_putc,"veces");
delay_ms(3000);
while(1){
k = kbd_getc();
if(k!=0){
if(k=='C'){
enter=1;}
if(k=='D'){
enter=0;}
if(k=='A'){
r++;}
if(k=='B'){
r= r-1;}
}
if(r>=5)
{r = 1;}
if (enter == 1){
switch (r){
case 1:{
personastmr = get_timer0();
personas = (conteo *256) + personastmr;
pasajeros=personas/2;
lcd_putc("\f");
lcd_gotoxy(1,1);
printf (lcd_putc,"Sensor %lu",personas);
lcd_gotoxy(1,2);
printf (lcd_putc,"Personas: %lu ",pasajeros);
delay_ms(100);
break;}
case 2:{
k = kbd_getc();
if(k!=0){
if(k=='C'){
Conteo=0;
personas=0;
set_timer0(0);
enter=0;}
}
lcd_putc("\f");
lcd_gotoxy(1,1);
printf (lcd_putc,"¿Borrar datos? ",);
lcd_gotoxy(1,2);
printf (lcd_putc,"Presione C ",);
delay_ms(100);
break;}
case 3:{
lcd_gotoxy(1,1);
printf (lcd_putc,"--Borrar datos-- ",);
lcd_gotoxy(1,2);
printf (lcd_putc,"-->Contraseña<-- ",);
break;}
case 4:{
goto inicio;
break;}
} }
if (enter == 0)
{
switch (r){
case 1:{
lcd_gotoxy(1,1);
printf (lcd_putc,"Menu seleccion ",);
lcd_gotoxy(1,2);
printf (lcd_putc,"---> Conteo <--- ",);
break;}
case 2:{
lcd_gotoxy(1,1);
printf (lcd_putc,"-----Conteo----- ",);
lcd_gotoxy(1,2);
printf (lcd_putc,"->Borrar datos<- ",);
break;}
case 3:{
lcd_gotoxy(1,1);
printf (lcd_putc,"--Borrar datos-- ",);
lcd_gotoxy(1,2);
printf (lcd_putc,"-->Contraseña<-- ",);
break;}
case 4:{
lcd_gotoxy(1,1);
printf (lcd_putc,"---Contraseña--- ",);
lcd_gotoxy(1,2);
printf (lcd_putc,"--> Regresar <-- ",);
break;}
}
}
}
}
else{
lcd_putc("\fClave incorrecta ");
lcd_putc("\n ");
j++;
if(j==3){
lcd_putc("\f Teclado ");
lcd_putc("\n Bloqueado ");
delay_ms(60000);
j=0;
}
delay_ms(2000);
}
//---------------clave fin------------------------------------------------------
}
}