28.02.2015 Views

TP n° 1 Prise en main de MPLAB 6 - LIAS

TP n° 1 Prise en main de MPLAB 6 - LIAS

TP n° 1 Prise en main de MPLAB 6 - LIAS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

WDTE : WatchDog Timer<br />

FOSC1/FOSC2 : Sélection du type d’oscillateur.<br />

L’objectif dans un premier temps est <strong>de</strong> réaliser une routine d’att<strong>en</strong>te permettant d’allumer une<br />

LED p<strong>en</strong>dant une <strong>de</strong>mi secon<strong>de</strong>, puis <strong>de</strong> la laisser éteinte p<strong>en</strong>dant une <strong>de</strong>mi secon<strong>de</strong>.<br />

Nous allons utiliser une routine logicielle d’att<strong>en</strong>te. Cela consiste à occuper le microprocesseur<br />

p<strong>en</strong>dant une <strong>de</strong>mi secon<strong>de</strong> (par <strong>de</strong>s décrém<strong>en</strong>tations) après l’allumage ou l’extinction <strong>de</strong> la LED.<br />

• Combi<strong>en</strong> <strong>de</strong> fois utilise t’on la routine temporisation ?<br />

• Sachant que le PIC fonctionne à partir d’un quartz à 8 MHz, combi<strong>en</strong> dénombre t’on <strong>de</strong><br />

cycle d’horloge <strong>en</strong> une <strong>de</strong>mi secon<strong>de</strong> ?<br />

• Un cycle machine a une durée <strong>de</strong> 4 coups d’horloge. A partir du tableau <strong>de</strong>s instructions<br />

(cf. le nombre <strong>de</strong> cycle machine associé à l’instruction), réaliser une routine pour<br />

« occuper » le microcontrôleur p<strong>en</strong>dant une <strong>de</strong>mi secon<strong>de</strong> ? On utilisera pour cela la<br />

fonction décrém<strong>en</strong>tation d’une variable, rappelez vous qu’une variable n’est définie que<br />

sur 8 bits.<br />

N’oubliez pas qu’un appel à une sous routine s’effectue par une instruction call et le corps <strong>de</strong><br />

l’instruction se termine par le co<strong>de</strong> return.<br />

On utilise la même routine pour l’allumage et l’extinction.<br />

L’horloge fonctionne à 8 MHZ, c'est-à-dire 4 000 000 <strong>de</strong> coups d’horloge <strong>en</strong> 0.5 secon<strong>de</strong>.<br />

Nous aurons alors 1 000 000 <strong>de</strong> cycles machines à ne ri<strong>en</strong> faire.<br />

Nous allons écrire l’ossature du programme<br />

;*******************************************<br />

;* Déclaration <strong>de</strong> variables *<br />

;*******************************************<br />

CBLOCK 0x00C<br />

Cmpt1 : 1<br />

ENDC<br />

;******************************************<br />

;* Sous routine <strong>de</strong> temporisation *<br />

;******************************************<br />

; Cette routine introduit un retard <strong>de</strong> 500 us<br />

; Elle ne reçoit aucun paramètre et ne retourne ri<strong>en</strong><br />

tempo<br />

clrf cmpt1<br />

boucle1<br />

<strong>de</strong>cfsz cmpt1,f<br />

goto boucle1<br />

return<br />

Programmes d’interruptions Page 3 Formation Thales EN3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!