Menu

Can anyone see why my interrup routine fails?

Help
2007-08-03
2013-05-30
  • Nobody/Anonymous

    Trying to build interrupt-driven hardware.  This is the simplest demo program to control a LED; it will eventually form part of a lighting sequencer but I need to get the basics sorted out first.  The idea is that the main loop controls a data structure (in this case just a flag called LEDFLAG) and every ms or so, timer0 generates an interrupt and the routine transfers whatever is in LEDFLAG to the LED.  This routine should flash the LED on and off. But it just sits there and does nothing!

    #chip 16F690, 4
    #config HS_OSC, WDT_OFF
    #define FlashDelay 1 ms

    'set up timer prescale 
    InitTimer0 (Osc,PS0_1/16)

    'enable global and timer interrupts
    set INTCON.GIE = ON
    SET INTCON.T0IE = ON

    'clear the interrupt flag
    SET INTCON.T0IF = OFF

    dir C0 out

    start:
    ledflag = 1
    for i = 1 to 255
    wait flashdelay
    next i
    ledflag = 0
    for i = 1 to 255
    wait flashdelay
    next i
    goto start

    sub interrupt
    if ledflag = 0 then set PORTC.0 OFF
    if ledflag = 1 then set PORTC.0 ON
    'clear the interrupt flag
    SET INTCON.T0IF = OFF
    end sub

     
    • Hugh Considine

      Hugh Considine - 2007-08-03

      One obvious issue I can see is this:

      SET INTCON.T0IF = OFF

      There isn't (or wasn't) meant to be an = in the Set command. Looking at the assembly generated, GCBASIC is actually setting INTCON.T0IF on.

      I've now altered GCBASIC slightly so it will accept = in Set. You can either download the newest GCBASIC release (http://gcbasic.sourceforge.net/newfiles/update.zip) or remove the = from the Set command.

      Something that you may notice with the newest version is that I've disabled the single letter variable name warning for i, j, k and l. This has no effect on the generated code.

       
    • Nobody/Anonymous

      That got it, thanks.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.