Autres articles / Other articles

Gestion de l'afficheur MAX7219 8x8

publication: 17 juin 2022 / mis à jour 17 juin 2022

Read this page in english

 

Appel à collaboration

Vous développez des montages, simples ou complexes avec ESP32 et ESP32forth.

Partagez-les ici sur ce site.

ESP32forth ne pourra se développer qu'avec la collaboration active de toutes les bonnes volontés.

Vos montages peuvent aider d'autres développeurs.

Les montages des autres développeurs peuvent vous aider.

Pour proposer un article ou un montage, cliquez ici



\ require SPI vocabulary: 
\ link: https://esp32.arduino-forth.com/article/SPI_implementation 
\ link: https://esp32.arduino-forth.com/article/SPI_words 
 
DEFINED? --MAX7219 [if] forget --MAX7219  [then] 
create --MAX7219 
 
\ define VSPI pins 
19 constant VSPI_MISO 
23 constant VSPI_MOSI 
18 constant VSPI_SCLK 
05 constant VSPI_CS 
 
\ define SPI port frequency 
4000000 constant SPI_FREQ 
 
\ select SPI vocabulary 
only FORTH  SPI also 
 
\ initialize HSPI port 
: init.VSPI ( -- ) 
    VSPI_CS OUTPUT pinMode 
    VSPI_SCLK VSPI_MISO VSPI_MOSI VSPI_CS SPI.begin 
    SPI_FREQ SPI.setFrequency 
  ; 
 
\ CS select for MAX7219 
: MAX7219.select ( -- ) 
    VSPI_CS LOW digitalWrite 
  ; 
 
\ CS deselect for MAX7219 
: MAX7219.deselect ( -- ) 
    VSPI_CS HIGH digitalWrite 
  ; 
 
\ send two bytes to MAX7219 thru SPI port 
: MAX7219.send ( c1 c2 -- ) 
    MAX7219.select 
    swap SPI.write SPI.write 
    MAX7219.deselect 
  ; 
 
: MAX7219.normal   ( -- )  
    $0c $01 MAX7219.send  
  ; 
 
: MAX7219.shutdown ( -- )  
    $0c $00 MAX7219.send 
  ; 
 
: MAX7219.intensity  ( c -- )   
    $0a swap MAX7219.send  
  ; 
 
: MAX7219.decode     ( c -- )   
    $09 swap MAX7219.send  
  ; 
 
: MAX7219.scan.limit ( c -- )   
    $0b swap MAX7219.send  
  ; 
 
: MAX7219.set.digit  ( cbits cdigit -- )  
    swap MAX7219.send  
  ; 
 
: MAX7219.test.on  ( -- )  
    $0f $01 MAX7219.send  
  ; 
 
: MAX7219.test.off ( -- )  
    $0f $00 MAX7219.send  
  ; 
 
\ all LEDs on full, 232mA needed 
: disp-test-1 ( -- )  
    init.VSPI 
    MAX7219.test.on 
    begin key? until 
    MAX7219.test.off 
    SPI.end 
  ; 
 
\ left 4 LEDs on first row, 42mA needed 
: disp-test-2 ( -- )  
    init.VSPI 
    MAX7219.normal 
    $03 MAX7219.intensity 
    $00 MAX7219.scan.limit 
    $f0 $01 MAX7219.set.digit 
    begin key? until 
    MAX7219.shutdown 
    SPI.end 
  ; 
 
 
\ draw face, 18mA needed 
: disp-test-3 ( -- )  
    init.VSPI 
    MAX7219.normal 
    $01 MAX7219.intensity 
    $07 MAX7219.scan.limit 
    $00 MAX7219.decode 
    [ 2 base ! ] 
    00000000 $01 MAX7219.set.digit 
    01100110 $02 MAX7219.set.digit 
    00000000 $03 MAX7219.set.digit 
    00011000 $04 MAX7219.set.digit 
    00011000 $05 MAX7219.set.digit 
    10000001 $06 MAX7219.set.digit 
    01000010 $07 MAX7219.set.digit 
    00111100 $08 MAX7219.set.digit 
    [ decimal ] 
    begin key? until 
    MAX7219.shutdown 
    SPI.end 
  ; 

Legal: site web personnel sans commerce / personal site without seling