Está en la página 1de 3

int X; // segundos transcurriendo en cuenta ascendente int tiempo; // segundos a mostrar en display int flag = 0; // interrupciones int act

= 0; // Bit display activo int luz; // 0 rojo, 1 amarillo, 2 verde; int H7Seg(int digito) ; void main() { // declaracion y configuracion int A; // digito de las decenas int B; // digito de las unidades PIE1.B1=1; // Enables the Timer2 to PR2 match interrupt T2CON = 0xFF; //1:16 Postscaler, Timer2 is on, Prescaler is 16 PR2 = 0xFF; // Flag bit TRISC = 0; // Salidas TRISB = 0; TRISA=0; ANSEL = 0; // Salidas Digitales ANSELH = 0; INTCON.B7 = 1; //Interrupt enable bits INTCON.B6=1; // Semaforo while (1){ if (luz ==0){ tiempo = (30-7)- X; // roja... PORTB.B6 = 1; PORTB.B5=0; PORTB.B4 = 0;} // else if (luz ==1){ // amarilla... tiempo = 3- X;

PORTB.B6 = 0; PORTB.B5=0; PORTB.B4 = 1;} // else if (luz == 2){ // verde... tiempo = (10+7)- X; PORTB.B6 = 0; PORTB.B5=1; PORTB.B4 = 0;} // if (tiempo == 0){ luz++ ; X=0; if (luz>2) luz = 0; // caigo de nuevo en 0 (rojo) } // muestra de resultado A = tiempo/10; B = tiempo - (A*10); // if (act == 0) { act = 1; PORTC = H7Seg(A); PORTB.B1 = 1; // cambio de display PORTB.B0 = 0;} // else{ act = 0; PORTC = H7Seg(B); PORTB.B1 = 0; //cambio de display PORTB.B0 = 1;} //

delay_ms(50); } // table de numeros a mostrar en el display } int H7Seg(int digito){ if (digito == 0) return(0xC0); if (digito == 1) return(0xF9); if (digito == 2) return(0xA4); if (digito == 3) return(0xB0); if (digito == 4) return(0x99); if (digito == 5) return(0x92); if (digito == 6) return(0x82); if (digito == 7) return(0xF8); if (digito == 8) return(0x80); if (digito == 9) return(0x90); } void interrupt(void); void interrupt() { flag++; if (flag >= 78){ // 78 ciclos aprox 1 segundo flag = 0; X++; } PIR1.B1 = 0; // bajo la bandera

También podría gustarte