I bought a development board from Matrix Multimedia, HP488(datasheet), but I dont know why I fail with a small program.

The program must flash a led with a delay (4 sec) using TMR0. So, from my calculations, using formula : Freq. out = Freq. osc / [prescaler * (256 - TMR0) * count] The prescaler is 1 : 256; TMR0 is 0, anf the frequency oscilator is 4Mhz (osccon = 0b01100000) An instruction is executed in 4 clock cycles. So the frequency clock is 4Mhz / 4 = 1Mhz. count = 61. I use sourceBoost IDE, and the compiler is BoostC.

Look my code :

unsigned int counter = 0; 

void Delay(void) 
  if(intcon & 2)                   // check if TMR0IF is set 
      clear_bit( intcon, 2 );     // if TMR0IF is set, clear this bit
      counter = counter + 1;      // increments the counter       
      if(counter == 61)           
           counter = 0;
           portb = ~portb;        // flash the Led 0 of Port B

void main(void) 
    trisb = 0x00;                    // set all pins of Port B as output
    portb = 0x01;                    // RB0 is high 
    tmr0 = 0;                        // the value of TMR0 register is zero.
    cmcon = 0x07;                    // comparators is off. 
    option_reg = 0b00000111;         // prescaler is assigned to the WDT, prescaler 1:256
    intcon = 0b10100000;             // GIE - enable, TMR0IE - enable
    {   } 

The program compiles fine, upload fine, but dont show me the led flashing. What I am doing wrong ? Are there any configuration settings that I am not aware of ?

  • 2
    \$\begingroup\$ You don't have an Interrupt Service Routine, so how would you expect this to work with an interrupt? \$\endgroup\$
    – user17592
    Jan 20, 2013 at 15:27

1 Answer 1


To make it works as it stands, in your while(1) routine, you need to keep calling your Delay function.
Or, preferably set up an actual ISR (Interrupt Service Routine - this is a routine the main loop jumps to when the interrupt occurs, then jumps back to where if left off from)

Your compiler manual will have information on setting up an ISR.

  • \$\begingroup\$ He mentions the compiler, it's BoostC. But still, pretty bad question indeed. \$\endgroup\$
    – user17592
    Jan 20, 2013 at 16:16
  • \$\begingroup\$ Ah, yes he does (rushing as always...) My apologies to the OP, will edit. \$\endgroup\$
    – Oli Glaser
    Jan 20, 2013 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.