Page 1 of 1

interruption

Posted: 05 Jun 2010 15:16
by ichigohollow
i have a program in microc in which i'll show a message throw a LCD 16*2 and i use an interruption of timer0 but the simulation in Proteus isis don't work
this is my program if there ara mistakes

unsigned cnt;

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

void main()
{
OPTION_REG = 0x84; // Assign prescaler to TMR0

TRISB = 0;
TMR0 = 96; // Timer0 initial value
INTCON = 0x90; // Enable TMRO interrupt
cnt = 0; // Initialize cnt
lcd_init(&PORTB); //initialisation de l'afficheur
do {
if (cnt == 400)
{
lcd_out(1,1,"A");
//delay_ms(1000);
cnt = 0; // Reset cnt
}
} while(1);
}

Re: interruption

Posted: 07 Jun 2010 13:39
by slavisa.zlatanovic
Hi!

It seems that you've forgotten to turn ON interrupts(GIE bit in INTCON).

Code: Select all

INTCON = 0xA0;           // GIE=1; TMRO=1;

Try the code below (written for 18F887 MCU):

Code: Select all

unsigned cnt;

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

void main() {
  OPTION_REG = 0x84;       // Assign prescaler to TMR0
  ANSEL  = 0;              // Configure AN pins as digital I/O
  ANSELH = 0;
  TRISB = 0;               // PORTB is output
  PORTB = 0xFF;            // Initialize PORTB
  TMR0  = 96;              // Timer0 initial value
  INTCON = 0xA0;           // Enable TMRO interrupt
  cnt = 0;                 // Initialize cnt

  do {
    if (cnt == 400) {
      PORTB = ~PORTB;      // Toggle PORTB LEDs
      cnt = 0;             // Reset cnt
      }
    } while(1);
}
Best regards
Slavisa