Instant Interrupts - Revisited


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 773

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Instant Interrupts - Revisited

    This is a series of include files that simplify the process of creating interrupt driven programs for PicBasic Pro. MPASM required.

    Once you try this, you may never use ON INTERRUPT again.

    Features:
    Assembly language Interrupts
    Basic language Interrupts
    Both ASM and Basic interrupts in the same program
    Service Multiple Interrupt sources
    Prioritized execution order
    Very easy to use


    No ON INTERRUPT "Code Bloat"
    No ON INTERRUPT " I'll service your interrupt whenever I feel like it." mentality.
    .
    One of the best things about this system, is that you don't have to remember where all the Enable bits and Interrupt flags are located.

    Each interrupt "source" is given a unique name that is used to reference it.
    The system "Looks Up" the correct bit locations for that name. Reducing those RTFM sessions to a minimum.
    The following table lists the Named Interrupts.
    Note: More interrupts have been added .. please visit http://darreltaylor.com/DT_INTS-14/intro.html

    Available Interrupt Sources 14-bit
    Code:
     INT_INT -- INT External Interrupt
     RBC_INT -- RB Port Change Interrupt
     TMR0_INT -- TMR0 Overflow Interrupt 16F
     TMR1_INT -- TMR1 Overflow Interrupt
     TMR2_INT -- TMR2 to PR2 Match Interrupt
     TX_INT -- USART Transmit Interrupt
     RX_INT -- USART Receive Interrupt
     CMP_INT -- Comparator Interrupt
     EE_INT -- EEPROM/FLASH Write Operation Interrupt
     BUS_INT -- Bus Collision Interrupt
     PSP_INT -- Parallel Slave Port Read/Write Interrupt
     AD_INT -- A/D Converter Interrupt
     SSP_INT -- Master Synchronous Serial Port Interrupt
     CCP1_INT -- CCP1 Interrupt
     CCP2_INT -- CCP2 Interrupt
    Here's a simple example of toggling an LED using the external interrupt (INT). (Hello World)
    Code:
    LED1   VAR  PORTB.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    
        INT_ENABLE   INT_INT     ; enable external (INT) interrupts
    ENDASM
    
    Main:
      PAUSE 1
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    Code Size = 234 words

    This project, and it's associated files, have been moved.
    Please download them from my website.
    DT_INTS-14 (12F-16F)
    http://darreltaylor.com/DT_INTS-14/intro.html

    DT_INTS-18 (18F)
    http://darreltaylor.com/DT_INTS-18/home.html

    .
    Last edited by Darrel Taylor; - 21st January 2014 at 19:20.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Example 2

    The ultimate overkill Blinky Light program ... using Timer 1
    Code:
    LED1   VAR  PORTB.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = $31                ; Prescaler=8, TMR1ON
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    Main:
      PAUSE 1
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    Code Size = 240 words

    OK, Why? ... You might ask.
    Well, for one, this Blinky Light program will continue Blinking at the same rate, no matter what else you add to the Main: program loop. Try doing that with pauses.
    Last edited by Darrel Taylor; - 21st January 2014 at 19:14.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Elapsed Timer

    The NEW Elapsed Timer does, ... well .. it does exactly the same thing as the old Elapsed Timer. But now it works with the Instant Interrupt system. Which means that you can use many other interrupts in the same program without much trouble at all. Unlike the last version.

    Here's an example of just the Elapsed Timer by itself.
    Code:
    INCLUDE "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas"
    INCLUDE "Elapsed_INT.bas"  ; Elapsed Timer Routines
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
        INT_CREATE            ; Creates the interrupt processor
    
        INT_ENABLE  TMR1_INT  ; Enable Timer 1 Interrupts  
    ENDASM
    
    GOSUB ResetTime           ' Reset Time to  0d-00:00:00.00
    GOSUB StartTimer          ' Start the Elapsed Timer
    
    Main:
      IF SecondsChanged = 1 THEN  
         SecondsChanged = 0
         LCDOUT $FE,2, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
      ENDIF
    GOTO Main
    Code Size = 537 Words

    This will create a Clock counting at 1/100 seconds. It runs in the background of PBP without any other program intervention required.

    The time is kept in the variables:
    Code:
        Ticks    var byte   ' 1/100th of a second
        Seconds  var byte   ' 0-59
        Minutes  var byte   ' 0-59
        Hours    var byte   ' 0-23
        Days     var word   ' 0-65535
    The time can be easily displayed with a single line:
    Code:
        LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
    For each of the variables (Seconds, Minutes, Hours and Days) there is a flag
    that indicates when the value of that variable has changed. The Flags are:

    SecondsChanged var bit
    MinutesChanged var bit
    HoursChanged var bit
    DaysChanged var bit

    If you wanted to display the time like a clock, you could wait until
    SecondsChanged = 1, display the time, then reset the flag.

    Code:
        Loop1:
            if SecondsChanged = 1 then
               LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
               SecondsChanged = 0
            endif
        Goto Loop1
    If you only wanted to display the time each minute instead of every second
    just do the same thing using the MinutesChanged flag.

    Code:
        Loop1:
            if MinutesChanged = 1 then
               LCDout $FE,2, dec Days,"d-",dec2 Hours,":",dec2 Minutes
               MinutesChanged = 0
            endif
        Goto Loop1
    The timer can be Stopped and Started, like a stopwatch.
    Code:
        Gosub StopTimer
        Gosub StartTimer
    Attached Files Attached Files
    Last edited by Darrel Taylor; - 21st January 2014 at 19:12.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Bringing them together

    So far I've shown one interrupt source being used at a time, but as I said in the first post, you can easily service Multiple Interrupt Sources.   So what if we wanted to join the previous 3 examples into one program.   NOT a problem!

    To add more interrupt "Handlers", simply add them to the INT_LIST, and create a subroutine for them.

    Since both the Blinky Light, and Elapsed Timer used TMR1, lets move the Blinky Light over to TMR0. Elapsed will still use TMR1.
    Code:
    LED1   VAR  PORTD.0
    LED2   VAR  PORTD.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    INCLUDE "Elapsed_INT.bas"    ' Elapsed Timer Routines
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
            INT_Handler   TMR0_INT,  _ToggleLED2,   PBP,  yes
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    
        INT_ENABLE   INT_INT     ; enable external (INT) interrupts
        INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts
        INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    ENDASM
    
    OPTION_REG = OPTION_REG & $80 | 1  ; Set TMR0 Prescaler to 256, leave RBPU alone
    GOSUB ResetTime              ' Reset Time to  0d-00:00:00.00
    GOSUB StartTimer             ' Start the Elapsed Timer
    
    Main:
        IF SecondsChanged = 1 THEN  
           SecondsChanged = 0
           LCDOUT $FE,$C0, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
        ENDIF
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    
    '---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
    T0Count  VAR WORD
    ToggleLED2:
        T0Count = T0Count + 1
        IF T0Count = 512 THEN T0Count = 0 : TOGGLE LED2
    @ INT_RETURN
    
    <font size=-2>Code Size = 711 Words</font>

    Now we have all three interrupt sources working together in the same program.
    LED1 responds to the external INT
    LED2 flashes, timed by TMR0
    and, the elapsed timer is maintained via TMR1
    And, all of this is happening behind the scenes of your normal PBP program.
    Attached Files Attached Files
    Last edited by ScaleRobotics; - 7th January 2012 at 17:38.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default The Base Layer - ASM interrupts

    <table cellpadding=6><tr><td valign=center></td><td>The Instant Interrupt System consists of several "Layers".

    The Bottom Layer is "DT_INTS-14.bas". This file contains everything required to use Interrupts at the ASM level. &nbsp; It handles all of the "Context Saving/Restoring", detects which interrupt has been triggered, and calls the appropriate "User Routine".

    The next layer up is created from the INT_LIST macro you define in the program. &nbsp; It defines the Interrupt sources to use and the corresponding subroutines that will be called. &nbsp; They can be either simple subroutines, or complete "Modules" in a separate Include file, like the Elapse Timer. &nbsp; Up to 14 separate INT_Handler's can be in the LIST.

    And, the Top Layer is the normal PBP program that runs in the foreground.

    If Basic Laguage interrupts are not being used, then DT_INTS-14.bas is the only file you need to include.</td></tr></table>Here's another example of a Blinky Light program using TMR1 with an Assembly Language Interrupt handler
    Code:
    LED1   VAR  PORTD.0
    LOW  LED1                    ; Set to Output Low
    
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,   ToggleLED1,   ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    
        INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    ENDASM
    
    T1CON = $31                  ; Prescaler=8, TMR1ON
    
    Main:
        PAUSE 1
    GOTO Main
    
    '---[TMR1_INT - interrupt handler]------------------------------------------
    ASM
    ToggleLED1
        btfsc  _LED1
        goto   $+3
        bsf    _LED1
        goto   $+2
        bcf    _LED1
        INT_RETURN
    ENDASM
    
    <font size=-3>Code Size = 104 Words</font>

    Notice that the INT_Handler's Type is ASM, and the Label does not have an underscore before it.<hr><table cellpadding=6><tr><td></td><td valign=top>By using this type of Layering scheme. It allows us more flexability, depending on the type of interrupt we want to use. &nbsp; If we want to add Basic Language Handlers, all we need to do is Include "ReEnterPBP.bas", and it will insert another Layer in-between the Base and the Handlers.

    With this layer included, you can have any combination of ASM and PBP interrupts in the same program</td></tr></table>
    <br>
    Last edited by ScaleRobotics; - 7th January 2012 at 17:33.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default ReEnterPBP.bas - An adaptation of INT_CTRL.pbp

    October 05, 2002 was a good day. &nbsp; Because that's the day that Tim Box released his "INT_CTRL.pbp" program. &nbsp; The original "Instant Interrupts"

    Tim had discovered that the only reason you couldn't use Basic statements in a normal interrupt, was because the PBP system variables currently being used by the statement that got interrupted, would be overwritten by the Basic statements in the interrupt routine. &nbsp; And that, all you have to do is save the state of the system vars at the start of the interrupt, and restore them back to the way they were before exiting the interrupt and you can use any Basic statements you want.

    I've probably said it too many times already but ... Thanks again Tim!
    <hr>
    ReEnterPBP.bas is an adaptation of the same concept, but it allows the Interrupt system to determine if it needs to save the variables or not.

    For instance, if you have a program with both ASM and PBP interrupt handlers, and an interrupt triggers an ASM handler, there's no need to save the variables first, it would just be waisting valuable time. And if more than 1 Basic handler is triggered at the same time, it only saves the variables once, and processes all the Interrupts on the same pass, before restoring the system vars, again saving time.

    However, it does still take a lot of time to save all those variables. Usually it takes around 70 instruction cycles to save the vars. Then another 70 cycles to restore them again. At 4mhz it's 140us total save and restore time, which limits the maximum interrupt frequency to just over 7khz. At 20mhz OSC, you can go up to almost 36khz. That's fast enough to receive RS232 at over 250Kbaud with the USART. &nbsp; But is still considerably slower than you can get with ASM interrupts.

    <br>

  7. #7
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    So far I've shown one interrupt source being used at a time, but as I said in the first post, you can easily service Multiple Interrupt Sources. &nbsp; So what if we wanted to join the previous 3 examples into one program. &nbsp; NOT a problem!

    To add more interrupt "Handlers", simply add them to the INT_LIST, and create a subroutine for them.

    Since both the Blinky Light, and Elapsed Timer used TMR1, lets move the Blinky Light over to TMR0. Elapsed will still use TMR1.
    Code:
    <font color="#000000"><b>LED1   </b><font color="#008000"><b>VAR  </b></font><b>PORTD</b>.<b>0
    LED2   </b><font color="#008000"><b>VAR  </b></font><b>PORTD</b>.<b>1
    
    </b><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;DT_INTS-14.bas&quot;     </font><font color="#0000FF"><b><i>' Base Interrupt System
    </i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;ReEnterPBP.bas&quot;     </font><font color="#0000FF"><b><i>' Include if using PBP interrupts
    </i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;Elapsed_INT.bas&quot;    </font><font color="#0000FF"><b><i>' Elapsed Timer Routines
    
    </i></b></font><font color="#008000"><b>ASM
    </b></font><font color="#000080">INT_LIST  macro    </font><font color="#0000FF"><b><i>; IntSource,        Label,  Type, ResetFlag?
            </i></b></font><font color="#000080">INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
            INT_Handler   TMR0_INT,  _ToggleLED2,   PBP,  yes
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
        INT_CREATE               </font><font color="#0000FF"><b><i>; Creates the interrupt processor
    
        </i></b></font><font color="#000080">INT_ENABLE   INT_INT     </font><font color="#0000FF"><b><i>; enable external (INT) interrupts
        </i></b></font><font color="#000080">INT_ENABLE  TMR0_INT     </font><font color="#0000FF"><b><i>; enable Timer 0 interrupts
        </i></b></font><font color="#000080">INT_ENABLE  TMR1_INT     </font><font color="#0000FF"><b><i>; Enable Timer 1 Interrupts  
    </i></b></font><font color="#008000"><b>ENDASM
    
    </b></font><b>OPTION_REG </b>= <b>OPTION_REG </b>&amp; <b>$80 </b>| <b>1  </b><font color="#0000FF"><b><i>; Set TMR0 Prescaler to 256, leave RBPU alone
    </i></b></font><font color="#008000"><b>GOSUB </b></font><b>ResetTime              </b><font color="#0000FF"><b><i>' Reset Time to  0d-00:00:00.00
    </i></b></font><font color="#008000"><b>GOSUB </b></font><b>StartTimer             </b><font color="#0000FF"><b><i>' Start the Elapsed Timer
    
    </i></b></font><b>Main</b>:
        <font color="#008000"><b>IF </b></font><b>SecondsChanged </b>= <b>1 </b><font color="#008000"><b>THEN  
           </b></font><b>SecondsChanged </b>= <b>0
           </b><font color="#008000"><b>LCDOUT </b></font><b>$FE</b>,<b>$C0</b>, <font color="#008000"><b>DEC </b></font><b>Days</b>,<font color="#FF0000">&quot;d-&quot;</font>,<font color="#008000"><b>DEC2 </b></font><b>Hours</b>,<font color="#FF0000">&quot;:&quot;</font>,<font color="#008000"><b>DEC2 </b></font><b>Minutes</b>,<font color="#FF0000">&quot;:&quot;</font>,<font color="#008000"><b>DEC2 </b></font><b>Seconds
        </b><font color="#008000"><b>ENDIF
    GOTO </b></font><b>Main
    
    </b><font color="#0000FF"><b><i>'---[INT - interrupt handler]---------------------------------------------------
    </i></b></font><b>ToggleLED1</b>:
         <font color="#008000"><b>TOGGLE </b></font><b>LED1
    </b><font color="#000080">@ INT_RETURN
    
    </font><font color="#0000FF"><b><i>'---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
    </i></b></font><b>T0Count  </b><font color="#008000"><b>VAR WORD
    </b></font><b>ToggleLED2</b>:
        <b>T0Count </b>= <b>T0Count </b>+ <b>1
        </b><font color="#008000"><b>IF </b></font><b>T0Count </b>= <b>512 </b><font color="#008000"><b>THEN </b></font><b>T0Count </b>= <b>0 </b>: <font color="#008000"><b>TOGGLE </b></font><b>LED2
    </b><font color="#000080">@ INT_RETURN
    </font>
    <font size=-2>Code Size = 711 Words</font>

    Now we have all three interrupt sources working together in the same program.
    LED1 responds to the external INT
    LED2 flashes, timed by TMR0
    and, the elapsed timer is maintained via TMR1
    And, all of this is happening behind the scenes of your normal PBP program.
    I test for 16f877a and it's work.
    But for the 18f88 i got the message : Symbol not previously defined (T0IF)
    and not compile.Why;

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik View Post
    I test for 16f877a and it's work.
    But for the 18f88 i got the message : Symbol not previously defined (T0IF)
    and not compile.Why;
    That would be a good trick....compiling for an 18F88. I can't seem to find it on the Microchip website.

    Try TMR0IF (a zero after TMR). Or you don't have an up-to-date version of PBP.

    Previous Release: 2.45

    * Adds support for PIC12F508, 509, 683, PIC16F505, 684, 688, 716, 737, 747, 767, 777, 87, 88, PIC18F2331, 2431, 2515, 2525, 2585, 2610, 2620, 2680, 4331, 4431, 4515, 4525, 4585, 4610, 4620, 4680, 6410, 6490, 8410 and 8490.

  9. #9
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Dt_ints-14

    Hello guys,

    I am a newbie to this forum and PIC/PBP.
    I am very glad to have Darrel Taylor's DT_INTS-14 compiled and work great for me.
    I tried to add small routine for receiving data from usart but something start to stop working.

    I posted my code below with all details remaked. Please someone find what have i done wrong.
    I am still in my learning process and am scrolling. Many thanks

    Cheers,
    ozion


    Code:
    '****************************************************************
    '*  Name    : BringTogether_with_RX-USart.BAS                   *
    '*  Notice  :  Using DT_INTS-14                                  *                                 
    '*  MCU     : PIC16F877A                                        *
    '*  Goal    : A string of data from PC via usart will interrupt *
    ''          : the PIC from what it was doing to receive the data,*
    '*          : filter and store received data for processing.    *
    '*          : After received the filtered data, an acknowledge  *
    '*          : will be send back to PC then return to what it was*
    '*          : left off (and processing the received data)       *
    '*          :                                                   *
    '*  Notes   : This program was working without adding Usart RX  *
    '*          : Now
    '*          : Clock works OK                                    *
    '*          : LED1 won't work                                   *
    '*          : LED2 won't work                                   *
    '*          : Usart won't work as expected.                     *
    '****************************************************************
    
    clear
    
    define LOADER_USED 1
    define  OSC 8
    
        ' Define LCD registers and bits
        Define	LCD_DREG	PORTB   ' LCD Data register on PORTB
        Define	LCD_DBIT	4       ' LCD data bits (4 bits)
        Define	LCD_RSREG	PORTB   ' LCD Reset register on PORTB
        Define	LCD_RSBIT	2       ' LCD Reset bit 2 (PORTB.2)
        Define	LCD_EREG	PORTB   ' LCD Enable register on PORTB
        Define	LCD_EBIT	3       ' LCD Enable bit 3 (PORTB.3)
    
    
    ADCON1 = 7						' Set portA outputs to Digital / No ADC
    'CMCON  = 7
    LCDOUT $FE,1                    ' Initialize LCD
    PAUSE  200
    
    dat_in  var byte[10]        ' Added for Usart receive data
    ack     var byte            ' Added for Usart receive acknowledge
    cntr    var byte            ' Added for Usart receive data storage
    LED1    VAR  PORTD.0
    LED2    VAR  PORTD.3
    
    INCLUDE "DT_INTS-14.bas"    ' Required
    INCLUDE "ReEnterPBP.bas"    ' Include if using PBP interrupts
    INCLUDE "Elapsed_INT.bas"   ' Elapsed Timer Routines
    
    ' Initialize USART          ' Added for Usart receive process
    TRISC = %10111111           ' Set PortC.6 to output, rest to input
    DEFINE HSER_BAUD 9600       ' Hser baud rate 
    RCSTA = %10010000           ' Enable serial port and continuous receive
    TXSTA = %00100000           ' Enable transmit and asynchronous mode
    
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED2,   PBP,  yes
            INT_Handler   TMR0_INT,  _ToggleLED1,   PBP,  yes
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
            INT_Handler     RX_INT,  _Read_USART,   PBP,  yes       ; Added
        endm
        INT_CREATE               ; Creates the interrupt processor
    
        INT_ENABLE   INT_INT     ; enable external (INT) interrupts
        INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts
        INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts
        INT_ENABLE   RX_INT      ; enable RX_Usart interrupts       ; Added 
    ENDASM
    
    OPTION_REG = OPTION_REG & $80 | 1  ; Set TMR0 Prescaler to 256, leave RBPU alone
    Gosub ResetTime              ' Reset Time to  0d-00:00:00.00
    Gosub StartTimer             ' Start the Elapsed Timer
    
    Main:
        if SecondsChanged = 1 then  
           SecondsChanged = 0
           LCDout $FE,$C0, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
        endif
        if Ack=1 then              ' Added
           gosub Receive_Ack       ' Added
        endif                      ' Added
        
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         Toggle LED1
    @ INT_RETURN
    
    '---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
    T0Count  Var WORD
    ToggleLED2:
        T0Count = T0Count + 1
        if T0Count = 512 then T0Count = 0 : Toggle LED2
    @ INT_RETURN
    '////////////////////////////////////////////////////////////////////////////////////
    'Added to read Usart
    Read_USART:                                              
        hserin[dat_in]
            '===========================================================================
            'The following 2 lines won't work
            'hserin[wait("X"),str dat_in\5]	' Wait for X ;receive a string of characters 
            'hserin[wait("X"),dat_in]	' Wait for X
            '=========================================================================== 
        'Following lines send back string includes first dectect char "$"
        'Example: PC sent:              "12345$6789"
        '         PIC send back to PC   "12345$"
        ack=0                               ' clear ack
        cntr=0                              ' reset counter
        while cntr<10                       ' looping
            if (dat_in[cntr]= "$") then     ' filter character "$"
                HSEROUT[str dat_in,cntr]    '
                ack=1                       ' Yes found "$"
                cntr=10                     ' get out of loop
            endif                           '
            cntr=cntr+1                     ' increment counter
        wend                                '
        HSEROUT[str dat_in]                 ' send to PC
        'gosub Receive_Ack                  ' This doesn't works it does not call Receive_Ack
    @ INT_RETURN
    
    Receive_Ack:
        if ack=1 then
            HSEROUT ["got it:"]
            HSEROUT[str dat_in]             ' Send dat_in received string           
        endif
        ack=0
    return
    '//////////////////////////////////////////////////////////////////////////////
    Last edited by Darrel Taylor; - 7th September 2006 at 06:20. Reason: added [code][/code] tags

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi ozion,

    First rule of interrupts, Never Wait for anything.

    Interrupt handlers should execute as fast as possible, and exit as soon as possible.

    With 18F's you can get away with using HSERIN/HSEROUT with Waits and Pauses, by putting them in a LOW priority interrupt handler. But with the 16F's, you don't have that option.

    If you want to use interrupts to receive serial data on 16F's, then you should only grab 1 byte at a time then exit. You can keep track of how many bytes have been received and set a Flag when finished so that it can be dealt with in the Main loop. Then you can HSEROUT to your hearts content.

    Otherwise, do all the serial stuff in the main loop, RX and TX. The main loop should run fast enough to catch everything. And the interrupts will continue on like they should.

    HTH,
    &nbsp; Darrel

  11. #11
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    5


    Did you find this post helpful? Yes | No

    Thumbs up Instant Interrupt

    Hi Darrel,

    Thanks for reply, I will try that your suggestion.

    Regards,
    ozion

  12. #12
    ra68gi's Avatar
    ra68gi Guest


    Did you find this post helpful? Yes | No

    Smile

    Hi Darrel,
    I have just started to use the instant interrupts. Previously i had used 8051 and the bascom compiler. I wanted to set priority to the various interrupts similar to the 8051. in the 8051 the lower priority interrupts can be interrupted by the higher priority interrupts. I can see that we can set priority only in 18F series of pic and not in 16F.

    Can we not have priority in 16F pics?

    Again i think among the high priority interrupts, those interrupts we would like to service it immediately we place their interrupt handler at the top, but i dont think by doing that we can exit the current high priority interrupt service routine to go and attend another interrupt whose interrupt handler is placed before the current executing interrupt's handler. Meaning to say nesting of interrupts is not possible here. One has to wait until the current ISR is finished to enter into another ISR.
    Am i right in saying that Darrel? If that is the case then for any time measuring program we must make sure that the ISR of each of the interrupts are so small that they dont cause a large error in measurement.

    Please comment.

    Raghunathan

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    That's correct.

    No priorities for 16F's. It's a limitation of the PIC's, not the Instant Interrupts.

    >> then for any time measuring program we must make sure that the ISR of each of the interrupts are so small that they dont cause a large error in measurement.

    Unless you use the capture mode of a CCP module, also true.

    But if you switch to 18F's, the problem goes away.
    <br>
    DT

  14. #14
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default On Change style Int with RB0

    Hi,

    I hope this is the right place to grab your attention. I am using a 16F73 @ 20Mhz with Hardware USART @ 115Kbps. I am using RB0 external interrupt portb.0 (can't help it only it is available) . Initially it is set to fire interrupt on a Low2High edge. Now when inside the interrupt I want to toggle the INT edge bit in the option_reg to have an interrupt on High2Low edge. The simple idea is to reset a timer when a variable duty cycle pulse begin and read the timer value when it turns off. Can't sit in a tight loop to watch if portb.0 = 0 cause got other tasks to do. So I am using Darrel's INT in both ASM and PBP. Here is the code:

    Code:
    ASM
    INT_LIST macro   ; IntSource,  Label,         Type,  ResetFlag?
        INT_Handler  INT_INT,     INT_ASM,        ASM,   NO
        INT_Handler  INT_INT,     _INT_PBP,        PBP,   YES    
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM    
    
    ; BELOW IS THE ASM INTERRUPT HANDLER
    ASM
    INT_ASM
           BSF   STATUS, RP0             ; SELECT BANK 1
           BTFSS OPTION_REG, INTEDG      ; CHECK THE INTERRUPT EDGE
           GOTO  EDGE_LOW
    
    ; IF HERE THEN EDGE IS HIGH2LOW AND INT OCCURED AND NEEDS TO BE ALTERED/////////
    EDGE_HIGH
           BCF   OPTION_REG, INTEDG      ; SET TO INTERRUPT ON LOW2HIGH TRANSITION
           CLRF  STATUS                  ; SELECT BANK0
           CLRF  TMR0                    ; CLEAR TIMER0
           BSF   _HIGH_EDGE              ; SET FLAG THAT THIS IS A LOW2HIGH_EDGE INT
           INT_RETURN                    ; RETURN FROM THE ASM INTERRUPT
    ; IF HERE THEN EDGE IS LOW2HIGH AND INT OCCURED AND NEEDS TO BE ALTERED ////////       
    EDGE_LOW       
            ; BANK1 IS ALREADY SELECTED
           BSF   OPTION_REG, INTEDG      ; SET TO INTERRUPT ON LOW
           CLRF  STATUS                  ; SELECT BANK0
           MOVF  TMR0, 0                 ; MOVE TIMER0 TO W
           MOVWF _TIMER                  ; MOVE TO THE TIMER VARIABLE IN BANK 0
           BCF   _HIGH_EDGE              ; SET FLAG THAT THIS IS HIGH2LOW_EDGE INT
           INT_RETURN                    ; RETURN FROM THE ASM INTERRUPT
    ENDASM
    
    INT_PBP:                     '  PBP INTERRUPT HANDLER
    IF HIGH_EDGE = 1 THEN        '
    HSEROUT [10,"L2H",10]        '
    @ INT_RETURN                 ; RETURN FROM INSTANT INTERRUPT
    ELSE
    HSEROUT [10,"H2L",#TIMER, 10]
    ENDIF
    @ INT_RETURN                 ; RETURN FROM INSTANT INTERRUPT
    Now my questions are :

    1. Will this work ? Chances of false interrupt should not be, cause anyway while changing the option_reg the INT0 flag is not cleared and taken care of in the next PBP slice. Am I right ?

    2. Should I manually check the transmit buffert (TRMT) and do the transmission to make things faster or let it be handled by PBP (keeps my hairfall under control )

    P.S. : Actually I am counting on the email notification and everybody working with Darrel's II . Lester/Darrel please move this thread if you think that this should go as a new thread.
    Last edited by sougata; - 13th March 2007 at 19:26.
    Regards

    Sougata

  15. #15
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    As far as the interrupt routines go, it looks like it should work.

    But the limiting factor is the number of bytes you're sending the results with.
    Even at 115200, sending a string of 10 characters will take over 800us. With trying to find both high and low transitions you double that (1600us). So you'd be limiting the frequency to around 600hz.

    I don't think a buffer and TX handler would help speed it up, because it's just the total amount of data being sent that limits it. A buffer would just over-run if it couldn't keep up.

    HTH,
    DT

  16. #16
    IE Ray's Avatar
    IE Ray Guest


    Did you find this post helpful? Yes | No

    Default CAN interrupt

    I have used the 18FXXX interupts, great stuff, does what is says on the tin. Taking things a stage further, are there and routines for the CAN interface for the 18F258/18F2580 chips?

    Thanks Ray

  17. #17
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    This is gonna sound like a dumb question.

    Where can I download the files for DT_INTS-18? I've been to Darrels website but cant find the link...

    http://darreltaylor.com/DT_INTS-18/home.html

    Can anyone help me out?

    Cheers
    Squib

  18. #18
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Nah, it's not a dumb question. Knowing what happened last week, it's probably normal than few things are missing on his website.

    I've attach ALL files.

    Quote Originally Posted by DT
    ** Files removed **
    They're back on the website again.

    Thanks Steve!
    DT
    Last edited by Darrel Taylor; - 11th June 2007 at 07:45. Reason: removed files
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  19. #19
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Nope, not a dumb question.

    But I got a dumb answer.

    The site was recently hacked by some Turkish Hacker Group. (Dirty Rats)

    The "dumb" part is that I haven't made a backup in over a year.
    So that's what the site looks like now. Same as a year+ ago.

    I'm so digusted at myself, I've not even been able to start the repairs.
    Every time I look at it, I just go .... "Uughhh! I don't want to do that right now."

    Thanks Steve, that ought to help out, for awhile.

    Regards,
    DT

  20. #20
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Thumbs down These bloody &*%^%

    These bloody ******* I tell you. I'd like to see them locked up. Weekly, sometimes even daily, I receive a dozen or so emails from fraudulent individuals either telling me that I've won the lottery (the motivation behind this is identity theft) - or requesting that I go and login into my bank account on their copied fraudulent web site.

    The internet needs to be policed by people that have the power to shut an operation down with as little as two keystrokes and a couple of clicks of the mouse.
    Last edited by T.Jackson; - 14th May 2007 at 06:41.

  21. #21
    Join Date
    Apr 2004
    Posts
    34


    Did you find this post helpful? Yes | No

    Thumbs up

    Thank you for the fast response!

    Regards

  22. #22
    Join Date
    Sep 2007
    Posts
    19


    Did you find this post helpful? Yes | No

    Question 16F689 and DT INT14

    After reviewing all posts on INT14.



    Added

    RBIF = RABIF
    RBIE = RABIE to after ASM and just before INT_LIST.

    @ INT_ENABLE RBC_INT

    I can't get simple blinky to work and the errors are as listed.

    I get few errors as shown

    Error testin~1.ASM 985:[224] local directive only for use in macros
    :[225] undefined symbol 'iflagreg'
    :[226] numeric constant or symbol name expected
    Fatal TESTIN~1.ASM 895:[300] too many errors.



    Any idea?

  23. #23
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You have to be using MPASM as the assembler.
    The default PM assembler will not work.
    <br>
    DT

  24. #24
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Darrel,
    How about a little tutorial on how to tell which assembler is in use, and how to switch to the mpasm?

  25. #25
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    OK, how bout this for detection ...
    Code:
    ASM
      ifdef PM_USED
           "Dude, you have to use MPASM with DT_INTS"
      endif
    ENDASM
    If you put that in your program, and try to assemble it with PM.exe, It will automatically pop-up a window in MicroCode Studio like this ...

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2450&stc=1&d=120694493 9" />

    Then you can just click on "Compile Using MPASM", and it will set the MPASM option and compile it.

    If it still fails to compile, you should try this ...
    http://www.picbasic.co.uk/forum/show...5&postcount=11

    I should add that to DT_INTS-14.

    hth,
    <br>
    Attached Images Attached Images  
    DT

  26. #26
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126


    Did you find this post helpful? Yes | No

    Default Issue with Timer0 and setting prescaler

    I have been playing with the code shown below on a 16f737 as I was trying to get different prescaler values into the int routinues. As part of the testing I stripped the code right back to just be a simple interrupt with a value loaded into the pre-load registrer, but I seem to end up with an interrupt time of 204uS. According to the Timer Calc in Mister E's PicMulti Calc I should get an interrupt every 5.019mS. (see attached image for capture of the output waveform - I love my PICkit 2!)

    This code is lifted straight from Darells example with the blinky led (1-2-3 version), and all I have done is add the pre-load. I have also removed the pre-load and still get the same time for the interrupt.

    Code:
    DEFINE OSC 20
    
    rs_led      var portb.7 ' rs232 led
    led         var portc.4 ' was Data_Out line
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
           INT_Handler   TMR0_INT,  _doBAM,   PBP,  yes
         endm
        INT_CREATE     ; Creates the interrupt processor
    ENDASM
    
    OPTION_REG = OPTION_REG & $80 | 1     'Set TMR0 Prescaler to 256, leave RBPU alone
    
    TMR0 =  158 ' preload with 158 to give 21uS interrupts (at 1:1)
    ' this should then give Interrupt every 5.019mS at 1:256
    
    @ INT_ENABLE  TMR0_INT     ; enable Timer 1 interrupts
    '~~~~~~~~~~~~~~~~~~
    
    goto main      ' jump over ISR
    
    '---[TMR0 - interrupt handler]--------------------------------------------------
    doBAM:
    toggle rs_led
    @ INT_RETURN
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~
     high rs_led
    main:
    
    '''''''''''''''''''''''
    ' do some flashing led stuff
    '''''''''''''''''''''''
    high led
    pause 500
    low led
    pause 500
    goto main
    There has got to be something really simple I am missing...
    bill.
    Attached Images Attached Images  
    Last edited by bcd; - 1st May 2008 at 10:19. Reason: Clarification of a few things

  27. #27
    Join Date
    Mar 2008
    Location
    london
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    This is a series of include files that simplify the process of creating interrupt driven programs for PicBasic Pro. MPASM required.

    Once you try this, you may never use ON INTERRUPT again.
    <table border=0 cellpadding=5><tr><td valign=top>
    Features:
    Assembly language Interrupts
    Basic language Interrupts
    Both ASM and Basic interrupts in the same program
    Service Multiple Interrupt sources
    Prioritized execution order
    Very easy to use


    No ON INTERRUPT "Code Bloat"
    No ON INTERRUPT " I'll service your interrupt
    &nbsp; whenever I feel like it." mentality.
    One of the best things about this system, is that you don't have to remember where all the Enable bits and Interrupt flags are located.

    Each interrupt "source" is given a unique name that is used to reference it. The system "Looks Up" the correct bit locations for that name. &nbsp; Reducing those RTFM sessions to a minimum. &nbsp; The table to the right lists the Named Interrupts.



    </td><td ><table border=1 cellpadding=5><tr><td valign=top nowrap> <center><b>Available Interrupt Sources</b> &nbsp; 14-bit</center><pre> INT_INT -- INT External Interrupt<br> RBC_INT -- RB Port Change Interrupt<br> TMR0_INT -- TMR0 Overflow Interrupt 16F<br> TMR1_INT -- TMR1 Overflow Interrupt<br> TMR2_INT -- TMR2 to PR2 Match Interrupt<br> TX_INT -- USART Transmit Interrupt<br> RX_INT -- USART Receive Interrupt<br> CMP_INT -- Comparator Interrupt<br> EE_INT -- EEPROM/FLASH Write Operation Interrupt<br> BUS_INT -- Bus Collision Interrupt<br> PSP_INT -- Parallel Slave Port Read/Write Interrupt<br> AD_INT -- A/D Converter Interrupt<br> SSP_INT -- Master Synchronous Serial Port Interrupt<br> CCP1_INT -- CCP1 Interrupt<br> CCP2_INT -- CCP2 Interrupt</pre></td></tr></table></td></tr></table>Here's a simple example of toggling an LED using the external interrupt (INT). (Hello World)
    Code:
    <font color="#000000"><b>LED1   </b><font color="#008000"><b>VAR  </b></font><b>PORTB</b>.<b>1
    
    </b><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;DT_INTS-14.bas&quot;     </font><font color="#0000FF"><b><i>' Base Interrupt System
    </i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;ReEnterPBP.bas&quot;     </font><font color="#0000FF"><b><i>' Include if using PBP interrupts
    
    </i></b></font><font color="#008000"><b>ASM
    </b></font><font color="#000080">INT_LIST  macro    </font><font color="#0000FF"><b><i>; IntSource,        Label,  Type, ResetFlag?
            </i></b></font><font color="#000080">INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               </font><font color="#0000FF"><b><i>; Creates the interrupt processor
    
        </i></b></font><font color="#000080">INT_ENABLE   INT_INT     </font><font color="#0000FF"><b><i>; enable external (INT) interrupts
    </i></b></font><font color="#008000"><b>ENDASM
    
    </b></font><b>Main</b>:
      <font color="#008000"><b>PAUSE </b></font><b>1
    </b><font color="#008000"><b>GOTO </b></font><b>Main
    
    </b><font color="#0000FF"><b><i>'---[INT - interrupt handler]---------------------------------------------------
    </i></b></font><b>ToggleLED1</b>:
         <font color="#008000"><b>TOGGLE </b></font><b>LED1
    </b><font color="#000080">@ INT_RETURN</font>
    <font size=-2>Code Size = 234 words</font>
    <script language="javascript" src="http://www.darreltaylor.com/files/forum_ii.js"></script>

    This project, and it's associated files, have been moved.
    Please download them from my website.
    DT_INTS-14 (12F-16F)
    http://darreltaylor.com/DT_INTS-14/intro.html

    DT_INTS-18 (18F)
    http://darreltaylor.com/DT_INTS-18/home.html

    <br>
    hello,
    i just tested the program with the 16f88 but it s not working , there are some error messages.

    dont know exactly what to do next
    can u give me some advices please??
    thanx

  28. #28
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    NO.. at least give more details... error message, code etc etc

    Make sure you're using MPASM to compile
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  29. #29
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    NO.. at least give more details... error message, code etc etc
    Make sure you're using MPASM to compile
    Judging from the:
    @ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF
    in the rest of the posts...hmmmmmmmmmmm........

  30. #30
    Join Date
    Jul 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    WoW!

    those routines works like magic for a noobie like me

    I've found out that most of my code must be done inside the interrupt part, otherwise if it's in the Main loop it can get trashed by the interrupt(like SEROUT to a serial LCD), but it got my
    latest project running very quickly.



    tnx Darrel

  31. #31


    Did you find this post helpful? Yes | No

    Default Int_return

    First of all thanx for the code my interups now gets handeled fast enoug so i dont loose any serial data, one problem for some reason my program do not return from the interupt.
    Any ideas
    i use a 16f913

    Code:
    INCLUDE "MODEDEFS.BAS"
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    
    DEFINE OSC 20				' Define crystal as 20Mhz
    
    '*Serial port Setup 9600 8N1*
    DEFINE HSER_BAUD 9600 		; 9600 Baud 
    DEFINE HSER_RCSTA 90h 		' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h 		' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1  		; Clear overflow automatically   
    
    '*ADC setup*
    DEFINE ADC_BITS 10 			'SETS NUMBER OF BITS IN RESULTS 8,10,12
    DEFINE ADC_CLOCK 3 			'SETS CLOCK SOURCE (RC = 3)
    DEFINE ADC_SAMPLEUS 50 		'SETS SAMPLING TIME IN MICROSECONDS
     
    'This Part set PORTA 0-5 an analog inputs
    ADCON1 = %01110000			'FRC (clock derived from a dedicated internal oscillator = 500 kHz max)
    ANSEL  = %00011111			'The ANSEL (91h) and CMCON0 (9Ch)registers must be initialized to configure an
    CMCON0 = %00000111			'analog channel as a digital input. Pins configured as analog inputs will read ‘0’.
    TRISA  = %00011111			'set PORTA 0-5 as inputs
    ADCON0.7 = 1				'Right justify output of ADC datasheet P145 of 16F913 
        
    TRISC = %10000000			'Set PORTC for serial coms and pins  as output   
    TRISB = %00000000			'Sert PORTb as outputs and for use with the ICD2
    
    V1 var WORD
    ID var byte[28]
    CELL1	VAR BYTE[11]
    I	VAR BYTE
    
    PORTC = 0
    
    ASM
    INT_LIST  macro ; IntSource,        Label,  Type, ResetFlag?
        INT_Handler    RX_INT,  _IntLoop,   ASM,  yes
        endm
        INT_CREATE               		; Creates the interrupt processor
    	INT_ENABLE   RX_INT     		; enable external (RX) interrupts
    
    ENDASM
    
    
    Main:
    		PORTC.5=1
    		PAUSE 200
    		PORTC.5=0
    		PAUSE 200
    		PORTC.5=1
    		PAUSE 200
    		PORTC.5=0
    goto Main
    
    IntLoop:
    	HSERIN [WAIT("^SMGL:"),SKIP 1 ,str ID\28]
        HSEROUT ["CELL NO:",_
              ID[17],iD[18],ID[19],ID[20],ID[21],ID[22],_
              ID[23],ID[24],ID[25],ID[26],ID[27],10,13]
    @ INT_RETURN
    
    END

  32. #32
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796


    Did you find this post helpful? Yes | No

    Default

    As Steve noted on many post before:

    Quote Originally Posted by mister_e View Post
    NO.. at least give more details... error message, code etc etc

    Make sure you're using MPASM to compile
    We are not fortune tellers here. More input as Johnny 5 said once!

    Ioannis

  33. #33
    Join Date
    Jun 2008
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Well,
    First I was asking if someone has problems with INT when using the BPI-216 LCD.
    Anyway,
    When using this code on my 16F887, The LCD gets freaked.
    I will just display junk. I tried to eliminate some of the timers, and as said before, When having only INT for button or for clock it reduce the junk.

    Other code which implemets clock without INT but just timer, (http://www.picbasic.co.uk/forum/showthread.php?t=2129) works perfect with this LCD.
    Here is the code that makes it go crazy:
    Code:
    LED1   VAR  PORTD.0
    LED2   VAR  PORTD.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    INCLUDE "Elapsed_INT.bas"    ' Elapsed Timer Routines
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
            INT_Handler   TMR0_INT,  _ToggleLED2,   PBP,  yes
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    OPTION_REG = OPTION_REG & $80 | 1  ; Set TMR0 Prescaler to 256, leave RBPU alone
    @    INT_ENABLE   INT_INT     ; enable external (INT) interrupts
    @    INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts
    @    INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    
    GOSUB ResetTime              ' Reset Time to  0d-00:00:00.00
    GOSUB StartTimer             ' Start the Elapsed Timer
    
    Main:
      IF SecondsChanged = 1 THEN  
         SecondsChanged = 0
            IF Hours>9 THEN
              SEROUT PORTB.1,6,[254,128,#Hours,58]
              pause 300
                ELSE
                  SEROUT PORTB.1,6,[254,128,48,#Hours,58]
                  pause 30
            ENDIF
            IF Minutes>9 THEN
              SEROUT PORTB.1,6,[254,131,#Minutes,58]
              pause 300
                ELSE
                  SEROUT PORTB.1,6,[254,131,48,#Minutes,58]
                  pause 300
            ENDIF
            IF Seconds>9 THEN
              SEROUT PORTB.1,6,[254,134,#Seconds]
              pause 300
                ELSE
                  SEROUT PORTB.1,6,[254,134,48,#Seconds]
                  pause 300
            ENDIF
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    
    '---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
    T0Count  VAR WORD
    ToggleLED2:
        T0Count = T0Count + 1
        IF T0Count = 512 THEN T0Count = 0 : TOGGLE LED2
    @ INT_RETURN

  34. #34
    Join Date
    Jun 2008
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    btw,
    If I disable INT (INTCON=0) the LCD shows correctly, but of ocurse interrupts are not working.

  35. #35
    Join Date
    Jun 2005
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Hi--

    I'm having a problem with Instant Interrupts that I can't figure out... I'm using Darrell's Elapsed Timer with V3.2 of DT_INTS-18 and Reenter-PBP-18. The chip is an 18F4520 running at 16MHz. The interrupt-driven elapsed timer system works beautifully, but then I can no longer use the second PWM output, CCP2, which I have set up to output on portc.1. CCP1 works perfectly. This is true whether I use the HPWM command and PBP defines or set up the PWM registers directly as described in the data sheet.

    What happens is that portc.1 goes low and stays that way. If I disable the DT includes and the interrupt handler, the PWM CCP2 port functions normally. I have checked and double checked things like the portb/c multiplexing and the tris output settings, etc. What I think is happening is something in Darrrell's code is clearing CCP2CON, but I haven't been able to find it.

    Does anybody have any ideas to try?

    Thanks--

    --Alan

  36. #36
    Join Date
    Aug 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Exclamation DT_INTS breaks pulsein/count PBP routines?

    Is this true? I can believe it to be. If so, is there any way I can replace this functionality using the interrupt driven counters or something? A hardware counter is not an option unfortunately, as the board is already in units in the field.

    The reason I need to add interrupts is because I need to add background hardware UART character reception using UART2 because the program spends too much time doing other things in the foreground to service the port soon enough.

    Is there a list of what PBP functions are affected by DT_INTS? If so where can I find it?

    Does anyone have examples of interrupt driven serial IO using DT_INTS? How about pulse counting routines?

    Thanks,
    Mike

  37. #37
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Changing direction after INT

    I'm trying to understand how to return to a specific place when coming out of a INT.

    Specifically, when I receive a command serially and trip the RX_INT, I need to abort the current operation in the main body of the program and restart with the newly commanded mode.
    I have looked at DT_INTS and other advise on interrupts, and still don't understand what I would need to change to get this to happen.
    The code works otherwise and gathers the command from the serial line, its just that I have to wait for the current operation to complete for it to be recognized and acted upon.

    The main code is driving patterns on 8 LEDS with SPWM_INT and it takes 10 or 20 seconds for it to get around to the place where it looks at the new mode. This also applies when I change the mode with a switch input. I have to wait until the operation is finished to get to the part where I look for the input.

    I don't believe that I can just mess with the RetAddr variable in DT_INTS and have that work without other steps. If I have a GOTO in the ISR, then I would likely corrupt the RETURN. I could just sprinkle switch and comm checks all over the place looking for flags, but that seems mediocre. Any advise?

    Thanks
    Mark

  38. #38
    Join Date
    Dec 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Thumbs up 7 seg display with rs232 data input

    I was testing with darrel Taylor Instant interrups. The colaboration is fantastic. Great.

    I mount four 7 seg, 4 inches each, with common anode, and the 16f877A. The input for data is the serial input, across portc.7. I probe fist without darrel tool, using on interrupts and I see that the serial input line stop de scan for the 7 segs, because the multiplexing loss the times in this waiting for the data. Each display is activate with portd.4 to portd.7

    The circuit work fine, so, the program need tuning up.

    When I used the Darrel tool, the time for the 7 segs scan don't change with the data wait in the serian in line, including this part in the main loop. The scan for the multiplexing is in instant interrup routine. My dude, in this case, is with time multiplexing scan. I not Know what is the lines for the scan, and in this moment, i only see the scan very slow.

    I need help for to put the timer a time for correct and fast scan.

    Thanks.

    Luis Elizarraraz

  39. #39
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    If you are using an interrupt handler to receive the serial data, then nothing else can happen until the handler is finished.

    If other things must continue operating at the same time, you either have to read the serial data 1 byte per interrupt, or have the HSERIN statement in the main loop so that it can be interrupted like everthing else.

    Sitting in the handler WAITing for the data, will not work.
    <br>
    DT

  40. #40
    Join Date
    Jun 2008
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    I'm having problems with my LCD (BPI-216) when using these intterupts.
    When using the code for the clock interrupt and button interrupt the LCD display junk.
    If using only one of the intterupts the junk is less, but still.
    It is mostly happen if pressing then button very often.
    Can someone advice?
    Last edited by menta; - 22nd June 2008 at 22:37.

Similar Threads

  1. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 22:43
  2. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 21:02
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 21:48
  4. Keypad and DT's Instant Interrupts
    By Homerclese in forum General
    Replies: 11
    Last Post: - 27th April 2007, 07:32
  5. Replies: 1
    Last Post: - 1st November 2006, 04:11

Members who have read this thread : 9

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts