Thread: Problem!!!!! pic16f690 Interrupt PORTB

  1. #1
    Registered User
    Join Date
    Nov 2014
    Posts
    1

    Problem!!!!! pic16f690 Interrupt PORTB

    hello,
    I have a problem with the interruption of PORTB .
    interrupt does not work.
    I put the 4.7K resistor to VSS. could you help me understand my mistakes.

    main.c
    Code:
    /* 
     * File:   main.c
     * Author: christop.soguel
     *
     * Created on 6. novembre 2014, 10:49
     */
    
     /** C O N F I G U R A T I O N B I T S ******************************/
    #pragma config WDTE = ON, PWRTE = OFF, CP = OFF, BOREN = ON, FCMEN = ON, MCLRE = ON, CPD = OFF, IESO = ON, FOSC = INTRCCLK
    
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <pic16f690.h>
    #include <xc.h>
    #define     CAPTEUR1    PORTAbits.RA3
    void Debounce (void);
    unsigned int CompteurA = 0;                // Counter variable for debounce routine.
    unsigned int CompteurB = 0;                // Counter variable for debounce routine.
    unsigned int CompteurI= 0;                // Counter variable for debounce routine.
    
    void interrupt ISR (void)
    {
       
        if (INTCONbits.RABIF)
        {
            
            Debounce();
            
             INTCONbits.RABIF = 0;
             
            return;
        }
    }
    
    void main (void)
    {
        OSCCON= 0b01100101;         //Freq = 4MHZ
        OSCTUNE=0b00000000;
    
    
        
        TRISC = 0b00000000;
        TRISB = 0b01110000;
        TRISA = 0b00000000;
        IOCB =  0b01110000;     // enable the top 3 IOC interrupts on PORTB
        
        PORTC = 0b00000000;
      
        OPTION_REGbits.nRABPU =0;
        OPTION_REGbits.INTEDG = 1;
        INTCONbits.GIE = 1;         // Global Interrupt Enable
        
        INTCONbits.RABIE = 1;      // enable interrupt on change (IOC) for ports A & B
        INTCONbits.RABIF = 0;     
    
        unsigned int uiCpt;
        unsigned char iCompteur;
        unsigned int i;
        unsigned char iSeconde;
        unsigned char TEST1=1;
       
        do
        {
            
            
            PORTC = 0b00000110;
            if (CompteurA >= 10)
            {
                 PORTC = 0b00000111;
    
            }
        }while (TEST1==0);
    
    }
    
        void Debounce (void)
        {
            if (!RB4 )
            {
                CompteurA = CompteurA + 1;
               
            }
         if (!RB5)
            {
                CompteurB = CompteurB + 1;
            
            }
            if(!RB6)
            {
                CompteurI = CompteurI + 1;
            }
          
        }
    
    
    
    
    /* for (iCompteur = 0; iCompteur < 1; iCompteur ++ )
               {
                    for( i=0;i<1000;i++)
                    {
                        // Met le driver moteur en Mode CW
                        PORTC = 0b00000110;
    
    
                    }
    
                }
    
                for (iSeconde = 0; iSeconde < 15; iSeconde ++)
                 {
                      for ( uiCpt = 0; uiCpt < 10000 ;uiCpt ++)
                      {
                           // Met le driver moteur en Mode BRAKE
                           PORTC = 0b00000111;
    
                      }
                 }CAPTEUR1 == 1
               TEST1=0;*/
    Last edited by Salem; 11-13-2014 at 03:46 PM. Reason: Inlined the code

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    In the future, please post your code in [code][/code] tags, and make sure it's properly formatted and indented, so it's easy to read.

    Also, often for embedded uC questions, a schematic can be very helpful.

    You need to be more specific in your problem. What "doesn't work" about the interrupt. Does it not trigger? Does it perform the wrong actions? Does it cause something in your circuit to blow up? The more details the better we can help you.

    What do you mean you "put the 4.7K resistor to VSS"? Did you simply tie the interrupt pin to high? From a quick glance at the datasheet and the comments in your code, the interrupts are "Interrupt-on-change", suggesting you need a high-to-low or low-to-high transition to trigger it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PIC16F690: Using RA2 as Both an Input and an Interrupt
    By C-Noob#1 in forum C Programming
    Replies: 3
    Last Post: 02-17-2013, 09:18 AM
  2. Problem coding Banner sensor interrupt...
    By processing in forum C Programming
    Replies: 1
    Last Post: 02-14-2005, 04:41 PM
  3. ASM interrupt and others
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 06-08-2002, 07:18 PM
  4. interrupt
    By juandy in forum C++ Programming
    Replies: 4
    Last Post: 05-21-2002, 08:24 AM
  5. Interrupt???
    By GiSH in forum C++ Programming
    Replies: 1
    Last Post: 11-15-2001, 12:27 PM