Pic16f84a project

Pic16f84a project:
The following video is about a “keylock” project, in this project we are using: Pic16f84a, a 4x4 keypad, and some logic gates (only to reduce the number of I/O pins used in the Pic16f84a).



 

How to program a pic16f84a

How to program a pic16f84a:
To explain that we’ll use an example of flashing a led and we’ll explain this code.
The code is the following:
start
; assigning names to addresses
STATUS equ    0x03
TRISA  equ   0x85
TRISB  equ   0x86
COUNT1 equ    0x0c
; Port configuration
bsf STATUS,5    ;go to bank1
movlw 0x00      ;put the value 00h " 'h' means in hexadecimal
movwf TRISA     ;put the value in TRISA
bcf STATUS,5     ;go to bank0
; initialize the COUNT1 register
movlw 0xff         ;put the value ffh in the w register
movwf COUNT1
main
movlw 0x01         ;put the value 01h in the w register
movwf PORTA      ;put the value in PORTA
call delay              ;make a delay
call delay              ;make a delay
clrf PORTA            ;make all PORTA pins '0' logic
call delay              ;make a delay
call delay              ;make a delay
goto main
delay
decfsz COUNT1,1  ; decrement COUNT1 by '1' when reaching '0' value then jump
goto delay
movlw 0xff              ;put the value ffh in the w register
movwf COUNT1     ;put the value in COUNT1 register
return
END                       ; directive 'end of program'
NOTE:
To make any bit of the pic16f84a’s port (PORTA or PORTB) as output, we send the logic”0” to the specified bit in the TRIS register (TRISA or TRISB).
Code explanation:
bsf STATUS,5
STATUS equ   0x03
This means that we give the name STATUS to the address o3h, “h” means in hexadecimal, so instead of using addresses it will be easier to use names that we can remember in the program. So each time we write “STATUS” in the program the assembler will use the address 03h instead.
Set the bit 5 in the STATUS register  to change from bank0 to bank1 that contains registers to configure ports (pins as outputs or inputs) and other registers (see PIC16F84A REGISTER FILE MAP).
movlw 0x00  
Put the value 00h “h” means the value is in hexadecimal and in our code we used the “0x” which means also that the value is in hexadecimal.
movwf TRISA    
put the value of the “w” register in TRISA register, the value is 00h and that means that we make all the bits of PORTA as output.
bcf STATUS,5     
clear the bit 5 in the STATUS register  to change from bank1 to bank0 .
movlw 0xff        ;put the value ffh in the w register
movwf COUNT1
put the value ffh in the COUNT register, this value that we are going to decrement till we reach the value 00h and that will make  a delay.
movlw 0x01         ;put the value 01h in the w register
movwf PORTA      ;put the value in PORTA
This will make the bit0 of PORTA high (logic 1)
call delay              ;make a delay
Jump to the delay subroutine to make a delay and then come back to the next instruction.
clrf PORTA            ;make all PORTA pins '0' logic
Make all pins of PORTA low (logic 0).
goto main
Go back to main label, and that will make the program be repeated.
decfsz COUNT1,1  ; decrement COUNT1 by '1' when reaching '0' value then jump
Decrement COUNT1 by '1' when reaching '0' value then jump the next instruction, and in this example it will jump to “movlw 0xff “instruction.
return
End the subroutine and go back to the main program( to the instruction that follows the instruction that called this subroutine).

PIC16F84A LIST OF INSTRUCTIONS

PIC16F84A LIST OF INSTRUCTIONS:

PIC16F84A accept 35 instructions and this is a list of them:


Photobucket

PIC16F84A REGISTER FILE MAP

PIC16F84A REGISTER FILE MAP:




This figure shows the register file map inside the PIC16F84
It’s devided into two banks , Bank 0 and Bank 1. Bank 1 is used to control the actual operation of the PIC, Bank 0 is used to manipulate the data.
example : to make one bit on Port A high. First we need to go to Bank 1 to set the particular bit, or pin, on Port A as an output. We then come back to Bank 0 and send a logic 1 to that pin.



The most common used registers are : STATUS, TRISA and TRISB. The first allows us to come back to Bank 0, TRISA allows us to determine which pins on Port A are output and which are input, TRISB allows us to determine which pins on Port B are output and which are input. The SELECT register in Bank 0 allows us to switch to Bank 1.

STATUS

To change from Bank 0 to Bank 1 we tell the STAUS register. We do this by setting bit 5 of the STATUS register to 1. To switch back to Bank 0, we set bit 5 of the STATUS register to 0. The STATUS register is located at address 03h (the ‘h’ means the number is in Hexadecimal).



TRISA and TRISB.
These are located at addresses 85h and 86h respectively. To program a pin to be an output or an input, we simply send a 0 or a 1 to the specified bit in the register. Now, this can either be done in binary, or hex.
On Port A we have 5 pins, and hence 5 bits. If we wanted to set one of the pins to input, we send ‘1’ to the specified bit. If we wanted to set one of the pins to an output, we set the specified bit to ‘0’.




PORTA and PORTB:
To send one of our output pins high, we simply send a ‘1’ to the corresponding bit in our PORTA or PORTB register. To read if a pin is high or low on our port pins, we can make a check to see if the particular corresponding bit is set to high (1) or set to low (0)
W:
The W register is a general register in which we can put any value that we wish. When we assigned a value to W register, we can add it to another value, or move it. If you assign another value to W, its contents are overwritten.

PIC16F84A PROGRAM MEMORY MAP

PIC16F84A PROGRAM MEMORY MAP :

PIC16F84A BLOCK DIAGRAM

PIC16F84A BLOCK DIAGRAM:

PIC16F84A

PIC16F84A

This is an 8-bit microcontroller with 18 pins.

main features:
- 35 instructions
- Instructions coded on 14 bits
- 8-bit data
- 1 instruction per machine cycle, except for the jumps (2 machine cycles)
- Maximum speed is 10 MHz instruction in 400 ns (1 machine cycle = 4 clock cycles)
- 4 interrupt sources
- 1000 cycles of erase / write to flash memory, 10 million for the EEPROM data memory



Pins assignment and there functions:




The functions of the pins are:

- VSS, VDD: Power
- OSC1, 2: Clock
- RA0-4: Port A
- RB0-7: Port B
- T0CKL: external clock input
- INT: Interrupt input
- MCLR: Reset: 0V
Selecting the program mode: 12V - 14V
Execution: 4.5V - 5.5V

Identification of PICs

Identification of PICs:

A PIC is identified by a number of the following form: xx (L) XXYY-zz
- Xx: Family of the component (12, 14, 16, 17, 18)
- L: Tolerance of voltage range
- XX: Type of Program Memory
For exemple :
C - EPROM or EEPROM
CR - PROM
F - FLASH
- Yy: Identification
- Zz: Maximum speed of the quartz

For example, PIC 16F84 -04, means:
- 16: Mid-Line
- F: FLASH
- 84: Type
- 04: Quartz up to 04MHz

Classification of Microchip PICs

Classification of Microchip PICs:

Microchip currently models are classified into three major families, each with several references. These families are:

■ Base-line: the instructions are coded on 12 bits.
■ mid-line: the instructions are coded on 14 bits.
■ High-End: The instructions are 16-bit.

PIC introduction

Introduction:

Microcontrollers are now established in most simple or professional applications, there are several kinds of microcontrollers.

The U.S. company Microchip Technology has developed in the 90’s CMOS microcontroller: the PIC (Peripheral Interface Controller). This component is widely used at the present time,it’s easy to use,quick in data treatment and has reduced cost.

The PIC exist in several versions:

 the UVPROM that are erasable by a source of ultraviolet radiation
 OTPROM the one-time programmable
 E ² PROM and the flash EPROM that is electrically erasable.

What is a mictocontroller?


What is a mictocontroller?

A microcontroller is an integrated circuit which includes the essential elements of a computer: CPU, memories (ROM for the program and RAM for the data), peripheral units and input-output interfaces.

Microcontrollers are characterized by a higher degree of integration, lower power consumption, a lower operating speed (a few megahertz to a few hundred megahertz) and reduced cost compared to microprocessors used in personal computers.

Compared to other electronic systems based on microprocessors and other separated components, microcontrollers can reduce the size, power consumption and cost of products.

Microcontrollers are widely used in embedded systems such as automotive engine controllers, remote controls, office equipment, toys, mobile phones...



Facebook

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost