interruption

General discussion on mikroC.
Post Reply
Author
Message
ichigohollow
Posts: 1
Joined: 05 Jun 2010 15:07

interruption

#1 Post by ichigohollow » 05 Jun 2010 15:16

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);
}

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: interruption

#2 Post by slavisa.zlatanovic » 07 Jun 2010 13:39

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
Best regards
Slavisa

Post Reply

Return to “mikroC General”