ArmandoCircuitos
Inicio
Electronica
Programacion
Diagrama
Codigo
bit flag; unsigned int cnt; char texto[6]; //Pines de salida para el LCD sbit LCD_RS at RD2_bit; sbit LCD_EN at RD3_bit; sbit LCD_D7 at RD7_bit; sbit LCD_D6 at RD6_bit; sbit LCD_D5 at RD5_bit; sbit LCD_D4 at RD4_bit; //Bits de configuración TRIS sbit LCD_RS_Direction at TRISD2_bit; sbit LCD_EN_Direction at TRISD3_bit; sbit LCD_D7_Direction at TRISD7_bit; sbit LCD_D6_Direction at TRISD6_bit; sbit LCD_D5_Direction at TRISD5_bit; sbit LCD_D4_Direction at TRISD4_bit; void main() { TRISB.F7 = 1; Lcd_Init(); //Inicialización del LCD. Lcd_Cmd(_LCD_CURSOR_OFF); //Se apaga el cursor. Lcd_Out(1, 1," Sensor PIR"); //Se imprime texto. flag = 0; while(1){ //Bucle infinito. if(PORTB.F7 == 1 && flag == 0){ Lcd_Out(2, 1,"Mov. Detectado "); flag = 1; cnt = 0; while(PORTB.F7 == 1){ //mientras el sensor se encuentre activo cnt++; //increnta el contador en 1 unidad Delay_ms(1); //espera 1 milisegundo } } if(PORTB.F7 == 0 && flag == 1){ Lcd_Out(2, 1,"Activo: "); WordToStr(cnt,texto); //convierte el valor del contador en texto Lcd_Out(2, 9,texto); //imprime el valor del contador Lcd_Chr_Cp('m'); Lcd_Chr_Cp('S'); flag = 0; } } }
Descarga del archivo
Descargar archivo