PIC16F84 Microcontroller - Philadelphia University

Transcription

PIC16F84 Microcontroller - Philadelphia University
5.4 Microcontrollers II:
PIC16F84 Microcontroller
Dr. Tarek A. Tutunji
Mechatronics Engineering Department
Philadelphia University, Jordan
PIC Microcontroller


In the previous sequence, general
microcontrollers and PIC architecture were
introduced
In this presentation, PIC 16F84 will be
used to elaborate microcontrollers. This
will include
•
•
•
•
Pins description
Registers
Instruction set
Design & programming examples
PIC 16F84 Pins

General Specifications
•
•
•
•
•

Runs at 10 MHz
8-bit data
14-bit instruction
1K Flash memory
One working register (W)
18 pins
• VDD (+5V), VSS (gnd)
• 13 I/O pins through two ports
• Port A: 5-pins RA0 RA5

RA4 dual purpose (timer)
• Port B: 8-pins RB0RB7

RB0 dual purpose (Interrupt)
• !MCLR master clear (active low)
• CLKIN (RC clock input)
PIC 16F84 Registers


All file registers are 8-bits
They are divided into:
• SPR, specific purpose
• GPR, general purpose

The main specific registers are
• PORTA: has 5 I/O bits
• TRISA: specifies the direction of
port pins

‘1’ for Input & ‘0’ for Output
• PORTB: has 8 I/O bits
• TRISB: specifies the direction of
port pins
• STATUS: bit 5 = 0 (1)  page 0 (1)
• TMR0: 8-bit timer
• INTCON: Interrupt Control register
35 Instructions
Instructions used in next examples









MOVLW
MOVWF
CLRF
INCF
BCF
BSF
BTFSS
BTFSC
GOTO
k
f
f
f
f,b
f,b
f,b
f,b
k
move literal ‘k’ to W
move W contents to f
clear f
increment f
clear bit ‘b’ in register ‘f’
set bit in f
bit test, skip if set
bit test, skip if clear
go to address k
LED : circuit diagram
Writing to port (LED):
assembly program
; This program is used to flash LED connected to pin RA1
STATUS equ 03h
TRISA equ 85h
PORTA equ 05h
Start
; ‘equ’ is not an instruction
; it is used by the assembler
; gives name to address value
bsf STATUS,5
movlw 00h
movwf TRISA
bcf STATUS,5
;
;
;
;
Set bit 5 in Status register  go to page 1
Move ’00’ to W (working register)
Move contents of W to TRISA  all output
Clear bit 5 in Status register  go to page 0
movlw 02h
movwf PORTA
movlw 00h
movwf PORTA
goto Start
;
;
;
;
;
Move ’02’ to W
Port A = ‘0000 0010’  RA1 ‘high’
Move ’00; to W
Port A = ‘0000 0000’  RA1 ‘low’
loop back to Start
+5V
Switches and LEDs:
circuit diagram
Vdd
!MCLR
R
RB1
RB2
RA0
RA1
CLKIN
RB0
PIC
16F84
RB3
RB4
RB5
Sw1
clear
Sw2
count
RB6
C
RB7
Vss
Reading & Writing
; This program outputs binary count to LEDs connected at RB0 to RB7
; Input switches connected to RA0 and Ra1 stops, starts, and resets the count
STATUS
PORTA
TRISA
PORTB
TRISB
equ
equ
equ
equ
equ
03
05
85
06
86
bsf
movwf
movlw
movwf
movlw
bcf
Reset
Start
; assigns names to register addresses
status, 5
00
PORTB
ff
PORTA
status,5
;
;
;
;
;
;
go to page 1
W = ‘0000 0000’
makes PORTB output (connected to LEDs)
W = ‘1111 1111’
makes PORTA input (connected to switches)
go back to page 0
clrf
portb
btfss
PORTA,0
goto
Reset
btfsc
PORTA,1
incf
PORTB
goto Start
;
;
;
;
;
PORTB = ‘0000 0000’  All LEDs off
Read RA0 (SW1), test RA0 value and skip if ‘1’
go back to Reset
Read RA1 (SW2), test RA1 value and skip if ‘0’
Increment PORTB  PORTB = PORTB+1
Summary






PIC 16F84 microcontroller runs at
maximum frequency of 10 MHz
The input clock can either be RC circuit or
oscillator
PIC 16F84 has 13 I/0 ports divided into 2
ports (A and B)
The main registers are: PORTA, PORTB,
TRISA, TRISB, and STATUS
There are 35 instructions
Examples for simple I/O circuits (LEDs and
Switches) were given