pumper
Junior Member
Offline
Posts: 35
Thank You
-Given: 13
-Receive: 18
|
|
« on: June 13, 2012, 01:33:48 13: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 ? /* * 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, 08:12:05 08: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
Posts: 4671
Thank You
-Given: 836
-Receive: 4331
There is no evidence that I muted SoNsIvRi
|
|
« Reply #1 on: June 13, 2012, 02:14:15 14: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: I stoped Muteing bad members OK I now put thier account in sleep mode
|
|
|
zuisti
Senior Member
Offline
Posts: 409
Thank You
-Given: 242
-Receive: 780
|
|
« Reply #2 on: June 13, 2012, 06:36:21 18: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
Offline
Posts: 35
Thank You
-Given: 13
-Receive: 18
|
|
« Reply #3 on: June 14, 2012, 08:10:15 08: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, 08:33:26 08: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
Posts: 409
Thank You
-Given: 242
-Receive: 780
|
|
« Reply #4 on: June 14, 2012, 10:59:40 10: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
Offline
Posts: 89
Thank You
-Given: 101
-Receive: 26
|
|
« Reply #5 on: June 14, 2012, 02:07:31 14: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, 02:14:35 14:14 by gan_canny »
|
Logged
|
|
|
|
pumper
Junior Member
Offline
Posts: 35
Thank You
-Given: 13
-Receive: 18
|
|
« Reply #6 on: June 14, 2012, 02:53:01 14: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
Posts: 409
Thank You
-Given: 242
-Receive: 780
|
|
« Reply #7 on: June 14, 2012, 04:18:21 16: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
Posts: 582
Thank You
-Given: 496
-Receive: 133
Very Wise (and grouchy) Old Man
|
|
« Reply #8 on: June 15, 2012, 12:13:15 00: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
Offline
Posts: 35
Thank You
-Given: 13
-Receive: 18
|
|
« Reply #9 on: June 15, 2012, 06:41:09 06:41 » |
|
Yes, I see, but it's still missing: CMCON = 7;
thanks zeusi the trick was CMCON = 7;
|
|
« Last Edit: June 15, 2012, 06:39:27 18: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
Offline
Posts: 35
Thank You
-Given: 13
-Receive: 18
|
|
« Reply #10 on: June 16, 2012, 02:34:12 14: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
|
|
|
|