16F767 Exteranl Interrupt with DT_INTS


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2006
    Location
    Australia, Gold Coast
    Posts
    31

    Default 16F767 Exteranl Interrupt with DT_INTS

    Hello Hello,

    I used Darrel's LCD anypin the other day on a 16F628, worked great, but I am not having any luck today with the interrupts on 16F767. I am probably doing something wrong.
    I have checked settings, wiring, re-read darrel's website info, but I am still missing something.
    Attached is a small test code. Using external interrupt, switch pins are connected to RB0,
    so when interrupt triggered, it should read pins.
    I assembled it on EasyPIC4 switches are indeed pulled to ground, I can verify with the LED and also doing a simple Port status display on the LCD, so it definitely the code or the configuration.
    Any help, comments, suggestions much appreciated.


    Code:
    '*** SWITCH / INTERRUPT TEST ***
    
    'Setup for PIC16F767 @ 4Mhz
    
    ;Config Register 1
    @ __CONFIG    _CONFIG1, _CP_OFF & _CCP2_RC1 & _DEBUG_OFF & _HS_OSC &_VBOR_2_7 & _MCLR_ON & _PWRTE_OFF & _WDT_ON 
    
    
    ;Config Register 2
    @ __CONFIG    _CONFIG2, _BORSEN_0 & _IESO_OFF & _FCMEN_OFF
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    DEFINE OSC 4      
    
    OPTION_REG.7 = 1  'Disable PORTB pull ups
    ADCON0.0 = 0
    ADCON1 = 15       'Disable ALL Analog inputs. ALL PORTS digital
    
    TRISB = %00011111 'PortB 7,6,5 Outputs,
    
    'Set LCD Data Port
    DEFINE LCD_DREG PORTC
    'Set starting Data Bit (0 or 4) if a 4-bit bus
    DEFINE LCD_DBIT	4
    'Set LCD Register Select Port
    DEFINE LCD_RSREG PORTC
    'Set LCD Register Select Bit
    DEFINE LCD_RSBIT 0
    'Set LCD Enable Port
    DEFINE LCD_EREG PORTC
    'Set LCD Enable Bit
    DEFINE LCD_EBIT 3
    'Set LCD Bus Size (4 or 8 bits)
    DEFINE LCD_BITS	4
    'Set number of lines on LCD
    DEFINE LCD_LINES 2
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _Detect,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE   INT_INT     ; enable external (INT) interrupts
    
    
    Switch_1 VAR PORTB.1
    Switch_2 VAR PORTB.2
    Switch_3 VAR PORTB.3
    Switch_4 VAR PORTB.4
    
    
    Main:
    Pause 50
    GOTO MAIN
    
    
    
    '---[INT - interrupt handler]---------------------------------------------------
    Detect:
    If switch_1 = 1 THEN LCDOUT $FE,$80,"Switch 1" 
    If switch_2 = 0 THEN LCDOUT $FE,$80,"Switch 2" 
    If switch_3 = 0 THEN LCDOUT $FE,$80,"Switch 3" 
    If switch_4 = 0 THEN LCDOUT $FE,$80,"Switch 4"
    @ INT_RETURN
    "Never under estimate the powers of an idiot"

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


    Did you find this post helpful? Yes | No

    Default

    And the problem is....?

    The interrupt should only happen when INT0 is triggered.

    For multiple switch, you may need to use Int On change (RBC_INT) ... or poll them in a Timer Interrupt.
    Last edited by mister_e; - 29th May 2008 at 21:55.
    Steve

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

  3. #3
    Join Date
    Feb 2006
    Location
    Australia, Gold Coast
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    Hello Mister_E

    Quote Originally Posted by mister_e View Post
    And the problem is....?
    The problem is that the existing code does not display anything on the LCD...

    It does not seem want to 'interrupt'.
    "Never under estimate the powers of an idiot"

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


    Did you find this post helpful? Yes | No

    Default

    i've edited my previous post. Also, let's say you want to use INT0 (RB0), you want to disable the multiplexed ADC on it (see ADCON1 register pdf page 155).

    INT_INT will work only with RB0, while RBC_INT will work with PORTB<7:4> pins (see INTCON page 25, and section 5.2 page 58).
    Steve

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

  5. #5
    Join Date
    Feb 2006
    Location
    Australia, Gold Coast
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    Wow that was quick reply Mister_E!

    Quote Originally Posted by mister_e View Post
    i've edited my previous post. Also, let's say you want to use INT0 (RB0), you want to disable the multiplexed ADC on it (see ADCON1 register pdf page 155).

    INT_INT will work only with RB0, while RBC_INT will work with PORTB<7:4> pins (see INTCON page 25, and section 5.2 page 58).
    Yes, checked the PDF pg 155, but isn't ADCON1 = 15 doing that?
    That should make all ports digital?

    I agree the port change 7:4 would be better, but I plan to use RB5 for CCP3...so that is not really possible. I think I should use the RB0 external interrupt.
    "Never under estimate the powers of an idiot"

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


    Did you find this post helpful? Yes | No

    Default

    Nah... you can use whatever spare I/O you have, and poll them with a Timer Interrupt, let's say 10 times/seconds. Your main loop just check if you have a new keypress.

    1 Timer interrupt will do everything,
    1. scan the Key
    2. say if there's a new key available,
    3. and... why not using it also for the debouncing as well?

    Think about it... 10 times a second is usually just fine.

    <hr>
    Yes ADCON1=15 will do.
    Last edited by mister_e; - 29th May 2008 at 22:19.
    Steve

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

  7. #7
    Join Date
    Feb 2006
    Location
    Australia, Gold Coast
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Nah... you can use whatever spare I/O you have, and poll them with a Timer Interrupt, let's say 10 times/seconds. Your main loop just check if you have a new keypress.

    1 Timer interrupt will do everything,
    1. scan the Key
    2. say if there's a new key available,
    3. and... why not using it also for the debouncing as well?

    Think about it... 10 times a second is usually just fine.

    <hr>
    Yes ADCON1=15 will do.
    Many thanks Mister_E...after much hair tearing I successfully managed to use the external RB0 interrupt with the above code. My stupid mistake, bad home made connector wiring on the EasyPIC board.
    I ended up using your suggestion with the 10Hz timer -your multi-calculator works great! - as you said at least i can also debounce easily.

    Many thanks for your time.
    "Never under estimate the powers of an idiot"

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


    Did you find this post helpful? Yes | No

    Default

    The advantage of the timer interrupt is that you have a Global key scan... all the time, you just need to poll few variables it here and there. Another great thing.. you can use the pin you want. For user Key, it's just perfect and really fast enough.

    Timer interrupt are sooo handy.
    Steve

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

Similar Threads

  1. 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
  2. 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
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  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