AVOP-ELEKTRO-VLC-005

Download Report

Transcript AVOP-ELEKTRO-VLC-005

Training program: Mechanic - electrotechnician
Program name:
Digital processing - microprocessors
III. class
Microcontrollers
Elaborated by: Vlastimil Vlček
Projekt Anglicky v odborných předmětech, CZ.1.07/1.3.09/04.0002
je spolufinancován Evropským sociálním fondem a státním rozpočtem České republiky.
PORTS from a programmer´s point of view
•
•
•
•
They are used for communication of a microcontroller with its environment
(the only pins brought out of the package, apart from the power supply and
the circuit of the oscillator).
They are mapped into the address space of the data memory (they belong
to special function registers – see the list of SFRs).
Data downstream through the ports is software programmable - at the level
of individual bits of a port.
The RE3 bit can be used only as an input (standardly MCLR)!
PIC16F883 PORTS
Illustration of a table
(PIC16F883 datasheet)
describing the function of pins
in individual ports.
All pins (except for pins No
8,19, 20) can be used as
common digital I/O lines or can
have a different function – see
the table.
The function of pins is software
selectable (also during the
program run).
Pins No 8,19, 20 are supply
pins. The RA3 pin is only an
input pin!
Data downstream is
determined by writing into the
TRIS registers.
Setup of data downstream through the ports –
TRIS registers
I = INPUT (data in)
O = OUTPUT (data out)
Memotechnic device:
1 = I = INPUT
0 = O = OUTPUT
It is possible to set up the data downstream for each port separately.
This can be done whenever, even during the program run.
Ports – block diagram
Flip-flop circuits of the D type form so-called output “latch” register. The data written
from the data bus are, at the I/O pin, released only after the gate (controlled by the TRIS
register output) opens.
Initialization of ports
Initialization of ports is carried out at the start of a program:
•Setup of a port type (analog or digital)
•Setup of the data downstream of individual bits of the port
•An example of a program in assembler for the initialization of the A port:
BANKSEL ANSEL
peripherals =>
CLRF
CLRF
BANKSEL TRISA
the A port:
MOVLW
MOVWF
BANKSEL PORTA
the ports
;switching off of analog
ANSEL
ANSELH
;all ports = digital I/O
;setup of the data downstream of
B’00001111’
TRISA
;RA <7:4> = output,
;RA <3:0> = input
;setup of the 0 bank – work with
Main principles of working with ports
Handling of unconnected input port pins:
•By means of hardware:
– Connecting a pin to an earth potential
– Connecting a pin to the positive power-supply voltage via a
resistor
•By means of software:
– Setting up a pin to an output mode (attention – then it cannot be
earthed!)
Protection against the current overload of the output pins:
•By a limiting resistor
•By current amplification (a switching transistor)
•By an insulated separating element (an optomember)
Summary of the subject matter
• What is the role of ports in a microcontroller?
• How many ports does the PIC16F883 microcontroller contain how
are they marked?
• What is the bit width of a port?
• Is the data downstream through the ports firmly determined by the
internal connection of a microcontroller?
• Are all the ports and their individual bits always and under all
circumstances available?
Summary of the subject matter
• What is the role of the TRIS registers?
• For what reasons is so-called inicialization of ports carried out?
• Is it necessary to handle the unconnected pins of a port somehow?
If so, how?
• From the documentation, find out the maximum permissible current
of one pin of the port in an output mode and the maximum
permissible current of the whole port! What important finding ensues
from this information?
References



Datasheet Microchip PIC16F882/883/884/886/887 DS41291E
(http://www.microchip.com)
Jiří Hrbáček: Mikrořadiče PIC16CXX a vývojový kit PICSTART (BEN – technická literatura,
Praha 2001 3. dotisk 4. vydání)
Jiří Hrbáček: Komunikace mikrokontroléru s okolím 1 ((BEN – technická literatura, Praha
2002)