PDA

View Full Version : 12F675 - How to configure the INTCON command to activate the various interrupts?



zorgloub
- 21st April 2023, 11:47
Good morning
As I am new to understanding and using Interrupts, could you explain to me the configuration of the INTCON command for a small PIC12F675?
The PBP manual gives as an example:
INTCON = %10010000 ' Enable RB0 interrupt
But I don't know for which PIC this command is valid (because I imagine it varies depending on the PIC used?).

Unless I am mistaken, the 6 ports of the PIC12F675 would make it possible to cause interrupts.
What would then be the commands to activate the various interrupts on GP0,1,2,3,4 and5 ?

Thanks all.

richard
- 21st April 2023, 13:02
But I don't know for which PIC this command is valid (because I imagine it varies depending on the PIC used?)
intcon is not a command, its a special function register
while the intcon reg is fairly similar in operation across the pic spectrum you need to always consult the data sheet for your chip
to ensure correct usage for the type/s of interrupt in question

the data sheet also has a section on interrupt types and how to configure them
the data sheet also will spell out how to save and restore mcu context to incorporate in your isr [interrupt service routine]code
the data sheet also has a section on ioc [int on change] for the gpio on that chip



What would then be the commands to activate the various interrupts on GP0,1,2,3,4 and5
there is no pbp command for that you need to set the appropriate registers yourself , properly of course

trisio,ioc, intcon

zorgloub
- 21st April 2023, 17:27
Indeed, INTCON is not strictly speaking a "command" but a configuration of the bits of the INTCON register obtained by a "line of code" of the style INTCON = 10010000.

I obviously consulted the datasheet of the PIC12F675 on the page relating to the INTCON register. (see attached jpg)
However, I do not see how to configure the six available ports.
At first, I would already be well advanced for my project if I could define an interrupt on the GP0 port.

For the others, we will see later with the assistance of the available specialists of this forum whom I already thank in advance.

9356
9357

richard
- 21st April 2023, 23:42
REGISTER 3-4: IOC: INTERRUPT-ON-CHANGE GPIO REGISTER (ADDRESS: 96h)

zorgloub
- 22nd April 2023, 08:55
Hi,
In fact, I'm more of a PICAXE user and I transform my "simple" codes with PBP to program small PICs.
I was trying to use interrupts...
The subtleties of the PICs are therefore quite nebulous for me and my English is not flexible and subtle enough to understand the mysteries of the data sheets.
In fact what I wanted to do initially seemed easy to me... but it doesn't seem to be the case :(

I just want to vary a variable named MODE from 0 to 3, 0 to 3, ..., when port GP0 (which has a pull-up resistor to Vcc) goes to zero state.

If someone could help me out with just this little routine, that would be great.
Thanks in advance.

richard
- 22nd April 2023, 11:14
'************************************************* ***************
'* Name : ioc-demo-12f675.BAS *
'* Author : richard *
'* Notice : Copyright (c) 2023 caveat emptor *
'* : All Rights Reserved *
'* Date : 22/04/2023 *
'* Version : 1.0 *
'* Notes : 12f675 ioc gpio.0 *
'* : *
'************************************************* ***************
#CONFIG
cfg = _INTRC_OSC_NOCLKOUT
cfg&= _WDT_ON
cfg&= _PWRTE_OFF
cfg&= _MCLRE_ON
cfg&= _BODEN_ON
cfg&= _CP_OFF
cfg&= _CPD_OFF
__CONFIG cfg
#ENDCONFIG
DEFINE INTHAND poll
wsave VAR BYTE $20 SYSTEM
ssave VAR BYTE BANK0 SYSTEM


mode var byte
DUMMY VAR BYTE


INPT VAR GPIO.0
LED VAR GPIO.1


cmcon = 7
ANSEL = 0
TRISIO.0 = 1
TRISIO.1 = 0
IOC.0 = 1




MODE = 3
DUMMY = GPIO
INTCON = 001000
LED = 1


MAIN:
IF ! MODE THEN
LED = 0
pause 1000
LED = 1
mode = 3
DUMMY = GPIO
INTCON = 001000
endif
PAUSE 10
GOTO MAIN




asm
poll
MOVWF wsave
SWAPF STATUS,W
BCF STATUS,RP0
MOVWF ssave

BANKSEL _mode
clrf _mode

SWAPF ssave,W
MOVWF STATUS
SWAPF wsave,F
SWAPF wsave,W
ENDASM





9358

richard
- 23rd April 2023, 03:16
wasn't really happy with previous attempt

these are better one with dt ints one without

zorgloub
- 24th April 2023, 10:29
Hi, Richard,
I will carefully read your .txt files.
But I really only master Basic... not really ASM

richard
- 24th April 2023, 22:16
I will carefully read your .txt files.

not sure if I have to point out the obvious but
what sort of file would "ZORB.pbp.txt" if you took the ".txt" off the end ?
[the pbp forum will not allow a pbp file to be uploaded , you need to mask its type with a .txt extension]



But I really only master Basic... not really ASM
such a limited outlook

good luck employing interrupts in any other way with such limited chips as 12f675

amgen
- 25th April 2023, 19:24
" not sure if I have to point out the obvious" but you often have some degrading, demeaning cutting comment to people seeking help. Basically a reflection of yourself......

please delete this

richard
- 26th April 2023, 00:01
I will carefully read your .txt files.


i read that as either a lack of understanding on how files are uploaded onto the forum or
a intimation that i have uploaded something weird, unusual or incorrect. i don't know which
but either way since it was specifically pointed out an explanation was warranted



not sure if I have to point out the obvious but...
makes it clearer why the txt extension is there and how to deal with it, just in case an explanation was
necessary





but you often have some degrading, demeaning cutting comment to people seeking help. Basically a reflection of yourself......


really

mpgmike
- 26th April 2023, 00:46
To activate a single I/O pin as IOC (Interrupt on Change) you use the "IOC" Register; Register 3.4 in the Data Sheet:


IOC.0 = 1 'Enables IOC on GPIO 0

If you want to enable IOC interrupts on multiple GPIO pins you can use the IOC Register in binary mode. Assume you want an IOC Interrupt on GPIO pins 0 & 1:


IOC = 000011 'Enables IOC on GPIO 0 & 1

Then you must enable IOC interrupts using the INTCON Register:


INTCON.3 = 1 'Enables IOC Interrupts

Next, you need to create an Interrupt Handler (See PBP Manual) so when you get the Interrupt, you can do something with it. In your Interrupt Handler, when you get an IOC interrupt you have to clear the Interrupt Flag:


INTCON.0 = 0 'Clears IOC Interrupt Flag

If you need more than one GPIO IOC Interrupt (2 or more Port Pins), you will have to Poll which GPIO triggered the IOC Interrupt:


IF GPIO.0 = 1 THEN
<Interrupt Handler Code for GPIO.0>
ELSE IF GPIO.1 = 1 THEN
<Interrupt Handler Code for GPIO.1>
ENDIF

The above code assumes that a low-to-high transition triggers your IOC interrupt. You may need to change that depending on your goals.

<edit> I tried to write "IOC = 000011 'Enables IOC on GPIO 0 & 1" but the forum keeps changing it to "IOC = 000011 'Enables IOC on GPIO 0 & 1"

richard
- 26th April 2023, 01:44
Next, you need to create an Interrupt Handler (See PBP Manual) so when you get the Interrupt, you can do something with it. In your Interrupt Handler, when you get an IOC interrupt you have to clear the Interrupt Flag:

not forgetting :-


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.

zorgloub
- 11th May 2023, 09:11
Thank you all.
I will try to assimilate all these notions.
Have a good day.