Explorer les Livres électroniques
Catégories
Explorer les Livres audio
Catégories
Explorer les Magazines
Catégories
Explorer les Documents
Catégories
;xxxxxx
; macro
;xxxxxx
;xxxxxxxxxxxxxxxxxxxxxxxxx
; déclaration de variables
;xxxxxxxxxxxxxxxxxxxxxxxxx
compteur_tempo52 : 1
compteur_tempo104 : 1
compteur_bit : 1
donnee : 1 ; 8 bits de données
ENDC
;xxxxxxxxxxxxxxxxxxxx
; démarrage sur reset
;xxxxxxxxxxxxxxxxxxxx
org 0x0000
goto initialisation
;xxxxxxxxxxxxxxx
; initialisation
;xxxxxxxxxxxxxxx
initialisation
bank0
clrf PORTA ; mise à 0 des sorties du port A
clrf PORTB ; mise à 0 des sorties du port B
bank1
movlw B'00011111'
movwf TRISA
; bit 0 du port A (RA0) = 1 : configuration en entrée (RX)
; bits 1 à 4 du port A (RA1 à RA4) = 1 : configuration en entrée,
par exemple
movlw B'00000001'
movwf TRISB
; bit 0 du port B (RB0) = 1 : configuration en entrée, par exemple
; bit 1 du port B (RB1) = 0 : configuration en sortie (LED segment
g de l'afficheur)
; bit 2 du port B (RB2) = 0 : configuration en sortie (LED segment
f)
; bit 3 du port B (RB3) = 0 : configuration en sortie (LED segment
e)
; bit 4 du port B (RB4) = 0 : configuration en sortie (LED segment
d)
; bit 5 du port B (RB5) = 0 : configuration en sortie (LED segment
c)
; bit 6 du port B (RB6) = 0 : configuration en sortie (LED segment
b)
; bit 7 du port B (RB7) = 0 : configuration en sortie (LED segment
a)
bank0
movlw B'11111100'
movwf PORTB ; RB1 au niveau bas (le segment g est allumé)
clrf donnee
movlw D'9'
movwf compteur_bit
movlw D'9'
movwf compteur_tempo52
movlw D'17'
movwf compteur_tempo104
goto debut_programme
;xxxxxxxxxxxxxxxxxxxxx
; programme principal
;xxxxxxxxxxxxxxxxxxxxx
debut_programme
reception
; on attend 1 période (1 période = 1/9600 = 104,17 µs)
call tempo104 ; tempo 104 µs
decf compteur_bit , f
movf compteur_bit , f
btfsc STATUS , Z
goto affichage ; compteur_bit = 0
btfsc PORTA , 0
goto RX1 ; RX = 1
; RX = 0
bcf STATUS , C ; bit Carry mis à 0
rrf donnee , f ; décalage à droite
goto reception
RX1
bsf STATUS , C ; bit Carry mis à 1
rrf donnee , f ; décalage à droite
goto reception
; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
affichage
; autre caractère
movlw B'01111110'
movwf PORTB ; RB7 au niveau bas (le segment a est allumé)
goto finaffichage
affiche0
movlw B'00000010' ; on affiche '0'
movwf PORTB ; afficheur 7 segments
(abcdefg) = (0000001)
goto finaffichage
affiche1
movlw B'10011110' ; on affiche '1'
movwf PORTB ; afficheur 7 segments
(abcdefg) = (1001111)
goto finaffichage
affiche2
movlw B'00100100' ; on affiche '2'
movwf PORTB ; afficheur 7 segments
(abcdefg) = (0010010)
goto finaffichage
affiche3
movlw B'00001100' ; on affiche '3'
movwf PORTB ; afficheur 7 segments
(abcdefg) = (0000110)
goto finaffichage
affiche4
movlw B'10011000' ; on affiche '4'
movwf PORTB ; afficheur 7 segments
(abcdefg) = (1001100)
goto finaffichage
affiche5
movlw B'01001000' ; on affiche '5'
movwf PORTB ; afficheur 7 segments
(abcdefg) = (0100100)
goto finaffichage
affiche6
movlw B'11000000' ; on affiche '6'
movwf PORTB ; afficheur 7 segments
(abcdefg) = (1100000)
goto finaffichage
affiche7
movlw B'00011110' ; on affiche '7'
movwf PORTB ; afficheur 7 segments
(abcdefg) = (0001111)
goto finaffichage
affiche8
movlw B'00000000' ; on affiche '8'
movwf PORTB ; afficheur 7 segments
(abcdefg) = (0000000)
goto finaffichage
affiche9
movlw B'00011000' ; on affiche '9'
movwf PORTB ; afficheur 7 segments
(abcdefg) = (0001100)
goto finaffichage
afficherien
movlw B'11111110' ; on affiche ' '
movwf PORTB ; afficheur 7 segments
(abcdefg) = (1111111)
goto finaffichage
finaffichage
clrf donnee
movlw D'9'
movwf compteur_bit
goto debut_programme
; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
; routine de temporisation de 52 µs (52 cycles avec un quartz 4 MHz)
tempo52
decf compteur_tempo52 , f
movf compteur_tempo52 , f
btfss STATUS , Z
goto tempo52 ; compteur_tempo52 <> 0
nop
nop
movlw D'9'
movwf compteur_tempo52
return
; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
; routine de temporisation de 104 µs (104 cycles avec un quartz 4 MHz)
tempo104
decf compteur_tempo104 , f
movf compteur_tempo104 , f
btfss STATUS , Z
goto tempo104 ; compteur_tempo104 <> 0
movlw D'17'
movwf compteur_tempo104
nop
nop
nop
nop
return
END
16f628
__config _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF &
_DATA_CP_OFF & _BOREN_OFF & _MCLRE_ON
;bits de configuration :
;code protect OFF
;watchdog timer OFF
;power up timer ON
;oscillateur HS (quartz 4 MHz)
;low voltage program OFF
;data EE read protect OFF
;brown out detect OFF
;master clear enable ON
;xxxxxx
; macro
;xxxxxx
;xxxxxxxxxxxxxxxxxxxxxxxxx
; déclaration de variables
;xxxxxxxxxxxxxxxxxxxxxxxxx
ENDC
;xxxxxxxxxxxxxxxxxxxx
; démarrage sur reset
;xxxxxxxxxxxxxxxxxxxx
org 0x0000
goto initialisation
; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
; Routine d'interruption
; 1 source d'interruption : réception (USART)
; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
movwf W_TEMP
swapf STATUS,W
movwf STATUS_TEMP ; sauvegarde du registre W puis du
registre STATUS
bank1
btfss PIE1, RCIE
goto suite
bank0
btfsc PIR1, RCIF
goto reception
suite
goto restauration
reception
bank0
movf RCREG , W ; le flag RCIF est remis à 0 par une lecture du registre
RCREG
movwf donnee ; les 8 bits de données sont transféres dans un registre
d'usage général
; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
; mise à jour afficheur 7 segments
; autre caractère
bsf PORTA,1
bsf PORTA,2
bsf PORTB,3
bsf PORTB,4
bsf PORTB,5
bsf PORTB,6
bcf PORTB,7
; le segment a est allumé
goto finaffichage
affiche0
bsf PORTA,1
bcf PORTA,2
bcf PORTB,3
bcf PORTB,4
bcf PORTB,5
bcf PORTB,6
bcf PORTB,7
; on affiche '0'
; afficheur 7 segments (abcdefg) = (0000001)
goto finaffichage
affiche1
bsf PORTA,1
bsf PORTA,2
bsf PORTB,3
bsf PORTB,4
bcf PORTB,5
bcf PORTB,6
bsf PORTB,7
; on affiche '1'
; afficheur 7 segments (abcdefg) = (1001111)
goto finaffichage
affiche2
bcf PORTA,1
bsf PORTA,2
bcf PORTB,3
bcf PORTB,4
bsf PORTB,5
bcf PORTB,6
bcf PORTB,7
; on affiche '2'
; afficheur 7 segments (abcdefg) = (0010010)
goto finaffichage
affiche3
bcf PORTA,1
bsf PORTA,2
bsf PORTB,3
bcf PORTB,4
bcf PORTB,5
bcf PORTB,6
bcf PORTB,7
; on affiche '3'
; afficheur 7 segments (abcdefg) = (0000110)
goto finaffichage
affiche4
bcf PORTA,1
bcf PORTA,2
bsf PORTB,3
bsf PORTB,4
bcf PORTB,5
bcf PORTB,6
bsf PORTB,7
; on affiche '4'
; afficheur 7 segments (abcdefg) = (1001100)
goto finaffichage
affiche5
bcf PORTA,1
bcf PORTA,2
bsf PORTB,3
bcf PORTB,4
bcf PORTB,5
bsf PORTB,6
bcf PORTB,7
; on affiche '5'
; afficheur 7 segments (abcdefg) = (0100100)
goto finaffichage
affiche6
bcf PORTA,1
bcf PORTA,2
bcf PORTB,3
bcf PORTB,4
bcf PORTB,5
bsf PORTB,6
bsf PORTB,7
; on affiche '6'
; afficheur 7 segments (abcdefg) = (1100000)
goto finaffichage
affiche7
bsf PORTA,1
bsf PORTA,2
bsf PORTB,3
bsf PORTB,4
bcf PORTB,5
bcf PORTB,6
bcf PORTB,7
; on affiche '7'
; afficheur 7 segments (abcdefg) = (0001111)
goto finaffichage
affiche8
bcf PORTA,1
bcf PORTA,2
bcf PORTB,3
bcf PORTB,4
bcf PORTB,5
bcf PORTB,6
bcf PORTB,7
; on affiche '8'
; afficheur 7 segments (abcdefg) = (0000000)
goto finaffichage
affiche9
bcf PORTA,1
bcf PORTA,2
bsf PORTB,3
bsf PORTB,4
bcf PORTB,5
bcf PORTB,6
bcf PORTB,7
; on affiche '9'
; afficheur 7 segments (abcdefg) = (0001100)
goto finaffichage
afficherien
bsf PORTA,1
bsf PORTA,2
bsf PORTB,3
bsf PORTB,4
bsf PORTB,5
bsf PORTB,6
bsf PORTB,7
; on affiche ' '
; afficheur 7 segments (abcdefg) = (1111111)
goto finaffichage
finaffichage
; xxxxxxxxxxxxxxxxxxxxxxxxxxx
; test d'une erreur d'overrun
bank0
btfss RCSTA , OERR
goto restauration
; traitement de l'erreur d'overrun
bcf RCSTA , CREN ; on efface le bit OERR
bsf RCSTA , CREN ; on relance la réception
goto restauration
restauration
retfie
;xxxxxxxxxxxxxxx
; initialisation
;xxxxxxxxxxxxxxx
initialisation
bank0
clrf PORTA ; mise à 0 des sorties du port A
clrf PORTB ; mise à 0 des sorties du port B
movlw B'00000111'
movwf CMCON ; inactivation des comparateurs
analogiques
bank1
movlw B'11111001'
movwf TRISA
; bit 0 du port A (RA0) = 1 : configuration en entrée, par exemple
; bit 1 du port A (RA1) = 0 : configuration en sortie (LED segment
g de l'afficheur)
; bit 2 du port A (RA2) = 0 : configuration en sortie (LED segment
f)
; bits 3 à 7 du port A (RA3 à RA7) = 1 : configuration en entrée,
par exemple
movlw B'00000111'
movwf TRISB
; bit 0 du port B (RB0) = 1 : configuration en entrée, par exemple
; bit 1 du port B (RB0) = 1 : configuration en entrée (RX : USART)
; bit 2 du port B (RB0) = 1 : configuration en entrée (TX : USART)
; bit 3 du port B (RB3) = 0 : configuration en sortie (LED segment
e)
; bit 4 du port B (RB4) = 0 : configuration en sortie (LED segment
d)
; bit 5 du port B (RB5) = 0 : configuration en sortie (LED segment
c)
; bit 6 du port B (RB6) = 0 : configuration en sortie (LED segment
b)
; bit 7 du port B (RB7) = 0 : configuration en sortie (LED segment
a)
movlw D'25'
movwf SPBRG ; (SPBRG) = D'25'
movlw B'00000100'
movwf TXSTA
; bit 7 (CSRC) = 0 (non utilisé : 0 par exemple)
; bit 6 (TX9) = 0 (non utilisé : 0 par exemple)
; bit 5 (TXEN) = 0 (non utilisé : 0 par exemple)
; bit 4 (SYNC) = 0 : mode asynchrone
; bit 3 = 0 (non implémenté)
; bit 2 (BRGH) = 1 : mode asynchrone haute vitesse
; bit 1 (TRMT) = 0 (non utilisé : 0 par exemple)
; bit 0 (TX9D) = 0 (non utilisé : 0 par exemple)
bank0
movlw B'10010000'
movwf RCSTA
; bit 7 (SPEN) = 1 : utilisation du port série
; bit 6 (RX9) = 0 : 8 bits de réception
; bit 5 (SREN) = 0 (non utilisé : 0 par exemple)
; bit 4 (CREN) = 1 : autorise la réception
; bit 3 (ADEN) = 0 (non utilisé : 0 par exemple)
; bit 2 (FERR) = 0 (en lecture seule)
; bit 1 (OERR) = 0 (en lecture seule)
; bit 0 (RX9D) = 0 (non utilisé : 0 par exemple)
clrf donnee
bank1
bsf PIE1 , RCIE ; autorisation de l'interruption de réception de
l'USART
bsf INTCON , PEIE ; autorisation des interruptions des périphériques
bsf INTCON, GIE ; autorisation globale des interruptions
bank0
goto debut_programme
;xxxxxxxxxxxxxxxxxxxxx
; programme principal
;xxxxxxxxxxxxxxxxxxxxx
debut_programme
END