The INTCON register

This register controls the processing of interrupts. The bits of interest are:

<7> GIE 1 = interrupts enabled, 0 = interrupts disabled. This bit is used to switch all interrupts on or off with a single command.

<6> PEIE 1 = enable peripheral interrupts, 0 = disable these interrupts. <5> TOIE 1 = enable timer TR0 overflow interrupts, 0 = disable.

<4> INT 1 = enable INT interrupt, 0 = disable. The INT interrupt is an external interrupt occurring when RA2 changes. The direction of change that brings about an interrupt depends on INTE, which is bit <6> of the OPTION register: 1 = interrupt on rising edge, 0 = interrupt on falling edge. By default INTE is 1.

<3> RABIE 1 = enable interrupt on change in Port A and Port B. You can select which bits of Port A have the interrupt on change feature by setting one or more bits in the IOCA register.

The lower three bits are flags:

<2> T0IF is set when the timer TM0 overflows.

<1> INTF is set when there is an INT interrupt (see above).

<0> RABIF is set when there is an interrupt on change in Ports A and B.

Like the flags in the PIR registers, the flags remain set until you clear them.

Other PICs

Because PICs share the same intruction set, programs written for one type of PIC can often be run on another type. The program may need to be modified for various reasons but this usually presents few problems.

The table below describes three popular mid-range PICs that can run at least some of our robotic programs without too many amendments. All the types are supported by MPASM, MPLAB IDE, PICkit 2 and the PICBASIC compiler.

Device number

16F84A

16F628A

16F88

Pins

Ports (bits)

General purpose RAM (bytes)

Program ROM (words)

EEPROM (bytes)

On-chip peripherals

1 timer

3 timers 2 comparators Capture/compare Internal oscillator

2 timers AD converter 2 comparators Capture/compare Internal oscillator USART

Popular PICs compared.

The major change is in the controller boards. All the PICs in the table have 18 pins and the layout of power terminals is different, as can be seen in the pinout diagrams below. Taking the PICs one at a time, the other important differences are:

16F84A: Has no internal oscillator so an external one is required. The diagram shows an RC oscillator. The programs in this book assume that the 16F690 is running on its internal clock rate of 4 Mz. For programs to run at the same speed on the 16F84A the external oscillator must have a 4 MHz crystal. This is the maximum rate for the 16F84A.

16F628A: This has an internal oscillator running at 4 MHz by default. Using this frees two more pins for input/output, bringing the total to 16. This PIC has more peripheral devices than the previous one, so has become very popular. The diagram below shows its pinout.

Vdd

MOP

OSC1

0SC2

RAO

RAI

RA2

IC1

RA3

PIC16F84A

RA4

RBO

RBI

RB2

RB3

RB4

RB5

RB6

RB7

(Left) The 16F84A needs an external oscillator, provided here by a resistor/capacitor network.

(Above) A crystal oscillator gives more precise timing.

(Right) The 16F628A and the 16F88 have the same pinout.

16F88: This controller scores over the others (but not over the 16F690) by having a larger program memory. It also has an analogue-to-digital converter.

The increase in the number and capabilities of the peripherals inevitably leads to more multiplexing of the input and output channels. Setting up the peripherals becomes more complex because there are more options to choose from. Although straightforward operations such as one-bit input and output remain unaffected, control of the peripherals involves more registers.

There are also differences in the properties of the I/O channels — whether they are digital or analogue, whether they have weak pull-ups, whether they have interrupt-on-change. For further details download the data sheet from Microchip.

0 0

Post a comment

  • Receive news updates via email from this site