Nous allons étudier un programme qui va utiliser une fonction tempo
Le but de cette fonction est de faire compter le Temp par notre microcontrôleur en cycle (c)
Comme nous utilisons la fonction call (appel a un sous programme) nous allons avoir besoin de SP qui doit pointer dans de la RAM , donc mov.w #270,SP sert a cela.
Et nous arrêtons le Watch DOG comme d'habitude. mov.w #WDTPW|WDTHOLD, &WDTCTL
.include "msp430x2xx.inc"
cette inclusion permet d'utiliser les étiquettes des registres des périphériques du msp
.msp430
.include "msp430x2xx.inc"
.org 0xF800
Debpp:
mov.w #WDTPW|WDTHOLD, &WDTCTL
mov.w #0x270,SP ; Stack pointer dans la ram
bis.b #1, P1DIR ; mise en sortie P1.0
bic.b #1, P1OUT ; ecrire 0 sur P1.0
onboucle:
call #tempo
xor.b #0x01,P1OUT ; toogle on change l'état de la LED rouge
jmp onboucle
fin: jmp fin
tempo:
mov.w #20,R9 ; X1 = 20 2 c
la: mov.w #50000,R10 ; X2 = 50000 2 c
ici: dec.w R10 ; 1 c
jnz ici ; 2 c
dec.w R9 ; 1 c
jnz la ; 2 c
ret
.org 0xFFFE
.dw Debpp
Les 2 fichiers du projet tempo:
naken_asm tempo.asm -o tempo.hex -l
grâce au fichier lst on obtient le nombre de cycles de chaque mnémonique.
.msp430
.include "msp430x2xx.inc"
.org 0xF800
Debpp:
mov.w #WDTPW|WDTHOLD, &WDTCTL
0xf800: 0x40b2 mov.w #0x5a80, &0x0120 cycles: 5
0xf802: 0x5a80
0xf804: 0x0120
mov.w #0x270,SP ; Stack pointer dans la ram
0xf806: 0x4031 mov.w #0x0270, SP cycles: 2
0xf808: 0x0270
bis.b #1, P1DIR ; mise en sortie P1.0
0xf80a: 0xd3d0 bis.b #1, 0x10022 cycles: 2
0xf80c: 0x0816
bic.b #1, P1OUT ; ecrire 0 sur P1.0
0xf80e: 0xc3d0 bic.b #1, 0x10021 cycles: 2
0xf810: 0x0811
onboucle:
call #tempo
0xf812: 0x12b0 call #0xf81e cycles: 5
0xf814: 0xf81e
xor.b #0x01,P1OUT ;toogle
0xf816: 0xe3d0 xor.b #1, 0x10021 cycles: 2
0xf818: 0x0809
jmp onboucle
0xf81a: 0x3ffb jmp 0xf812 (offset: -10) cycles: 2
fin: jmp fin
0xf81c: 0x3fff jmp 0xf81c (offset: -2) cycles: 2
tempo:
mov.w #20,R9
0xf81e: 0x4039 mov.w #0x0014, r9 cycles: 2
0xf820: 0x0014
la: mov.w #50000,R10
0xf822: 0x403a mov.w #0xc350, r10 cycles: 2
0xf824: 0xc350
ici: dec.w R10
0xf826: 0x831a sub.w #1, r10 cycles: 1
jnz ici
0xf828: 0x23fe jne 0xf826 (offset: -4) cycles: 2
dec.w R9
0xf82a: 0x8319 sub.w #1, r9 cycles: 1
jnz la
0xf82c: 0x23fa jne 0xf822 (offset: -12) cycles: 2
ret
0xf82e: 0x4130 ret -- mov.w @SP+, PC cycles: 3
.org 0xFFFE
.dw Debpp
data sections:
fffe: 00 f8 ..
Program Info:
LABEL ADDRESS SCOPE
Debpp 0000f800 0
onboucle 0000f812 0
fin 0000f81c 0
tempo 0000f81e 0
la 0000f822 0
ici 0000f826 0
-> Total symbols: 6
Include Paths: .
/usr/local/share/naken_asm/include
include
Instructions: 15
Code Bytes: 48
Data Bytes: 2
Low Address: f800 (63488)
High Address: ffff (65535)
T =2+ X1 (2+X2(1+2)+1+2)
X1 : 20
X2: 50000
A.N :
2+20 x (2+(50000x3)+3)
T= 3000140 µs
T= 3 s environ
T = X1 (2+2+X2(1+2)+1+2)
T en cycle (ici une microseconde)
X1 et X2 sont des variables pouvant évoluer de 1 a 65535
Générateur d'un la sur P1.1
pour faire jouer un signal carré sur P1.1 un 'la' de 440Hz T/2=1136 us , ou cycle du msp430
.msp430
.include "msp430x2xx.inc"
.org 0xc000
debut: mov.w #WDTHOLD|WDTPW ,WDTCTL
bis.b #2, P1DIR ; mise en sortie P1.1
bic.b #2, P1OUT ; ecrire 0 sur P1.1
debson: call #tempo
;mettre à 1 P1.1
bis.b #2, P1OUT
call #tempo
;mettre à 0 P1.1
bic.b #2, P1OUT
jmp debson
tempo: mov.w #379,R7 ; T/2 de 440Hz
decrem: dec R7
jnz decrem
ret
fin: jmp fin
; vecteur reset
.org 0xfffe
dw debut
.end