![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi all I知 doing a small led project. It has only three patterns. The patterns are changing through RB0 external switch. Inside the Delay loop I知 checking the INTF flag bit. The patterns are not changing very well. Mostly it痴 skipping the patterns & changing in a messy way. Help me to solve this problem. Thanks Code: processor PIC16F84A include <P16F84A.inc> __config 3ffbh errorlevel -302 cblock 20h d1,d2,Select endc org 0000h Main bsf STATUS,RP0 movlw b'00000001' movwf TRISB bsf INTCON,GIE ;enable global int enable bsf INTCON,INTE ;enable ext interrupt bcf STATUS,RP0 clrf PORTB clrf Select movlw 01h ;load 1 to Select reg movwf Select goto PAT1 ************************************ Delay & detect which PATTERN to loop ************************************ DEL0.1 btfsc INTCON,INTF ;has external Int occur? goto Choose ;YES,then goto choose pattern movlw 0x1F ;NO,then carry on the delay movwf d1 movlw 0x4F movwf d2 DEL0.1A decfsz d1, f goto $+2 decfsz d2, f goto DEL0.1A goto $+1 return Choose bcf INTCON,INTF ;turn off ext interrupt incf Select,F ;increment Select value by one movf Select,W bcf STATUS,Z xorlw .2 ;check the Select reg value 2 or not? btfsc STATUS,Z goto PAT2 xorlw .3 ;check the Select reg value 3 or not? btfsc STATUS,Z goto PAT3 xorlw .4 ;check the Select reg value is 4? btfsc STATUS,Z goto $+1 clrf Select goto PAT1 ************ LED patterns ************ PAT1 movlw 01H ;pattern 1 movwf PORTB call DEL0.1 movlw 02H movwf PORTB call DEL0.1 movlw 04H movwf PORTB call DEL0.1 movlw 0AH movwf PORTB call DEL0.1 movlw 14H movwf PORTB call DEL0.1 movlw 2AH movwf PORTB call DEL0.1 movlw 54H movwf PORTB call DEL0.1 movlw 28H movwf 06H call DEL0.1 movlw 50H movwf PORTB call DEL0.1 movlw 20H movwf PORTB call DEL0.1 movlw 40H movwf PORTB call DEL0.1 movlw 00H movwf PORTB call DEL0.1 goto PAT1 PAT2 movlw 02H ;pattern 2 movwf PORTB PAT2A call DEL0.1 bcf STATUS,C rlf PORTB,F btfss PORTB,6 goto $-4 PAT2B call DEL0.1 rrf PORTB,F btfss PORTB,1 goto PAT2B goto PAT2A PAT3 movlw 00H ;pattern 3 movwf PORTB call DEL0.1 movlw 02H movwf PORTB call DEL0.1 movlw 06H movwf PORTB call DEL0.1 movlw 0EH movwf PORTB call DEL0.1 movlw 1EH movwf PORTB call DEL0.1 movlw 3EH movwf PORTB call DEL0.1 movlw 7EH movwf PORTB call DEL0.1 goto PAT3 end | |
| |
| | #2 |
|
Hi, I haven't used external interrupt, just timer interrupt ![]() Just quick read the application note, there is no 'retfie (return from interrupt)' in your code right? It should be placed at the last line of the interrupt routine.
__________________ bananasiong | |
| |
| | #3 |
|
you need something like: org 04h goto intserv .... .... .... intserv : .... .... ... retfie | |
| |
| | #4 |
|
Ok Thank you guys I tried your way but still the problem is there.I put a new thread which my new routine is there.
| |
| |
| | #5 |
|
Assuming you actually fixed your come (what you posted is waaaay off the mark) then I'd bet you are generating lots of interrupts every time you press the switch. Is the switch you hooked to rb0 debounced? I doubt it. It's generally a bad idea to hook an undebounced switch to an interrupt pin. You need to read up on interrupts. it's not hard but you clearly don't understand them. debouncing - when you close a switch, the contacts don't make an instaneous connection. since it's a mostly inelastic material, they tend to bounce around a bit. In the process they make and break the connection several times. Connected to an interrupt pin, you will see a number of interrupts in a short period of time. You need to figure out a way to supress the extra bounces. I would use a timer interrupt to read the state of the switch every few milliseconds and when the pin has had the same value for 20 mS or so, then I'd use the value of the pin. look here to learn more about debouncing http://www.ganssle.com/debouncing.pdf | |
| |
| | #6 |
|
Hi Philba you have read my mind. I was thinking one time to add the debouncing coding. For a normal I/O pin I知 using debouncing codings. But for RB0 like external interrupt pin I thought no need to debounce. But now it痴 the other way I need to debounce RB0 as well. Your PDF is excellent thank you very much for that. I was searching such a thing from a long time but today I got. Thank you very much for your explanation. | |
| |
| | #7 |
|
Adding this line after org 0004h will disable the external interrupt enable bit.but make sure to enable back it again before returning from ISR. Code: org 0004h bcf INTCON,INTE Last edited by Gayan Soyza; 30th August 2007 at 09:40 AM. | |
| |
|
| Tags |
| external, interrupt, problem, rb0 |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| external interrupt | neelam29 | Micro Controllers | 4 | 11th March 2006 02:50 PM |
| external interrupt frequency counter pic | neelam29 | Micro Controllers | 7 | 6th March 2006 02:20 PM |
| external interrupt address | neelam29 | Micro Controllers | 4 | 25th February 2006 03:00 AM |
| Pic16F7XX transmission interrupt problem | Tzvik | Micro Controllers | 1 | 27th January 2006 02:01 AM |
| Interrupt on GP Change problem | Dan East | Micro Controllers | 2 | 22nd May 2004 06:12 PM |