Estoy usando el MPLAB con hitech @ 16f877
En el main si agrego una linea de codigo, el programa deja de funcionar. Es alguna mala configuracion del Timer?
Por ejemplo la linea que esta comentada (// PORTA=0x00;) , si la descomento, compilo, programo y voy a la proto, el PORTB deja de titilar.
Lo mismo me pasa en el proteus.
Encambio si la comento ( una linea menos de codigo ) y programo, anda.
Les dejo el programa. Gracias.
#include <htc.h>
#include <pic.h>
__CONFIG(XT & WDTDIS & PWRTEN & BORDIS & LVPDIS & DUNPROT & WRTEN & DEBUGDIS & UNPROTECT );
#define _XTAL_FREQ 4000000
#define TMR0_TICK 250
#define TMR0_PRESCALE 1 //(FOSC=16MHz,Prescale=3),(FOSC=4MHz,Prescale=1)
#define TMR0_RELOAD (255 - (TMR0_TICK-6))
void TMR0Init(void);
int count=1000;
void main (void)
{
TMR0Init();
TRISB=0x00;
ADCON1=0x06;
TRISA=0x00;
PORTA=0xff;
PORTA=0x00;
PORTA=0xff;
// PORTA=0x00;
while(1)
{
;
}
}
void TMR0Init()
{
TMR0 = 0; // Clear TMR0
INTCON = 0; // Disable all interrupts and clear T0IF
OPTION &= 0xC0; // Turn off least 6 bits to configure tmr0
OPTION |= TMR0_PRESCALE; // set prescaler to 1
TMR0=1;
T0IE = 1; // Enable TMR0 interrupt
GIE = 1; // Enable the global interrupt
}
void interrupt tmr0_isr(void)
{
if(TMR0IF)
{
TMR0 = TMR0_RELOAD;
count++;
if(count == 1000)
{
PORTB=~PORTB; //Toggles LED once per second
count = 0;
}
T0IF = 0;
}
}