PDA

View Full Version : Interrupts and Disable 16f877



Rob Martin
- 17th April 2005, 20:27
I'm trying to learn how to use interrupts and in all the examples I find the word DISABLE appears.
But to me it doesn't appear to do anything as it is never passed by the program.
Am I being thick?

My next question is the 16f877 shows it has 14 Interrupts but the paper work only shows interrupts on some of the RB pins?

And lastly I want to use four different RBx pins to trigger four different bits of code. But looking at example and reading the paperwork I can not see how I differentiate between which pins causes the interrupt as once enabled any of the RB pins cause an interrupt? or do I have to do this in code?

I'm sure this is obvious to everyone except me but I've spent all weekend reading and can not see the wood for the trees.

Rob

***EXAMPLE*****
' On Interrupt - Interrupts in BASIC
' Turn LED on. Interrupt on PORTB.0 (INTE) turns LED off.
' Program waits .5 seconds and turns LED back on.

led var PORTB.7


OPTION_REG = $7f ' Enable PORTB pullups

On Interrupt Goto myint ' Define interrupt handler
INTCON = $90 ' Enable INTE interrupt

loop: High led ' Turn LED on
Goto loop ' Do it forever


' Interrupt handler
Disable ' No interrupts past this point
myint: Low led ' If we get here, turn LED off
Pause 500 ' Wait .5 seconds
INTCON.1 = 0 ' Clear interrupt flag
Resume ' Return to main program
Enable

Luciano
- 17th April 2005, 21:39
Hi!



I've spent all weekend reading....
(>400 pages)
http://www.mind-tek.com/assets/images/speed.JPG


Q1. DISABLE

See PicBasic Pro manual.
DISABLE and ENABLE are pseudo-ops in that they give the compiler
directions, rather than actually generate code.


Q2. 14/15 interrupts.

Open the data sheet of the 16f877 and search the word 'interrupt'.

Read section 8 of the Mid-Range MCU Family Reference Manual.
http://ww1.microchip.com/downloads/en/DeviceDoc/33023a.pdf


Q3. PORTB Interrupt.

AN566 - Using the PORTB Interrupt on Change as an External Interrupt.
http://ww1.microchip.com/downloads/en/AppNotes/00566b.pdf


Best regards,

Luciano

Rob Martin
- 17th April 2005, 23:28
Luciano


The data sheet you pointed to is different to mine so perhaps that's the first lesson I have learnt. The one I downloaded covers several 16f8xx and only had a couple of lines about interrupts but was over 200 pages long.

Secondly I have misplaced my PBP manual and I'm using the online HTML version which is not ideal.

Thank's for taking the time to reply it is very much appreciated.

Rob

Luciano
- 18th April 2005, 09:58
Rob

The datasheets are only one part of the documentation.

See http://www.microchip.com for:

- Reference Manuals
- Datasheets
- Application Notes
- (and more)


* * * * *

PicBasic Pro manual in PDF format.
http://www.melabs.com/downloads/pbpm304.pdf

* * * * *

PIC16F873/4/6/7 Datasheet

http://ww1.microchip.com/downloads/en/DeviceDoc/30292c.pdf

* * * * *

PIC16F87XA Datasheet (Parts with an "A" suffix).

PIC16F87XA Datasheet
http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf

PIC16F87XA Rev. B2 Silicon/Data Sheet Errata
http://ww1.microchip.com/downloads/en/DeviceDoc/80133f.pdf

* * * * *
Luciano

Rob Martin
- 18th April 2005, 16:18
Luciano

I'm still not having any luck making my interrupts work, they appear to be permanently on but looking over my circuit I may have found my problem and would appreciate another opinion.

I use RB0,1,2 as outputs to drive another chip serially so I am assuming I can use these as outputs and still use RB4:7 as inputs?

My code goes like this (I have just cut n pasted the interrupt bits)
When I scope RB4 it always appears to be at a low level where as RB5:7 are just under 5 Volts? When you use the internal pull-ups I assume volts appear on the appropriate pin? Or am I dragging down RB4 where it's connected to another IC, and this is causing a permanent interrupt?

I have one of the Lab -x3 * x2 boards and was trying to get a working interrupt demo on a 16f628 but I still had no joy.
Sorry to be a pain but all pointers gratefully accepted.

Rob



OPTION_REG = %1111000 ' Enable PORTB pullups
INTCON = %10011000 ' Enable INTE interrupt

On Interrupt Goto NoVideo ' Define interrupt handler
disable
:NoVideo



IF PORTB.4 = 1 then
low PORTC.0 'Green LED (bipolar LED)
high PORTC.1 'Green LED
ENDIF
IF PORTB.4 = 0 then
low PORTC.1 'Red LED
high PORTC.0 'Red LED
NoSync = PORTB.4
ENDIF


'**Interrupts stuff
INTCON.1 = 0 ' Clear interrupt flag
Resume ' Return to main program
Enable

Luciano
- 18th April 2005, 21:08
Hi!

Each of the PORTB pins has a weak internal pull-up
(≈200 µA typical). A single control bit can turn on all the
pull-ups. This is done by clearing the RBPU
(OPTION<7>) bit. The weak pull-up is automatically
turned off when the port pin is configured as an output.
The pull-ups are disabled on Power-on Reset.

OPTION_REG.7 = 0 ' Enable all PORTB pullups
OPTION_REG.7 = 1 ' Disable all PORTB pullups

* * *

To set a pin or port to an output (or input), set its TRIS register.
Setting a TRIS bit to 0 makes its corresponding port pin an output.
Setting a TRIS bit to 1 makes its corresponding port pin an input.

Examples on PORTB:

TRISB = %11111111 'sets all the PORTB pins to inputs.
TRISB = %00000000 'sets all the PORTB pins to outputs.
TRISB = %11110000 'b7,b6,b5,b4=inputs / b3,b2,b1,b0 =outputs
TRISB = %11100000 'b7,b6,b5=inputs / b4,b3,b2,b1,b0 =outputs


Try to find out what happen if you set all the PINs of PORTB
as inputs with TRISB = %11111111 then enable all PORTB pullups
with OPTION_REG.7 = 0 and then you set TRISB = %11100000.
('b7,b6,b5=inputs / b4,b3,b2,b1,b0 =outputs).
Pullups still there on b7,b6,b5? (Source +5 Volts ≈200 µA).

* * *

External interrupt on RB0/INT pin

External interrupt on RB0/INT pin is edge triggered:
either rising if INTEDG bit (OPTION<6>) is set, or
falling, if INTEDG bit is clear. When a valid edge
appears on the RB0/INT pin, the INTF bit
(INTCON<1>) is set. This interrupt can be disabled by
clearing the INTE control bit (INTCON<4>). The INTF
bit must be cleared in software in the interrupt service
routine before re-enabling this interrupt. The RB0/INT
interrupt can wake-up the processor from SLEEP, if the
INTE bit was set prior to going into SLEEP. The status
of the GIE bit decides whether or not the processor
branches to the interrupt vector following wake-up.

OPTION_REG.6 = 0 'Interrupt on falling edge of RB0/INT pin
OPTION_REG.6 = 1 'Interrupt on rising edge of RB0/INT pin
INTCON = %10010000 'Enable INTE
INTCON.1 = 0 'Clear RB0/INT External Interrupt Flag bit

* * *

RB<7:4>, have an interrupt-onchange feature.

Four of PORTB’s pins, RB<7:4>, have an interrupt-onchange
feature. Only pins configured as inputs can
cause this interrupt to occur (i.e., any RB<7:4> pin configured
as an output is excluded from the interrupt-onchange
comparison). The input pins (of RB7:RB4) are
compared with the old value latched on the last read of
PORTB. The “mismatch” outputs of RB7:RB4 are
OR’ed together to generate the RBIF interrupt (flag
latched in INTCON<0>).


INTCON = %10001000 'Enable RBIE
INTCON.0 = 0 'Clear Port Change Interrupt Flag bit

* * *

From your code:

INTCON = %10011000 ' Enable INTE interrupt
(Comment wrong, you enable INTE and also RBIE).

INTCON.1 = 0 ' Clear interrupt flag
(Clear RB0/INT External Interrupt Flag bit).


Best regards,

Luciano