Change On Interrupt, PIC16F884


Results 1 to 18 of 18

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    with code bracket
    I type
    [code]
    i now paste my code here
    then i type [/code]

    we got
    Code:
            asm ; The following code is assembly, not Basic
                    __CONFIG _CONFIG1, _INTOSCIO & _WDT_OFF & _PWRTE_ON & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF & _LVP_OFF
                    ; Use internal oscillator & make both, OSC pins I/Os, turn off watchdog timer, enable Power-up timer,
                    ; code protection off, brown-out off, disable switch over mode, turn off failsafe monitor,
                    ; low voltage programming off
            endasm ' End assembly code
    
            define OSC 8        ' Tell the program the oscillator is running at 8 MHz
            OSCCON.6 = 1        ; Set the internal oscillator to 8MHz
            OSCCON.5 = 1        ; Set the internal oscillator to 8MHz
            OSCCON.4 = 1        ; Set the internal oscillator to 8MHz
    
            PORTA = $00         ' Set all port a pins to low
            PORTB = $00         ' Set all port b pins to low
            PORTC = $00         ' Set all port c pins to low
            PORTD = $00         ' Set all port d pins to low
            PORTE = $00         ' Set all port e pins to low
    
            TRISA = %00000000   ' Make all port a pins outputs
            TRISB = %00001111   ' Make port b pins 0-3 inputs and the rest as outputs
            TRISC = %00000000   ' Make all port c pins outputs
            TRISD = %00000000   ' Make all port d pins outputs
            TRISE = %00000000   ' Make all port e pins outputs
            
            ADCON0.0 = 0        ; Make all analog pins digital I/Os
            CM1CON0.7 = 0       ; Disable comparator C1
            CM2CON0.7 = 0       ; Disable comparator C2
            WDTCON.0 = 0        ; Disable the watchdog timer
            ANSEL = %00000000   ; Set all analog pins on port a to digital I/O
            ANSELH = %00000000  ; Set all analog pins on port b to digital I/O
            
            INCLUDE "modedefs.bas"
    
    'Variables*****************************************************************************************
            b0 VAR byte         ' Required byte variable for toggle button
    
    
    '**************************************************************************************************
    INITIALIZE:                 ' Initialize Routine
            INTCON.0 = 0        ' Clear the interrupt-on-change flag
            On Interrupt goto Halt ' Once an active interrupt port is enabled, go to the Halt routine
            INTCON = %10001000  ' Enable global interrupts, Enable interrupt-on-change on Port b
            IOCB = %00000011    ' Enable interrupt-on-change on RB0-RB3
            PORTE.1 = 0         ' Make sure LED on PORTE.1 is off
            PORTE.2 = 0         ' Make sure LED on PORTE.2 is off
    
    
    '*************************************************************************************************** *
    MAIN:
            HIGH PORTE.0
            PAUSE 500
            LOW PORTE.0
            PAUSE 500
            GOTO MAIN
    
    
    '*************************************************
            DISABLE         ' do NOT place interrupt checking code below
            
    Halt:   ' Halt Routine
            IF PORTB.0 = 0 THEN
                    WHILE PORTB.0=0 ' wait for button release & end mismatch condition on portb
                    WEND
                    PAUSE 20        ' Debounce delay
                    HIGH PORTE.1
                    LOW PORTE.2
                    ENDIF
                    
            IF PORTB.1 = 0 THEN
                    WHILE PORTB.1=0 ' wait for button release & end mismatch condition on portb
                    WEND            
                    PAUSE 20        ' Debounce delay
                    LOW PORTE.1
                    HIGH PORTE.2
                    ENDIF
           
            INTCON.0 = 0            ' Clear the interrupt-on-change flag
            RESUME                  ' Go to Main routine
            ENABLE                  ' Enable all active interrupts
    with colors, following the following thread
    http://www.picbasic.co.uk/forum/show...ht=show+colors

    we got
    Code:
    <font color="#000000">        <font color="#000080">ASM </font><font color="#008000">; The following code is assembly, not Basic
                    </font><font color="#000080">__CONFIG _CONFIG1, _INTOSCIO &amp; _WDT_OFF &amp; _PWRTE_ON &amp; _CP_OFF &amp; _BOR_OFF &amp; _IESO_OFF &amp; _FCMEN_OFF &amp; _LVP_OFF
                    </font><font color="#008000">; Use internal oscillator &amp; make both, OSC pins I/Os, turn off watchdog timer, enable Power-up timer,
                    ; code protection off, brown-out off, disable switch over mode, turn off failsafe monitor,
                    ; low voltage programming off
            </font><font color="#000080">ENDASM </font><font color="#008000">' End assembly code
    
            </font><font color="#000080">DEFINE </font>OSC 8        <font color="#008000">' Tell the program the oscillator is running at 8 MHz
            </font>OSCCON.6 = 1        <font color="#008000">; Set the internal oscillator to 8MHz
            </font>OSCCON.5 = 1        <font color="#008000">; Set the internal oscillator to 8MHz
            </font>OSCCON.4 = 1        <font color="#008000">; Set the internal oscillator to 8MHz
    
            </font>PORTA = $00         <font color="#008000">' Set all port a pins to low
            </font>PORTB = $00         <font color="#008000">' Set all port b pins to low
            </font>PORTC = $00         <font color="#008000">' Set all port c pins to low
            </font>PORTD = $00         <font color="#008000">' Set all port d pins to low
            </font>PORTE = $00         <font color="#008000">' Set all port e pins to low
    
            </font>TRISA = %00000000   <font color="#008000">' Make all port a pins outputs
            </font>TRISB = %00001111   <font color="#008000">' Make port b pins 0-3 inputs and the rest as outputs
            </font>TRISC = %00000000   <font color="#008000">' Make all port c pins outputs
            </font>TRISD = %00000000   <font color="#008000">' Make all port d pins outputs
            </font>TRISE = %00000000   <font color="#008000">' Make all port e pins outputs
            
            </font>ADCON0.0 = 0        <font color="#008000">; Make all analog pins digital I/Os
            </font>CM1CON0.7 = 0       <font color="#008000">; Disable comparator C1
            </font>CM2CON0.7 = 0       <font color="#008000">; Disable comparator C2
            </font>WDTCON.0 = 0        <font color="#008000">; Disable the watchdog timer
            </font>ANSEL = %00000000   <font color="#008000">; Set all analog pins on port a to digital I/O
            </font>ANSELH = %00000000  <font color="#008000">; Set all analog pins on port b to digital I/O
            
            </font><font color="#000080">INCLUDE </font>&quot;modedefs.bas&quot;
    
    <font color="#008000">'Variables*****************************************************************************************
            </font>b0 <font color="#000080">VAR BYTE         </font><font color="#008000">' Required byte variable for toggle button
    
    
    '**************************************************************************************************
    </font>INITIALIZE:                 <font color="#008000">' Initialize Routine
            </font>INTCON.0 = 0        <font color="#008000">' Clear the interrupt-on-change flag
            </font><font color="#000080">ON INTERRUPT GOTO </font>Halt <font color="#008000">' Once an active interrupt port is enabled, go to the Halt routine
            </font>INTCON = %10001000  <font color="#008000">' Enable global interrupts, Enable interrupt-on-change on Port b
            </font>IOCB = %00000011    <font color="#008000">' Enable interrupt-on-change on RB0-RB3
            </font>PORTE.1 = 0         <font color="#008000">' Make sure LED on PORTE.1 is off
            </font>PORTE.2 = 0         <font color="#008000">' Make sure LED on PORTE.2 is off
    
    
    '*************************************************************************************************** *
    </font>MAIN:
            <font color="#000080">HIGH </font>PORTE.0
            <font color="#000080">PAUSE </font>500
            <font color="#000080">LOW </font>PORTE.0
            <font color="#000080">PAUSE </font>500
            <font color="#000080">GOTO </font>MAIN
    
    
    <font color="#008000">'*************************************************
            </font><font color="#000080">DISABLE         </font><font color="#008000">' do NOT place interrupt checking code below
            
    </font>Halt:   <font color="#008000">' Halt Routine
            </font><font color="#000080">IF </font>PORTB.0 = 0 <font color="#000080">THEN
                    WHILE </font>PORTB.0=0 <font color="#008000">' wait for button release &amp; end mismatch condition on portb
                    </font><font color="#000080">WEND
                    PAUSE </font>20        <font color="#008000">' Debounce delay
                    </font><font color="#000080">HIGH </font>PORTE.1
                    <font color="#000080">LOW </font>PORTE.2
                    <font color="#000080">ENDIF
                    
            IF </font>PORTB.1 = 0 <font color="#000080">THEN
                    WHILE </font>PORTB.1=0 <font color="#008000">' wait for button release &amp; end mismatch condition on portb
                    </font><font color="#000080">WEND            
                    PAUSE </font>20        <font color="#008000">' Debounce delay
                    </font><font color="#000080">LOW </font>PORTE.1
                    <font color="#000080">HIGH </font>PORTE.2
                    <font color="#000080">ENDIF
           
            </font>INTCON.0 = 0            <font color="#008000">' Clear the interrupt-on-change flag
            </font><font color="#000080">RESUME                  </font><font color="#008000">' Go to Main routine
            </font><font color="#000080">ENABLE                  </font><font color="#008000">' Enable all active interrupts
    </font>
    Read your datasheet about Interrupt on change. I haven't done myself, but I bet you should read the whole, save it to a variable, then play with this variable.

    Probably not a bad idea, to do the same thing before ON INTERRUPT.. read the whole port, save it to a dummy variable, etc.

    HTH
    Last edited by mister_e; - 13th November 2008 at 19:54.
    Steve

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

Similar Threads

  1. A Simple IOC Routine (Interrupt On Change)
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th March 2010, 19:53
  2. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  3. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  4. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 0

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

Posting Permissions

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