Académique Documents
Professionnel Documents
Culture Documents
I.\. Réalisation d’un chenillard, synthétisé en langage machine ou assembleur dédié 68HC11
Didier PEYTAVI
Généralités sur l’architecture des PIC
L’architecture interne de la plupart des microcontrôleurs et microprocesseurs est organisée selon une structure
dite de VON NEUMANN.
La mémoire de programme contient les instructions et les données stockées les unes à la suite des autres ; c’est
le bus de donnée seul, qui véhicule les codes des instructions et les données.
Cette structure présente des problèmes dès lors que l’on souhaite augmenter la fréquence de fonctionnement de
l’ensemble ; l’exécution d’une seule instruction demande plusieurs opérations sur le bus de données puisqu’il
faut aller chercher le code opération de l’instruction à exécuter puis la ou les données qu’elle doit manipuler.
Aussi préfèrerons nous faire appel à une structure de type HARVARD ou les instructions et les données sont
manipulées sur des bus différents. L’utilisation de ces deux bus est transparente vis à vis de l’utilisateur et les
vitesses d’exécutions obtenues sont remarquables.
L’exécution d’une instruction ne fait plus alors appel qu’à un seul cycle machine puisque l’on peut
simultanément grâce aux deux bus de données et d’instructions, rechercher le code opération de l’instruction et
la ou les données manipulées.
Les microcontrôleurs PIC de Microchip adoptent une structure interne de type HARVARD mais font également
appel à une architecture RISC (reduced instruction set computer) signifiant entre autre « processeur à jeu
d’instructions réduit ».
L’objectif d’une architecture RISC étant l’augmentation de la vitesse de fonctionnement, un certain nombre de
particularités doivent êtres prises en considération :
- Les microcontrôleurs à architecture RISC utilisent des instructions codées sur 14 bits (cas du PIC 16F83) ;
chaque emplacement de la mémoire de programme contient une instruction (x mots de 14 bits) et un seul
cycle machine est nécessaire pour assurer la lecture du code de l’instruction, d’ou une vitesse de
fonctionnement accrue.
- Les circuits RISC utilisent une structure de type pipe-line permettant d’exécuter une instruction tout en
recherchant la suivante en mémoire.
- Sur les chronogrammes ci-après, le compteur programme est augmenté d’une unité à chaque cycle Q1, alors
que les instructions sont recherchées en mémoire de programme et mémorisée dans le registre d’instructions à
chaque cycle Q4 ; une instruction s’exécute donc alors que la suivante est en cours de recherche, c’est le
propre de la structure pipe-line.
- Toutes les instructions dans une architecture RISC sont exécutées en un seul cycle machine, l’ALU disposant
en une seule fois de toutes les informations nécessaires à l’exécution de l’instruction.
- Les instructions d’un circuit de type RISC peuvent être exécutées sur tous les registres avec tous les modes
d’adressage ; il n’est donc pas nécessaire de retenir toutes les configurations particulières d’adressage.
- Pour terminer, une architecture RISC ne fait appel qu’à un jeu d’instructions réduit (33 ou 35 instructions).
Les PIC se destinent aux applications à base de microcontrôleurs ; ces boîtiers à taille réduite sont caractérisés
par un niveau d’intégration élevé leur permettant de se passer de tout circuit externe pour l’horloge et le reset.
Elle est particulière, car elle contient à la fois des registres des ressources internes et des registres à usage
général que l’on peut considérer comme de la RAM de travail, et parce qu’elle fait aussi appel à un mécanisme
de pagination.
La mémoire de donnée des PIC contient à la fois les registres de l’unité centrale, les registres des ressources
internes, et des registres à usage général ; elle est divisée artificiellement en pages de 128 octets, il suffit alors
de 7 bits pour adresser n’importe quel élément au sein d’une page.
Dans le cas du PIC 16F83 seules deux pages de 128 octets sont accessibles (bit RP1 à « 0 », RP0 est utilisé pour
accéder à une page ou à l’autre).
L’examen de l’organisation de la mémoire de donnée du PIC 16F83 donne un certain nombre d’informations :
- Les registres à usage général que l’on peut utiliser comme mémoire vive de travail, se trouvent au dessus de
l’adresse 0Bh de chaque page (0Ch en page 0, 8Ch en page 1).
- Un certain nombre de registres sont toujours implantés aux mêmes adresses ; ce sont les registres
correspondant aux fonctions de base de l’UC (de 00h à 0Bh en page 0).
- Certains registres invariants se trouvent dupliqués dans toutes les pages (sauf entre autre TMR0 – OPTION);
cela permet d’y accéder immédiatement quelle que soit la page et sans devoir positionner les bits RP0 et RP1.
- Les registres de gestion par exemple, des ports d’E/S PORTA et TRISA, se retrouvent à la même adresse,
mais dans deux pages différentes, et ce afin de pouvoir passer de l’un à l’autre par simple modification des
bits RP0 et RP1.
Bibliographie :
Fichier CHENILLARD.LST
M68HC11 Absolute Assembler Version 2.70C:\HC11\CHENIL.ASC
1 A 1004 portb equ $1004
2 A 0000
3 A B600 org $b600
4 A B600 8640 boucle ldaa #$40
5 A B602 B71004 deb staa portb
6 A B605 BDB60F jsr tempo
7 A B608 46 rora
8 A B609 8100 cmpa #$00
9 A B60B 26F5 bne deb
10 A B60D 20F1 bra boucle
11 A B60F
12 A B60F CE03B1 tempo ldx #$03b1
13 A B612 C644 tpx ldab #$44
14 A B614 5A tpb decb
15 A B615 26FD bne tpb
16 A B617 09 dex
17 A B618 26F8 bne tpx
18 A B61A 39 rts
19 A B61B
20 A end
Début
Recherche des
erreursen Fichiers d'extensions
Assemblage ou
listant le fichier (1) (2) . S19
Création du programme objet.
. LST. . LST
Le fichier
NON assemblé n'a
pas d'erreurs.
OUI
Téléchargement
du fichier.S19 dans la mémoire (3)
programme du 68HC11.
Modification
du programme (1) Essai du programme (3)
source
Le
NON programme
fonctionne
t-il?
OUI
(1).Utilisation de l'éditeur de texte
0
s1
s0
s0
0
s2
c1 B0 s1
0.2
osc
O
u1
Up
Dn Val
INDEX
I Q(I) W
B1
B2
B3
s1
s2
0
s2 s3
0 Clr Zero UBYTE
table
B4
Pr
UBYTE
essai
0 B5
B6
s3
s3
1
B7 s4
s4
B>A
B=A=C
A
B
s4
s5
0
B<C C 8 s5
s5
s6
s6
0
s7 s6
s7
0
s7
0
Rev: 0.02 Date: 10 Feb 2002 12:33 Eng: Didier PEYTAVI
Project: CHENILLARD Number:
Company:
Address: IUFM de TOULOUSE
City:
Country:
Initial Date: 26/12/2001 Page: 1 Of: 3
Utilisation d'un registre à décalage
SORTIE SERIE
s
ls
b0
s
b1
osc1 Bitshifter s
B0
Clr
b2
OSC1 B1
8 O D/U C
s
bt RAD B2
Cin Out
W B3 b3
128 In
B4 s
osc2 Shift
UINT B5 b4
OSC2 B6 s
1 O
bt B7
b5
0 s
b6
s
b7
Sortie C : Sérialisation au rythme de Shift, du contenu du registre à décalage
s
Décalage à droite si D/U = 0
RAD
0
0
00:00:00.0000 00:00:25.0000 64 0
00:00:00.0000 00:00:25.0000 b0
0
b1
SORTIE SERIE
0
s b2
ls
0
b0 b3
s
b1
0
b4
osc1 Bitshifter s
Clr
B0
b2
0
OSC1 B1 b5
8 O D/U C
s
RAD B2
bt
128
Cin
In
Out
W B3 b3 0
b6
B4 s
osc2 Shift
UINT B5 b4 1
OSC2 B6 s b7
1 O
B7
bt
0 s
b5
0
b6
s
b7
s
Utilisation d'un registre à décalage
SORTIE SERIE
s
ls
b0
s
b1
osc1 Bitshifter s
B0
Clr
b2
OSC1 B1
7 O D/U C
s
bt RAD B2
Cin Out
W B3 b3
128 In
B4 s
osc2 Shift
UINT B5 b4
OSC2 B6 s
1 O
bt B7
b5
0 s
b6
s
b7
s
RAD
0
0
00:00:00.0000 00:00:25.0000 64 0
00:00:00.0000 00:00:25.0000 b0
0
b1
SORTIE SERIE
0
s b2
ls
0
b0 b3
s
b1
0
b4
osc1 Bitshifter s
Clr
B0
b2
0
OSC1 B1 b5
7 O D/U C
s
RAD B2
bt
128
Cin
In
Out
W B3 b3 0
b6
B4 s
osc2 Shift
UINT B5 b4 1
OSC2 B6 s b7
1 O
B7
bt
0 s
b5
0
b6
s
b7
s
III.\. Introduction à la programmation graphique de REALIZER
REALIZER est un logiciel permettant de charger directement une application dans un microcontrôleur, sans
avoir à écrire une seule ligne de langage assembleur.A cette fin, l’utilisation de symboles permet de représenter
des fonctions de programmation, qui une fois liées entres elles peuvent répondre à une application dédiée.
Une bonne connaissance du microcontrôleur de destination est bien évidemment essentiel à la conduite du
projet. REALIZER génère donc à partir d’un schéma représentatif de l’application, du code assembleur prêt à
être utilisé.
Créer une application revient à placer et à connecter des symboles dans un schéma; chaque symbole
représentant graphiquement une macro en assembleur. Les différents symboles sont organisés sous la forme de
librairies décrivant des fonctions, mathématiques, logiques, de conversion, de gestion de puissance, et
permettant l’utilisation de constantes, de machines à états, ou encore de sous schémas.
Une application est construite autour d’un microcontrôleur cible; les signaux d’entrée du schémas, devant faire
référence aux broches, ports ou périphériques du microcontrôleur.
Chaque symbole est associé à une macro en assembleur; les fils de liaison représentent le flux des données, et
sont liés à des variables ou des constantes dont le type est paramétrable.
Dans REALIZER, l’application s’organise autour d’un schéma, le schéma racine (ROOT); dans un soucis de
lisibilité et de clarté dans la relecture graphique d’un fonctionnement, l’utilisation de sous-schémas (du schéma
racine) est à privilégier; notons encore que l’analyse par machines à états est aussi possible.
La programmation graphique permet aussi de prendre en compte des « évènements » tels qu’une demande
d’interruption liée à un TIMER, une interruption matérielle, un changement de valeur d’entrée…
III.\.1 Mise en œuvre partielle de la synthèse schématique de REALIZER
A.\.1. Création d’un nouveau projet ou ouverture d’un projet existant (.RPF)
(définition du composant cible destiné à recevoir le code machine; ici le PIC16F83).
(choix automatique des librairies de symboles).
A.\.2. Saisie du schéma racine (ROOT) ou ouverture d’un fichier schéma existant (.SCH)
* Sélection graphique des signaux à visualiser par ajout « d’OBJECT » de type PROBE
(NUMERIC)
* Génération des stimulis (signaux de commandes) par ajout « d’OBJECT » de type ADJUSTER
(NUMERIC)
.RRF: Fichier de report du projet crée (prise en compte du chipset de destination, taux d’occupation des
ressources matérielles internes).
.INC: Table d’équivalence associant à chaque ressource interne (registre, mémoire, entrée, sortie) son
adresse physique.
.ERR: Fichier pointant les erreurs symboliques, syntaxiques, et de définitions des entrées/sorties.
----------------------------------------------------------------------
PIC16F83 Realizing Unit (V4.00) (c) 1990-2000 Actum Solutions
Report file of project C:\WINDOWS\BUREAU\chenillard\chenillard.rpf
Scheme Version : 1.00
Report timestamp : Tue Dec 26 00:19:45 2000
Analyze results : No errors
----------------------------------------------------------------------
Optimisations:
----------------------------------------------------------------------
Ram size optimisation: Disabled
Sleeping code optimisation: Disabled
Constant optimisation: Disabled
Speed optimisation: Disabled
Symbol:
Function: Converts a physical digital value to a binary value.
Syntax:
Pin Description
In Physical digital input (type = Boolean). The user is
prompted for the symbolic name (In). The connection is
made to a physical micro controller pin and is invisible.
Out Digital representation of digital value (type = Boolean).
Remarks:
The NAME attribute is used for connecting this symbol
to a hardware port. For this, double-click the symbol or
use the right mouse button.
The COMMENT attribute is used in the report file.
Digital output
Name: DIGOUT
Library: MAIN.LIB
Symbol:
Function: Converts a binary value to a physical digital output.
Syntax:
Pin Description
In Digital representation of digital value (type = Boolean).
Out Physical digital output (type = Boolean). The user is
prompted for the symbolic name (In). The connection is
made to a physical micro controller pin and is invisible.
Remarks:
the NAME attribute is used for connecting this symbol to
a hardware port. For this, double-click the symbol or use
the right mouse button.
The COMMENT attribute is used in the report file.
Constant bit
Name: CONSTB
Library: MAIN.LIB
Symbol:
Function: Constant Boolean.
Syntax:
Pin Description
Value Constant value entered by the user (0 or 1).
Out Binary value (type: Boolean).
Remarks: None.
Constant word
Name: CONSTW
Library: MAIN.LIB
Symbol:
Function: Constant Word.
Syntax:
Pin Description
Value Constant value entered by the user.
The following formats are allowed:
Decimal 123
Hexadecimal: 0xD4 or 1FFH
Octal: 345O
Binary: 1100110B
Out Binary value (type: Word).
Remarks: None.
Oscillator fixed
Name: OSCF
Library: MAIN.LIB
Symbol:
Function: Oscillator with a fixed oscillation time.
Syntax:
Pin Description
Time Oscillation time value (in days:hrs:min:sec.xxx). The
user is prompted to enter this value.
where:
days is the number of days, hrs is the number of hours,
min is the number of minutes, sec is the number of
seconds and xxx is a fraction of a second.
O Delayed output (type: Boolean).
O becomes I after the chosen time period
Time
Out
Symbol:
Function: Counter with a fixed pre-set value
Syntax:
Pin Description
Up Up, binary value (type = Boolean).
Dn Down, binary value (type = Boolean).
Clr Clear, binary value (type = Boolean).
Pr Pre-set, binary value (type = Boolean).
Value Pre-set value, the user is prompted to enter this value.
Val if Clr = 1 Then Val = 0
else
if Pr becomes 1 Then Val = Value
if Up becomes 1 Then Val = Val + 1
if Dn becomes 1 Then Val = Val – 1
(type: depends on the type entered by the user)
Zero if Val = 0 Then Zero = 1
else Zero = 0
Remarks: None.
Comparator
Name: COMP
Library: MAIN.LIB
Symbol:
Function: Multi purpose comparator.
Syntax:
Pin Description
A Binary value (type = Word).
B Binary value (type = Word).
C Binary value (type = Word).
B>A When input B is larger than input A
Then output = 1
Else output = 0
(type: Boolean)
B=A=C When input B equals input A and equals input C
Then output = 1
Else output = 0
(type: Boolean)
B<C When input B is smaller than input C
Then output = 1
Else output = 0
(type: Boolean)
Remarks: None.
Index table
Name: INDEXTABLE
Library: MAIN.LIB
Symbol:
Function: Index conversion table.
Syntax:
Pin Description
In Binary value (type = Word).
Out Convert the input to a non-linear output value, defined in
a table. The input is used as an index to address the
constant value from the table.
(Type: depends on type entered by the user).
Remarks:
If the input exceeds the index size the default value
is used.
The values are stored as an ASCII file. Just double
click the symbol or use the right mouse button
(Enter) to edit the table.
Byte unpack
Name: BUNPACK
Library: MAIN.LIB
Symbol:
Function: 1 Byte to bits unpacker.
Syntax:
Pin Description
W Binary value (type = Word).
B0 .. B7 The W input is unpacked to 8 separate Boolean outputs.
B0 is the least significant bit (Type: Boolean).
Remarks: Enables you to unpack a byte into eight (or less) bits.
Shift register
Name: SHIFT
Library: MAIN.LIB
Symbol:
Function: Shift register
Syntax:
Pin Description
Clr Clears the shift register, binary value (type = Boolean).
D/U Selects the up (1) or down (0) shift direction, binary
value (type = Boolean).
Cin Latches input In into the shift register, binary value (type
= Boolean).
In Input, binary value, when a Boolean value is presented
then the value is shifted into the register (serial in)
otherwise the value will be copied into the register
(parallel in). (type = All).
Shift Shift, binary value, shifts the register up or down,
depending on the D/U input (type = Boolean).
Out if Clr = 1 Then Out = 0
else
see the description of the input pins
(type: depends on the type entered by the user)
C Carry Out, contains the Boolean shifted out (type
Boolean)
Remarks: None.
Converter
Name: CONVERT
Library: MAIN.LIB
Symbol:
Function: Multi purpose converter.
Syntax:
Pin Description
In Binary value (type = All).
Out Convert the input to any output type, this symbol
enables the user to convert Booleans to Words and visa
versa.
(Type: depends on type entered by the user).
Remarks: None.
Appendix A: Variables and
Attributes
This appendix provides you with quick access to the type of information
you'll need when you create Realizer applications. This information
includes:
• A list of the type of variables you can define, and the rules that apply
to variables.
• A list of the attributes you can place on symbols and wires.
PIC16CR8X
PIC16F8X
(PIC16LF8X, PIC16LCR8X) MCLR 4 15 OSC2/CLKOUT
VSS 5 14 VDD
High Performance RISC CPU Features: RB0/INT 6 13 RB7
• Only 35 single word instructions to learn RB1 7 12 RB6
• All instructions single cycle except for program RB2 8 11 RB5
branches which are two-cycle RB3 9 10 RB4
13 Data Bus 8
Flash/ROM Program Counter EEPROM Data Memory
Program
Memory
PIC16F83/CR83 RAM
512 x 14 File Registers EEPROM
8 Level Stack EEDATA Data Memory
PIC16F84/CR84 PIC16F83/CR83
(13-bit) 36 x 8 64 x 8
1K x 14
PIC16F84/CR84
68 x 8
Program
Bus 14
7 RAM Addr EEADR
Addr Mux
Instruction reg
MUX
Power-up
Timer I/O Ports
8
Instruction Oscillator
Decode & Start-up Timer
Control ALU
Power-on RA3:RA0
Reset
Timing Watchdog RB7:RB1
Timer W reg
Generation
RB0/INT
MCLR 4 4 I/P ST Master clear (reset) input/programming voltage input. This pin is an
active low reset to the device.
PORTA is a bi-directional I/O port.
RA0 17 17 I/O TTL
RA1 18 18 I/O TTL
RA2 1 1 I/O TTL
RA3 2 2 I/O TTL
RA4/T0CKI 3 3 I/O ST Can also be selected to be the clock input to the TMR0 timer/
counter. Output is open drain type.
PORTB is a bi-directional I/O port. PORTB can be software pro-
grammed for internal weak pull-up on all inputs.
RB0/INT 6 6 I/O TTL/ST (1) RB0/INT can also be selected as an external interrupt pin.
RB1 7 7 I/O TTL
RB2 8 8 I/O TTL
RB3 9 9 I/O TTL
RB4 10 10 I/O TTL Interrupt on change pin.
RB5 11 11 I/O TTL Interrupt on change pin.
RB6 12 12 I/O TTL/ST (2) Interrupt on change pin. Serial programming clock.
RB7 13 13 I/O TTL/ST (2) Interrupt on change pin. Serial programming data.
VSS 5 5 P — Ground reference for logic and I/O pins.
VDD 14 14 P — Positive supply for logic and I/O pins.
Legend: I= input O = output I/O = Input/Output P = power
— = Not used TTL = TTL input ST = Schmitt Trigger input
Note 1: This buffer is a Schmitt Trigger input when configured as the external interrupt.
2: This buffer is a Schmitt Trigger input when used in serial programming mode.
3: This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.
section discussing each individual peripheral module. Peripheral Interrupt Vector 0004h
User Memory
The data memory area also contains the data
Space
EEPROM memory. This memory is not directly mapped
into the data memory, but is indirectly mapped. That is,
an indirect address pointer specifies the address of the
data EEPROM memory to read/write. The 64 bytes of
data EEPROM memory have the address range
1FFh
0h-3Fh. More details on the EEPROM memory can be
found in Section 7.0.
The reset vector is at 0000h and the interrupt vector is Stack Level 8
at 0004h. Reset Vector 0000h
3FFh
1FFFh
The data memory is partitioned into two areas. The first All devices have some amount of General Purpose
is the Special Function Registers (SFR) area, while the Register (GPR) area. Each GPR is 8 bits wide and is
second is the General Purpose Registers (GPR) area. accessed either directly or indirectly through the FSR
The SFRs control the operation of the device. (Section 4.5).
Portions of data memory are banked. This is for both The GPR addresses in bank 1 are mapped to
the SFR area and the GPR area. The GPR area is addresses in bank 0. As an example, addressing loca-
banked to allow greater than 116 bytes of general tion 0Ch or 8Ch will access the same GPR.
purpose RAM. The banked areas of the SFR are for the
registers that control the peripheral functions. Banking 4.2.2 SPECIAL FUNCTION REGISTERS
requires the use of control bits for bank selection. The Special Function Registers (Figure 4-1, Figure 4-2
These control bits are located in the STATUS Register. and Table 4-1) are used by the CPU and Peripheral
Figure 4-1 and Figure 4-2 show the data memory map functions to control the device operation. These
organization. registers are static RAM.
Instructions MOVWF and MOVF can move values from The special function registers can be classified into two
the W register to any location in the register file (“F”), sets, core and peripheral. Those associated with the
and vice-versa. core functions are described in this section. Those
The entire data memory can be accessed either related to the operation of the peripheral features are
directly using the absolute address of each register file described in the section for that specific feature.
or indirectly through the File Select Register (FSR)
(Section 4.5). Indirect addressing uses the present
value of the RP1:RP0 bits for access into the banked
areas of data memory.
Data memory is partitioned into two banks which
contain the general purpose registers and the special
function registers. Bank 0 is selected by clearing the
RP0 bit (STATUS<5>). Setting the RP0 bit selects Bank
1. Each Bank extends up to 7Fh (128 bytes). The first
twelve locations of each Bank are reserved for the
Special Function Registers. The remainder are Gen-
eral Purpose Registers implemented as static RAM.
4Fh CFh
50h D0h
The INDF register is not a physical register. Address- EXAMPLE 4-2: HOW TO CLEAR RAM
ing INDF actually addresses the register whose USING INDIRECT
address is contained in the FSR register (FSR is a
ADDRESSING
pointer). This is indirect addressing. movlw 0x20 ;initialize pointer
movwf FSR ; to RAM
EXAMPLE 4-1: INDIRECT ADDRESSING NEXT clrf INDF ;clear INDF register
• Register file 05 contains the value 10h incf FSR ;inc pointer
• Register file 06 contains the value 0Ah btfss FSR,4 ;all done?
• Load the value 05 into the FSR register goto NEXT ;NO, clear next
• A read of the INDF register will return the value of CONTINUE
: ;YES, continue
10h
• Increment the value of the FSR register by one An effective 9-bit address is obtained by concatenating
(FSR = 06) the 8-bit FSR register and the IRP bit (STATUS<7>), as
• A read of the INDF register now will return the shown in Figure 4-1. However, IRP is not used in the
value of 0Ah. PIC16F8X.
Reading INDF itself indirectly (FSR = 0) will produce
00h. Writing to the INDF register indirectly results in a
no-operation (although STATUS bits may be affected).
00 01 10 11
00h 00h
not used not used
0Bh
0Ch
Addresses
Data 2Fh (1) map back
Memory (3) 30h (1) to Bank 0
4Fh (2)
50h (2)
7Fh 7Fh
Bank 0 Bank 1 Bank 2 Bank 3