AVOP-ELEKTRO-VLC-002
Download
Report
Transcript AVOP-ELEKTRO-VLC-002
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.
How does a microcontroller work?
Unlike the classic hardware solution by means of standard digital circuits, the
required function of an electronic device is carried out by means of a program
which is saved in a dedicated area of the memory of a microcontroller.
After the program is launched, the microcontroller reads the first instruction,
decodes it and carries it out. Immediately afterwards, the program will do the
same with the second instruction, then the third, fourth etc.
This is therefore referred to as a sequence of instructions, forming a definite
functional unit which performs a particular activity.
Program run is controlled by an internal source of clock frequency. Instructions
are carried out individually, at one moment it is possible to carry out only one
instruction, it is therefore not possible to carry out two or more instructions at
the same time. Everything, however, occurs many times per second, so the
result is a seemingly continuous action.
Procedure for creating applications with
microcontrollers
•
•
•
•
•
•
Assignment
Design of an electric circuit diagram
Assembling a functional model of the design prototype
Design of the program block diagram
Writing the source text of the program
Translation into the machine code of a microcontroller, elimination of
syntactic errors
• Debugging of individual parts of the program (possible software
simulation), debugging on a functional model (function check,
testing)
• Writing a finished, debugged code in the program memory of a
microcontroller
Development environment
Development environment is a
complex of means for
assembling and debugging of a
program in the target
application.
ICD (In Circuit Debugger) is a method of program debugging
directly inside the chip of a microcontroller (in its program
memory).
Main principles of designing a device with
microcontrollers.
• Careful design and check of a circuit diagram.
• Careful construction of a functional model (thorough check of the
printed circuit, measuring the components, high-quality soldering,
not to use soldering pastes and other preparations, only clean
colophony!).
• Fit the important parts of the program source text with notes to make
it comprehensible even after a longer time.
• In longer programs use the principles of structured programming,
debug the individual functional blocks separately and call them by
means of subroutines. Thus the main program block can be short
and clear and both the structure and the function of the program are
obvious at first sight.
An example of designing a simple device
controlled by a microcontroller.
• Design an electronic device in which a light emitting diode (LED) is
switched on after pressing the button. The LED diode must remain
on while the button is pressed; when the button is released, the
diode must switch off.
• Implement the device by means of the PIC16F883 microcontroller.
The function of the device must be implemented with the help of
software.
Circuit diagram design
Block diagram
Corresponding code in an assembler
__
list
config
F=inhx8m, P=16F84A, R=hex, N=0
0x3FF9
;Definition
Porta
portb
trisa
trisb
Status
of special function registers
equ
0x05
equ
0x06
equ
0x85
equ
0x86
equ
0x03
#define
#define
TL
LED
RB0
RA0
org
0
;Port inicialization
banksel
movlw
movwf
movlw
movwf
banksel
bsf
trisa
b'00001111'
trisa
b'00000000'
trisb
porta
LED
;The beginning of the main program
back
btfsc
TL
goto
back
bcf
LED
zp1
btfss
TL
goto
zp1
bsf
LED
goto
back
end
;the button is on a zero bit of the B port
;the LED diode is on a zero bit of the A port
;bank selection
;setup of ports
;bank selection
;the LED diode switching off
;button test. Is it pressed?
;no -> we read again
;yes -> switch on the LED diode!
;button test. Is it already released?
;no -> we read again
;yes -> switch off the LED diode!
The purpose of a block diagram
• Clear presentation of the function of the whole assignment
• Clear view of the division of a problem into individual parts
• Universality of the solution – independence on a particular programming
language (knowledge of a particular programming language is not necessary
at this moment)
• Easy portability between various development systems and programming
languages (there is no programming code yet)
In more complicated tasks, it is possible to make detailed drawings of
individual main functional units, they describe a certain part of the program in
a more detailed way.
A certain limit must not be, however, exceeded, otherwise the main advantage
of a block diagram – clearness – will disappear.
Summary of the subject matter
• What is the task of a program in a microcontroller?
• What is the task and purpose of a block diagram?
• Can any text editor (e.g. MS-Word) be used for writing
the source text of a program?
Summary of the subject matter
• Is it possible for a microcontroller to process several
instructions at the same time?
• What springs to your mind when you hear the term
“development environment”?
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í)