Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 06, 2016, 09:10:47 09:10


Login with username, password and session length


Pages: [1]
Print
Author Topic: pic12f629 interupt on change  (Read 3812 times)
0 Members and 1 Guest are viewing this topic.
pumper
Junior Member
**
 Muted
Offline Offline

Posts: 35

Thank You
-Given: 13
-Receive: 17


« on: June 13, 2012, 02:33:48 14:33 »

hi
i,m try to work with pic12f629 interupt on change with no success
please check the code and tell me whats wrong with it ?
Code:
/*
 * File:   main.c
 * Author: mohsen
 *
 * Created on June 11, 2012, 12:40 PM
 */
#include<xc.h>
__CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & BOREN_ON & CP_OFF & CPD_OFF);
/***/
volatile unsigned char htime=0;
void interrupt isr_rt(void);


int main(void) {
    GPIO=0x00;
    TRISIO=(1<<0)|(1<<2);
    IOCbits.IOC0=1;    //INTERRUPT-ON-CHANGE GPIO GP0
     INTCONbits.PEIE=1;
     OPTION_REGbits.INTEDG=1;
    INTCONbits.INTE=1;
    INTCONbits.GIE=1;
    INTCONbits.GPIE=1;        //INTERRUPT-ON-CHANGE GPIO
    INTCONbits.GPIF=0;
    INTCONbits.INTF=0;
    while(1);
    return 0;
}

void interrupt isr_rt(void){
    if(INTCONbits.INTE&&INTCONbits.INTF){
        INTCONbits.INTF=0;

        GPIObits.GPIO5=(GPIObits.GPIO5?0:1);
    }
    if(INTCONbits.GPIE&&INTCONbits.GPIF){
        htime=GPIO;
        INTCONbits.GPIF=0;
       
        if(htime&0x01){
            GPIObits.GPIO5=(GPIObits.GPIO5?0:1);
        }else{
        GPIObits.GPIO5=(GPIObits.GPIO5?0:1);
        }
    }

}
the other interrupt works fine .
i use proteus for simulating.
« Last Edit: June 14, 2012, 09:12:05 09:12 by pumper » Logged

C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly
pickit2
Moderator
Hero Member
*****
Offline Offline

Posts: 3816

Thank You
-Given: 567
-Receive: 2049


There is no evidence that I muted SoNsIvRi


« Reply #1 on: June 13, 2012, 03:14:15 15:14 »

the 12f629 will onle service one interrupt at a time and will disable other interupts, you need to enabled them again, with the RETFIE instruction..

Logged

Note: If you have no posts other than, I want or reporting a dead link Then you can't complain If I remove your post So Stop Leeching
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #2 on: June 13, 2012, 07:36:21 19:36 »

INTF: GP2/INT External Interrupt Flag bit
GPIF: Port Change Interrupt Flag bit
 and:
You cannot clear GPIF before any read (or write) of the GPIO.
Look at the datasheet chapter 3.3.2:
"A mismatch condition will continue to set flag bit GPIF.
Reading GPIO will end the mismatch condition and allow flag bit GPIF to be cleared."


So first read the GPIO and then clear GPIF.
Logged
pumper
Junior Member
**
 Muted
Offline Offline

Posts: 35

Thank You
-Given: 13
-Receive: 17


« Reply #3 on: June 14, 2012, 09:10:15 09:10 »

thanks mr zuisti
my problem is that the interrupt never fires.
any way i think the problem is in proteus.
i changed the micro to pic12f675 and now  interrupt not happened again
i uploaded entire project  + proteus files. please take look
« Last Edit: June 14, 2012, 09:33:26 09:33 by pumper » Logged

C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #4 on: June 14, 2012, 11:59:40 11:59 »

The most important:

- if you want only digital IOs then you must switch off comparators (CMCON = 7) and - in case of the 12F675 - also the ADC inputs (ANSEL = 0).
(see the datasheet, chapter 3.0).

Sorry but I don't have (and don't like) Hitech-C, I'm using MikroC (and CCS C or C18 if necessary :-), pure assembly or - mainly - Proton Basic.

However (if your IT is fired already):
- your IT routine is using three times the same line:
GPIObits.GPIO5=(GPIObits.GPIO5?0:1);  // toggle GPIO5, it runs always twice !
- the result will be that the pin does not change (toggle 2 times)

And in general, why use two IT (the ext and the on change) at a time when there is just one switch?
First by all means try with only one IT!
zuisti
Logged
gan_canny
Junior Member
**
 Warned
Offline Offline

Posts: 85

Thank You
-Given: 98
-Receive: 25


« Reply #5 on: June 14, 2012, 03:07:31 15:07 »

On a number of boards dealing with PIC devices the person needing help is using Proteus. I'm not knocking Proteus but working with the hardware is reality and Proteus is virtual reality. They are never the same and the insights learned by working with reality are lost to those that only prefer the convenience of the virtual world. The virtual world facilitates a throw it at the wall approach hoping something might just stick. The real world makes you read data sheets before soldering parts and creates a check twice solder once strategy. The concept learned in the real world is that the PIC has interrupts that are double enabled/disabled one specific to a function and the other general, the interrupt is initiated by a flag being set by hardware, interrupts aren't recursive ( an interrupt can't be interrupted}, and the way this flag is cleared matters that's why there is a data sheet.
Not all pins on a PIC are equivalent as to function....ex the usb pins on a usb enabled device can't be used for general output only input.
Proteus is not the way to learn this but I'm sure like gaming it is fun to some.
It will be a nightmare for the forest if carpentry moves to virtual reality and measure twice cut once is cast aside. If it does there will be good money to be made in sawdust and odd length lumber.
« Last Edit: June 14, 2012, 03:14:35 15:14 by gan_canny » Logged
pumper
Junior Member
**
 Muted
Offline Offline

Posts: 35

Thank You
-Given: 13
-Receive: 17


« Reply #6 on: June 14, 2012, 03:53:01 15:53 »

thanks mr zuisti
If you look at porject file you see that i made ANSEL = 0
and the line is just for test and i made a break point at  the enterance of interrupt routine.
but never the interrupt flag GPIF is set to 1.
Logged

C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #7 on: June 14, 2012, 05:18:21 17:18 »

If you look at porject file you see that i made ANSEL = 0

Yes, I see, but it's still missing:
CMCON = 7;
Logged
Parmin
Hero Member
*****
Offline Offline

Posts: 544

Thank You
-Given: 357
-Receive: 126


Very Wise (and grouchy) Old Man


« Reply #8 on: June 15, 2012, 01:13:15 01:13 »

Zuisti is right, you need to initialize CMCON register.

Read the datasheet Page 19
"The ANSEL (9Fh) and CMCON (19h) registers (9Fh) must be initialized to
configure an analog channel as a digital input. Pins configured as analog inputs will read 0.
The ANSEL register is defined for the PIC12F675."

Logged

If I have said something that offends you, please let me know, so I can say it again later.
pumper
Junior Member
**
 Muted
Offline Offline

Posts: 35

Thank You
-Given: 13
-Receive: 17


« Reply #9 on: June 15, 2012, 07:41:09 07:41 »

Yes, I see, but it's still missing:
CMCON = 7;

thanks  zeusi
the trick was CMCON = 7;
« Last Edit: June 15, 2012, 07:39:27 19:39 by pumper » Logged

C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly
pumper
Junior Member
**
 Muted
Offline Offline

Posts: 35

Thank You
-Given: 13
-Receive: 17


« Reply #10 on: June 16, 2012, 03:34:12 15:34 »

this topic solved
please mark it.
Logged

C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC