LaDissertation.com - Dissertations, fiches de lectures, exemples du BAC
Recherche

Pic De microcontrôleurs

Recherche de Documents : Pic De microcontrôleurs. Recherche parmi 298 000+ dissertations

Par   •  17 Mai 2013  •  1 018 Mots (5 Pages)  •  640 Vues

Page 1 sur 5

Débuter avec les microcontrôleurs PIC

RAPPEL:

Brochage du circuit

Schéma de départ

Vous allez pouvoir trouver sur cette page quelques programmes pour faire vos premiers pas avec les microcontrôleurs PIC.

Allumer une led:

; programme qui permet d'allumer une LED

; sur la sortie PB3

#include <p16F84.inc> ; initialisation des noms de variables

ORG 0x00 ; début de programme

goto main ; saut au programme principal

main nop ; TRIS est le registre de direction des ports

bsf STATUS,5 ; banque 1 pour accéder au registre TRIS

movlw B'00000000' ; 0 = sortie

movwf TRISB ; le port b est entièrement en sortie

bcf STATUS,5 ; retour à la banque 0

bsf PORTB,0 ; met le bit 0 du port B à 1 (allume la LED)

end ; fin de programme

Faire clignoter une led:

; programe qui permet de faire clignoter une LED

; sur le port B0

; sans utiliser les interruptions et le TIMER TMR0

#include <p16F84.inc>

compt_1 equ 0C

compt_2 equ 0D

compt_3 equ 0E

compt_4 equ 0F

ORG 0x00 ; processor reset vector

goto main

; * * * * * * * * * * * * * * * * * * * * * * * * * *

;

; sous-programmes d'attente

;

; * * * * * * * * * * * * * * * * * * * * * * * * * *

wait: nop ; 1er temps d'attente

decfsz compt_1,1 ; environ 260 ms

goto wait

movlw 0xff

movwf compt_1

decfsz compt_2,1

goto wait

movlw 0xff

movwf compt_1

movlw 0xff

movwf compt_2

return

wait2: nop ; 2ème temps d'attente

decfsz compt_3,1 ; environ 200ms

goto wait2

movlw 0xAf

movwf compt_3

decfsz compt_4,1

goto wait2

movlw 0xAf

movwf compt_3

movlw 0xAf

movwf compt_4

return

; * * * * * * * * * * * * * * * * * * * * * * * * * * *

;

; Programme Principal

;

; * * * * * * * * * * * * * * * * * * * * * * * * * * *

main: nop

movlw 0xff ; initialisation des compteurs

movwf compt_1

movlw 0xff

movwf compt_2

movlw 0xAf

movwf compt_3

movlw 0xAf

movwf compt_4

banksel TRISB

clrf TRISB ; PORTB en sortie

banksel PORTB

movlw B'00000001' ; PORTB0 = 1

movwf PORTB

call wait ; temps d'attente (1)

movlw B'00000000' ; PORTB0 = 0

movwf PORTB

call wait ; temps d'attente (1)

movlw B'00000001' ; PORTB0 = 1

movwf PORTB

call wait ; temps d'attente (1)

movlw B'00000000' ; PORTB0 = 0

movwf PORTB

call wait2 ; temps d'attente (2)

movlw B'00000001' ; PORTB0 = 1

movwf PORTB

call wait ; temps d'attente (1)

movlw B'00000000' ; PORTB0 = 0

movwf PORTB

call wait2 ; temps d'attente (2)

goto main ; retour au début du programme

; (boucle sans fin)

END ; fin de programme

Créer une interruption sur le PORT B pour déclencher le clignotement d'une led:

; programme autorisant une interuption sur le port B

; déclenchant le clignotement d'une LED

#include <p16F84.inc>

...

Télécharger au format  txt (9.5 Kb)   pdf (119.8 Kb)   docx (13.5 Kb)  
Voir 4 pages de plus »
Uniquement disponible sur LaDissertation.com