18f4550_timer0_interrupt_test

//source: mikroelectronica's example
 // working code
 //disable lvp_off
//blink led on portb and portd

unsigned cnt;

void interrupt() {
  cnt++;               // Increment value of cnt on every interrupt
  TMR0L  = 96;
  INTCON = 0x20;       // Set T0IE, clear T0IF
}//~

void main() {
  TRISD=0;
  ADCON1 = 0x3F;        // Set AN pins to Digital I/O
  T0CON  = 0xC4;        // Set TMR0 in 8bit mode, assign prescaler to TMR0
  TRISB  = 0;           // PORTB is output
  PORTB  = 0xFF;        // Initialize PORTB
  TMR0L  = 96;          // Timer0 initial value
  INTCON = 0xA0;        // Enable TMRO interrupt
  cnt = 0;              // Initialize cnt
  portb=~portb;

  do {
    if (cnt == 10) {
      pORTD=~PORTD;
      PORTB = ~PORTB;  // Toggle PORTB LEDs
      cnt = 0;         // Reset cnt
    }
  } while(1);          // endless loop
}//~!

Comments

Popular posts from this blog

Inductance caculator

Pointer to object array