Cov txheej txheem:

Yuav ua li cas cuam tshuam MAX7219 Tsav LED Matrix 8x8 Nrog ATtiny85 Microcontroller: 7 Cov Kauj Ruam
Yuav ua li cas cuam tshuam MAX7219 Tsav LED Matrix 8x8 Nrog ATtiny85 Microcontroller: 7 Cov Kauj Ruam

Video: Yuav ua li cas cuam tshuam MAX7219 Tsav LED Matrix 8x8 Nrog ATtiny85 Microcontroller: 7 Cov Kauj Ruam

Video: Yuav ua li cas cuam tshuam MAX7219 Tsav LED Matrix 8x8 Nrog ATtiny85 Microcontroller: 7 Cov Kauj Ruam
Video: Yuav ua li cas thiaj khiav dim lub ntiajteb no 2024, Kaum ib hlis
Anonim
Yuav ua li cas cuam tshuam MAX7219 Tsav LED Matrix 8x8 Nrog ATtiny85 Microcontroller
Yuav ua li cas cuam tshuam MAX7219 Tsav LED Matrix 8x8 Nrog ATtiny85 Microcontroller

MAX7219 tus tswj hwm yog tsim los ntawm Maxim Kev Sib Koom yog kev cog lus, cov ntawv tso tawm/tso tawm ntau-cathode cov tsav tsheb uas tuaj yeem cuam tshuam microcontrollers rau 64 tus neeg LEDs, 7-ntu lej LED qhia txog li 8 tus lej, kab lus qhia, thiab lwm yam. -chip yog BCD code-B decoder, multiplex scan circuitry, ntu thiab tus lej tsav tsheb thiab 8 × 8 zoo li qub RAM uas khaws txhua tus lej.

MAX7219 cov qauv tau yooj yim heev rau siv nrog microcontrollers xws li ATtiny85, lossis, hauv peb qhov xwm txheej Tinusaur Board.

Kauj ruam 1: Kho vajtse

Kho vajtse
Kho vajtse
Kho vajtse
Kho vajtse

MAX7219 cov qauv feem ntau zoo li qhov no. Lawv muaj lub tsheb npav nkag ntawm ib sab thiab tso tsheb npav mus rau lwm qhov. Qhov no tso cai rau koj kom daisy saw 2 lossis ntau qhov qauv, piv txwv li ib qho dhau ib qho, txhawm rau tsim teeb tsa nyuaj dua.

Cov qauv uas peb tab tom siv muaj peev xwm txuas rau hauv cov saw siv 5 tus dhia me. Saib daim duab hauv qab no.

Kauj Ruam 2: Pinout thiab Cov Cim

MAX7219 module muaj 5 tus pin:

  • VCC - hwj chim (+)
  • GND-hauv av (-)
  • DIN - Cov ntaub ntawv tawm tswv yim
  • CS - Chip xaiv
  • CLK - Clock

Qhov ntawd txhais tau tias peb xav tau 3 tus pin ntawm ATtiny85 microcontroller sab los tswj tus qauv. Cov ntawd yuav yog:

  • PB0 - txuas nrog CLK
  • PB1 - txuas nrog CS
  • PB2 - txuas nrog DIN

Qhov no txaus los txuas rau MAX7219 tus qauv thiab ua haujlwm rau nws.

Kauj Ruam 3: Txoj Cai

Txoj Cai
Txoj Cai

Kev sib txuas lus nrog MAX7219 yog qhov yooj yim - nws siv cov txheej txheem sib xws uas txhais tau tias rau txhua cov ntaub ntawv me ntsis peb xa mus muaj lub moos ncig uas qhia tau tias muaj cov ntaub ntawv ntawd me ntsis.

Hauv lwm lo lus, peb xa 2 ntu sib luag rau cov khoom - ib qho rau lub moos thiab lwm qhov rau cov ntaub ntawv. Nov yog qhov software ua.

Kauj ruam 4: Software

Lub Software
Lub Software

Txoj hauv kev no MAX7219 module ua haujlwm yog qhov no:

  • Peb sau bytes rau nws daim ntawv sau npe sab hauv.
  • MAX7219 txhais cov ntaub ntawv.
  • MAX7219 tswj cov LEDs hauv matrix.

Qhov ntawd kuj txhais tau tias peb tsis tas yuav tsum tau viav vias hla kab ntawm LEDs txhua lub sijhawm txhawm rau teeb lawv - MAX7219 tus tswj hwm saib xyuas qhov ntawd. Nws kuj tseem tuaj yeem tswj qhov kev siv ntawm LEDs.

Yog li, txhawm rau siv MAX7219 cov qauv hauv txoj hauv kev yooj yim peb xav tau lub tsev qiv ntawv ua haujlwm kom ua tiav lub hom phiaj ntawd.

Ua ntej, peb xav tau qee qhov haujlwm tseem ceeb txhawm rau sau mus rau MAX7219 cov npe.

  • Sau ib byte rau MAX7219.
  • Sau ib lo lus (2 bytes) rau MAX7219.

Txoj haujlwm uas sau ib byte rau tus tswj xyuas zoo li no:

void max7219_byte (uint8_t data) {rau (uint8_t i = 8; i> = 1; i--) {PORTB & = ~ (1 << MAX7219_CLK); // Teeb CLK rau LOW yog tias (cov ntaub ntawv & 0x80) // Mask MSB ntawm cov ntaub ntawv PORTB | = (1 << MAX7219_DIN); // Teeb DIN rau HIGH lwm PORTB & = ~ (1 << MAX7219_DIN); // Teeb DIN rau LOW PORTB | = (1 << MAX7219_CLK); // Teeb CLK rau HIGH cov ntaub ntawv << = 1; // Hloov mus rau sab laug}}

Tam sim no peb tuaj yeem xa bytes mus rau MAX7219 peb tuaj yeem pib xa cov lus txib. Qhov no yog ua tiav los ntawm kev xa 2 byes - 1st rau qhov chaw nyob ntawm kev sau npe sab hauv thiab thib 2 rau cov ntaub ntawv peb xav xa.

Muaj ntau dua kaum ob ntawm kev sau npe hauv MAX7219 tus tswj.

Xa cov lus txib, lossis lo lus, yog qhov pib xa 2 bytes sib law liag. Kev ua haujlwm uas yooj yim heev.

void max7219_word (uint8_t chaw nyob, uint8_t cov ntaub ntawv) {PORTB & = ~ (1 << MAX7219_CS); // Teeb CS rau LOW max7219_byte (chaw nyob); // Xa qhov chaw nyob max7219_byte (cov ntaub ntawv); // Xa cov ntaub ntawv PORTB | = (1 << MAX7219_CS); // Teeb CS rau HIGH PORTB & = ~ (1 << MAX7219_CLK); // Teeb CLK rau LOW}

Nws yog ib qho tseem ceeb kom nco ntsoov ntawm no kab uas peb coj CS lub teeb liab rov qab mus rau HIGH - qhov no yog qhov xaus ntawm qhov ua ntu zus - qhov xwm txheej no, qhov kawg ntawm qhov hais kom ua. Cov txheej txheem zoo sib xws tau siv thaum tswj hwm ntau qhov ib qho txuas nrog hauv cov saw hlau. Qhov kauj ruam tom ntej, ua ntej peb pib qhib thiab tua lub LEDs, yog los pib lub MAX7219 maub los. Qhov no yog ua tiav los ntawm kev sau qee qhov txiaj ntsig rau qee cov npe. Txhawm rau kom yooj yim, thaum coding nws peb tuaj yeem tso qhov pib ua ntu zus hauv ib qho array.

uint8_t initseq = {0x09, 0x00, // Decode-Mode Register, 00 = No decode 0x0a, 0x01, // Intensity Register, 0x00.. 0x0f 0x0b, 0x07, // Scan-Limit Register, 0x07 to show all lines 0x0c, 0x01, // Shutdown Register, 0x01 = Normal Operation 0x0f, 0x00, // Display-Test Register, 0x00 = Normal Operation};

Peb tsuas yog xav xa 5 cov lus txib saum toj no hauv ib ntu raws li chaw nyob/cov ntaub ntawv txuas ntxiv mus.

Nov yog qhov yooj yim heev - peb tsuas yog sau ib lo lus txib qhov twg 1 byte yog qhov chaw nyob (los ntawm 0 txog 7) thiab thib ob byte yog 8 khoom sawv cev rau 8 LEDs hauv kab.

void max7219_row (uint8_t address, uint8_t data) {if (address> = 1 && address <= 8) max7219_word (address, data); }

Nws yog ib qho tseem ceeb kom nco ntsoov tias qhov no yuav ua haujlwm rau 1 matrix nkaus xwb. Yog tias peb txuas ntau cov lej hauv cov saw lawv txhua tus yuav qhia tib cov ntaub ntawv. Qhov laj thawj rau qhov no yog tias tom qab xa cov lus txib peb coj CS teeb liab rov qab mus rau HIGH uas ua rau txhua tus MAX7219 tus tswj hwm hauv cov saw los tuav thiab qhia qhov twg los xij qhov lus txib kawg.

Pom zoo: