codigo de luz

Download CODIGO DE LUZ

If you can't read please download the document

Upload: johnnattan-vargas

Post on 14-Dec-2015

3 views

Category:

Documents


0 download

DESCRIPTION

PARA SNESAR LUZ

TRANSCRIPT

#include // Libreria del compilador XC8// Zona de definiciones de constantes#define _XTAL_FREQ 20000000 // para generar retardos en ms y us// Palabra de configuracion#pragma config FOSC=HS, WDTE=OFF, LVP=OFF#pragma config CP=OFF, CPD=OFF, BOREN=ON, PWRTE=ONunsigned char temp;void interrupt ISR(){ //se ejecuta cada 10 milisegundos if(T0IE == 1 && T0IF == 1){ temp++; T0IF = 0; // Limpiar el flag de desborde del TMR0 T0IF = 60; // Para reiniciar el TMR0 }}void main(){ TRISBbits.TRISB0 = 0; // Configuracion del TMR0 OPTION_REGbits.T0CS = 0; // Seleccion del clock interno (Fosc/4) // Preescaler de 1:256 OPTION_REGbits.PS0 = 1; OPTION_REGbits.PS1 = 1; OPTION_REGbits.PS2 = 1; OPTION_REGbits.PSA = 0; // Asignacion del preescaler al TMR0 TMR0 = 60; // Para iniciar la cuenta del TMR0 INTCONbits.T0IE = 1;//habilitacion de la interrupcion por TIMER0 INTCONbits.T0IF = 0;//limpiar la interrupcion INTCONbits.GIE = 1; //habilitacion de interrupcion general while(1){ if(temp==100){ // Despues de 100 veces repetirse la cuenta RB0 = ~RB0; // Para indicar que se cumplio 1 segundo temp = 0; } }}