aujourd'hui, test d' une matrice 8 x 8 leds a max7219 .. avec un 16f84
certes, cela ne casse pas 3 pattes a un canard mais au moins maintenant j' ai une base
Code : Tout sélectionner
;**********************************************************************
;
; NOM: max7219 / 16F84
; Date: 08/08/2018
; Release
; Version: 1.0
; Circuit:
; Auteur: Ducran Lapoigne
;
;**********************************************************************
;
; Fichier requis: P16F84.inc
;
;**********************************************************************
;
; Notes: affiche le contenu de data_r .... data_r + 7
; sur une matrice 8x8 à MAX7219
; data_r est la rangee superieure ; data_r + 7 la rangee inferieure
;
; ________________________ _______________
; | | | |
; |1 RA2 RA1 18 | | |
; | | | |
; |2 RA3 RAO 17 | | |
; | | | |
; |3 RA4/TOCKI OSC1 16 | | |
; | | | |
; |4 /MCLR OSC2 15 | | |
; | | | |
; |5 Vss VDD 14 | | |
; | | | |
; |6 RBO/INT RB7 13 |------------- | D_in |
; | | | |
; |7 RB1 RB6 12 |------------- | Clk |
; | | | |
; |8 RB2 RB5 11 |------------- | CS |
; | | | |
; |9 RB3 RB4 10 | | |
; |_______________________ | |_______________|
;
; PIC16F84 MAX7219
;
LIST p=16F84 ; Définition de processeur
#include <p16F84.inc> ; Définitions de variables
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
;*********************************************************************
; ASSIGNATIONS *
;*********************************************************************
OPTIONVAL EQU H'0008' ; Valeur registre option
; Résistance pull-up ON
; Pas de préscaler
;*********************************************************************
; DEFINE
;*********************************************************************
#DEFINE PAGE0 bcf STATUS,RP0
#DEFINE PAGE1 bsf STATUS,RP0
#define CLK_Pin PORTB, 6
#define DATA_Pin PORTB, 7
#define LATCH_Pin PORTB, 5
;*********************************************************************
; CONSTANTES DU MAX 7219
;*********************************************************************
MAX_Digit_0 equ 0x01
MAX_Digit_1 equ 0x02
MAX_Digit_2 equ 0x03
MAX_Digit_3 equ 0x04
MAX_Digit_4 equ 0x05
MAX_Digit_5 equ 0x06
MAX_Digit_6 equ 0x07
MAX_Digit_7 equ 0x08
MAX_decode_mode equ 0x09
MAX_Intensity equ 0x0A
MAX_Scan_Limit equ 0x0B
MAX_Shutdown equ 0x0C
MAX_display_Test equ 0x0F
;*********************************************************************
; MACRO
;*********************************************************************
;*********************************************************************
; DECLARATIONS DE VARIABLES
;*********************************************************************
CBLOCK 0x00C ; début de la zone variables
bit_counter :1 ;
nbre_lines :1 ; nombre de digit a afficher
addr_col :1 ; addresse afficheur
maxim_hi :1 ;
maxim_lo :1 ;
index :1 ;
cnt_oct :1 ; compteur octets
cmpt1 :1 ; pour timers
cmpt2 :1 ; pour timers
cmpt3 :1 ; pour timers
data_r :8 ; 8 octets pour les rangees a afficher
ENDC ; Fin de la zone
;*********************************************************************
; DEMARRAGE SUR RESET
;*********************************************************************
org 0x000 ; Adresse de départ après reset
;*********************************************************************
; INITIALISATION DES PORTS ET DES VARIABLES
;*********************************************************************
initports ; initialisation des ports du 16F84
CLRF PORTA ;
CLRF PORTB ;
PAGE1 ;page 1
MOVLW B'00000001' ;tout le port en sortie sauf b0
MOVWF TRISB ;configuration port B
MOVLW B'00011111' ;pour l' exemple
MOVWF TRISA ;configuration port A
MOVLW OPTIONVAL ;B'00000000' ;
MOVWF OPTION_REG ;configuration OPTION
PAGE0 ;page 0
CLRF PORTB ;
;---------------------------------------------------------------------
; Chargement des datas a afficher
;---------------------------------------------------------------------
call init_MAX7219 ; initialiser le max7219
debut
clrf index
next
clrf cnt_oct ; compte octets a transferer
movlw data_r ; ADRESSE de data_r
movwf FSR
bit_suiv
movf index,w
call data_table
movwf INDF
incf FSR ,f
incf index,f
incf cnt_oct,f
btfss cnt_oct ,3
goto bit_suiv
affichage
call disp_32 ; afficher
tempo
movlw D'2'
call del_100ms
movlw 0x20 ; si les 4 tables ont été explorées
xorwf index ,w ; index =0x20
btfsc STATUS,Z ;
goto debut ;
goto next ;
data_table
addwf PCL,f
retlw 0x00 ; . . . . . . . .
retlw 0x00 ; . . . . . . . .
retlw 0x00 ; . . . . . . . .
retlw 0x18 ; . . . X X . . .
retlw 0x18 ; . . . X X . . .
retlw 0x00 ; . . . . . . . .
retlw 0x00 ; . . . . . . . .
retlw 0x00 ; . . . . . . . .
retlw 0x00 ; . . . . . . . .
retlw 0x00 ; . . . . . . . .
retlw 0x3C ; . . X X X X . .
retlw 0x24 ; . . X . . X . .
retlw 0x24 ; . . X . . X . .
retlw 0x3C ; . . X X X X . .
retlw 0x00 ; . . . . . . . .
retlw 0x00 ; . . . . . . . .
retlw 0x00 ; . . . . . . . .
retlw 0x7E ; . X X X X X X .
retlw 0x42 ; . X . . . . X .
retlw 0x42 ; . X . . . . X .
retlw 0x42 ; . X . . . . X .
retlw 0x42 ; . X . . . . X .
retlw 0x7E ; . X X X X X X .
retlw 0x00 ; . . . . . . . .
retlw 0xFF ; X X X X X X X X
retlw 0x81 ; X . . . . . . X
retlw 0x81 ; X . . . . . . X
retlw 0x81 ; X . . . . . . X
retlw 0x81 ; X . . . . . . X
retlw 0x81 ; X . . . . . . X
retlw 0x81 ; X . . . . . . X
retlw 0xFF ; X X X X X X X X
;*************************************************************************
; initialisation du MAX7219
;**************************************************************************
init_MAX7219
movlw 00
movwf PORTB
;-------------------------------------------------------------------------
; shutdown: registre 0x0C du max7219
; xxxxxxx0 : arret
; xxxxxxx1 : normal operation
;-------------------------------------------------------------------------
shutdown
movlw MAX_Shutdown
movwf maxim_hi
movlw 0x01 ; turn on display
movwf maxim_lo
call disp_write
;------------------------------------------------------------------------
; decode mode registre 0x09 du max7219
; 00000000 (0x00) :pas de décodage bcd
; 00000001 (0x01) :décodage pour digit 0 pas décodage pour 7 à 1
; 00001111 (0x0F) :décodage pour digit 3-0 pas décodage pour 7 à 4
; 11111111 (0xFF) :décodage pour digit 7-0
;-------------------------------------------------------------------------
decode_mode
movlw MAX_decode_mode ; adresse registre 'Decode mode'du MAX7219
movwf maxim_hi
movlw 0x00 ; pas de decodage bcd
movwf maxim_lo
call disp_write
;-------------------------------------------------------------------------
; intensity registre 0x0A du max7219
; règle l'intensité 0x00 :min 0xFF :max
;-------------------------------------------------------------------------
intensity
movlw MAX_Intensity ; adresse registre 'Intensity 'du MAX7219
movwf maxim_hi
movlw 0x0B ; max intensity (min 01 max 0F )
movwf maxim_lo
call disp_write
;-------------------------------------------------------------------------
; scan limit registre 0x0B du max7219
; display rangee 0: 0xX0
; display rangee 0-1: 0xX1
; display rangee 0-1-2: 0xX2
; display rangee 0-1-2-3: 0xX3
; display rangee 0-1-2-3-4: 0xX4
; display rangee 0-1-2-3-4-5: 0xX5
; display rangee 0-1-2-3-4-5-6: 0xX6
; display rangee 0-1-2-3-4-5-6-7: 0xX7
;-------------------------------------------------------------------------
scan_limit
movlw MAX_Scan_Limit ; adresse registre 'scan limit 'du MAX7219
movwf maxim_hi
movlw H'07' ; 8 digits
movwf maxim_lo
call disp_write
;-------------------------------------------------------------------------
; disp test registre 0x0F du max7219
;-------------------------------------------------------------------------
disp_test
movlw MAX_display_Test ; adresse registre 'Display test'du MAX7219
movwf maxim_hi
movlw H'00' ; test
movwf maxim_lo
call disp_write
return
;*************************************************************************
; sous routine envoi de commandes ou data vers le max7219
; sous la forme d' un mot de 16 bits
; Le MSB (bit15) est envoyé le premier
;**************************************************************************
disp_write:
movlw h'00'
movwf PORTB
movlw h'08' ;
movwf bit_counter ; compteur bits
bcf STATUS ,C ; clear carry
loop_hi
rlf maxim_hi,f ;
btfss STATUS ,C
goto toggle_clock_hi
bsf DATA_Pin
toggle_clock_hi
bsf CLK_Pin ; front montant impulsion sur CLK
bcf CLK_Pin ; front descendant impulsion sur CLK
bcf DATA_Pin ; if set,reset it.
decfsz bit_counter,f
goto loop_hi
movlw h'08' ; counter
movwf bit_counter
bcf STATUS ,C ; clear carry
loop_lo
rlf maxim_lo,f
btfss STATUS ,C
goto toggle_clock_lo
bsf DATA_Pin
toggle_clock_lo
bsf CLK_Pin
bcf CLK_Pin
bcf DATA_Pin ; if set,reset it.
decfsz bit_counter,f
goto loop_lo
toggle_load
bsf LATCH_Pin
bcf LATCH_Pin
return ;
;**************************************************************************
; affiche le contenu de data_r sur la rangée 0,rangée+1,
; rangée +2..... jusque rangée +7
; rangée +7 est la rangee du fond
;**************************************************************************
disp_32
movlw data_r ; addresse de rangee 0
movwf FSR ; data-pointer
movlw h'08' ; counter : number lines to display
movwf nbre_lines ; to var 'nbre_lines'
movlw h'01' ; adresse 1ere colonne
movwf addr_col ; to var 'addr_col'
next_digit
movf addr_col,w ; addr col -> W
movwf maxim_hi ;
movf INDF,w ; data to display -> W
movwf maxim_lo ;
call disp_write ;
incf FSR,f ; pointer data suivante
incf addr_col,f ; addr col = addr col+1
decfsz nbre_lines,f ;
goto next_digit ; fini ???
return
;---------------------------------------------------------------------
; sous-routine del_500us introduit un retard de 500 us
; Elle ne retourne aucun paramètre
;---------------------------------------------------------------------
del_500us
movlw D'165' ; 1 cycle
movwf cmpt1 ; 1 cycle
del_500us_1
decfsz cmpt1,f ; 1 cycle
goto del_500us_1 ; 2 cycle
nop ; 1 cycle
return ; 2 cycle
;---------------------------------------------------------------------
; La sous-routine del_ms introduit un retard en ms
; On entre avec le nombre de boucles desire dans W
; Elle ne retourne aucun paramètre
;---------------------------------------------------------------------
del_100ms
movwf cmpt3 ; 1 cycle
movlw D'200' ; 1 cycle il faut 200x 500 uS
movwf cmpt2 ; 1 cycle
del_100ms_1
call del_500us ; 2 cycle
decfsz cmpt2 ,f
goto del_100ms_1
decfsz cmpt3 ,f
goto del_100ms_1
return
end