Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

EE Design > In Technical
| Home | Contact |

Title: The PIC Microcontrollers
Author: Vincent Wong
Date: 29th March 2005


Here I have listed some notes on developing with the PIC microcontrollers. The most common PICs that I am using are the 18-pin PIC16F84, 28-pin PIC16F870 and the 40/PLCC-44 pin PIC16F877 or PIC18F452 series.

A project that requires low pin count MCU are like the 12C508 & 16F627 are developed using the PIC16F84. Please note that the 16F627 are cheaper for industrial product design compared to the 16F84. It has 2 additional timers, 1 comparator input and many other additional features. However, they are not widely available at local electronic shops.

When using PIC16F84 to emulate the 12C508, please note that the address and size of internal RAM (file/registers) are different. The general purpose register (GPR) area for the F84 is from 0x0C to 0x4F. The GPR for 12C508 is from 0x07 to 0x1F. It can be seen that the common GPRs for the c508 and F84 overlaps at 0x0C - 0x1F.

For the 16F627, the comparator must be turned off if it is being used as digital I/O like the 16F84. To make all PORTA of 16F627 as I/O ports, we must first turn off the comparator module and enable I/O function:

    CLRF PORTA
    MOVLW 0X07
    MOVWF CMCON
    ; .. now we can set the direction of port A

The scratch pad area (GPRs) for the PIC16F870 is from 0x20 to 0x7F (96 bytes). Please note that when using the 16F87X series the low voltage programming option must be turn off when burning in chip. The comparator must be turned off if PORTA is being used as digital I/Os. The 16F87X series has 4 to 8 ADCs. They must be turned off when PORTA is being used as digital I/Os.

    BSF STATUS,RP0 ;switch to Bank1
    MOVLW 0X06
    MOVWF ADCON1 ;All pins at PORTA is digital I/Os
    ; .. now we can set the direction of port A
To make RA0 as analog input,

    BSF STATUS,RP0 ;switch to Bank1
    MOVLW 0XC1
    MOVWF TRISA ;RA0=input, RA1-RA5=output
    MOVLW 0X0E
    MOVWF ADCON1 ;RA0=analog input with Vdd & Vss as ref.
For the PIC18F452 series, you will have to set the configuration bits. Example on setting configuration bits for XT oscillator at 4MHz.

    __CONFIG _CONFIG1H, 21h
    __CONFIG _CONFIG2L, 0Eh
    __CONFIG _CONFIG2H, 0Eh
    __CONFIG _CONFIG3H, 00h
    __CONFIG _CONFIG4L, 80h
    __CONFIG _CONFIG5L, 0Fh
    __CONFIG _CONFIG5H, 0C0h
    __CONFIG _CONFIG6L, 0Fh
    __CONFIG _CONFIG6H, 0E0h
    __CONFIG _CONFIG7L, 0Fh
    __CONFIG _CONFIG7H, 40h
Please take note that there are high priority interrupts and low priority interrupts in the 18F series PIC MCU. The ADC is now 10-bits, so if you need only 8 bits ADC, you will need to left/right justify the bits.



| Home | Top Page | Contact |


Copyright Notice: This article, including all text, documents and schematic diagrams, are the intellectual property of Vincent Wong, and is Copyright (c) 2005. Reproduction or re-publication by any means whatsoever, whether it is electrical & electronic, mechanical or electro-mechanical, is strictly prohibited under International Copyright laws. The author (Vincent Wong) grants the reader the right to use this information for personal use only. Commercial use is prohibited without express written authorisation from Vincent Wong.

Copyright of Vincent Wong. All Rights Reserved.