Cov txheej txheem:

Kev ntsais muag, Hu nkauj, Marioman: 5 Kauj Ruam
Kev ntsais muag, Hu nkauj, Marioman: 5 Kauj Ruam

Video: Kev ntsais muag, Hu nkauj, Marioman: 5 Kauj Ruam

Video: Kev ntsais muag, Hu nkauj, Marioman: 5 Kauj Ruam
Video: Plab Plab Ntswg..(Pluav Pluav Ntswg) Maiv Twm New Song 2023-2024 2024, Hlis ntuj nqeg
Anonim
Blinking, Hu Nkauj, Marioman
Blinking, Hu Nkauj, Marioman

Siv qhov attiny13a, ob lub LEDs thiab daim npav tos txais tus neeg hais lus kom tsim lub ntsais muag Marioman uas ua yeeb yaj kiab Super Mario Brothers ntsiab nkauj zaj nkauj. Qhov no tuaj yeem yog txoj haujlwm yooj yim-tus nqi qis rau txhua tus neeg uas tab tom nrhiav txoj hauv kev lom zem kom tawg mus rau hauv AVR txoj haujlwm! sau ntawv ntawm cov nkauj tau tsim los ntawm ib puag ncig nthwv dej tso tawm ntawm ib tus pin ntawm AVR microcontroller. Cov LEDs uas hloov pauv ntawm txhua daim ntawv tau txuas nrog 2 tus pin ntawm txhua tus tib lub nti.

Kauj Ruam 1: Cov Ntaub Ntawv thiab Kev Txhim Kho

Cov Ntaub Ntawv thiab Kev Txhim Kho
Cov Ntaub Ntawv thiab Kev Txhim Kho

1 qig 13a

www.mouser.com/Search/ProductDetail.aspx?qs=sGAEpiMZZMvu0Nwh4cA1wRKJzS2Lmyk%252bEP0e%2f7dEeq0%3dCost: $ 1.40

  • 2 LEDs - ib qho LEDs yuav ua
  • 1 lithium npib cell roj teeb

www.sparkfun.com/commerce/product_info.php?products_id=338 Tus nqi: $ 2.00

1 npib cell tuav

www.sparkfun.com/commerce/product_info.php?products_id=8822Cost: $ 1.25

1 tus neeg hais lus me me los ntawm daim npav tos txais suab paj nruag

Tag nrho tus nqi ntawm cov ntaub ntawv ~ $ 5 Ob lub LEDs tau txuas ncaj qha rau ob tus pin ntawm txhua qhov attiny13A. Ob tus pin tau siv rau txhua tus LED, tus pin thib ob tau teeb tsa qis kom siv los ua kev sib txuas hauv av. Qhov txwv tam sim no ntawm I/O pins ntawm AVR yuav tiv thaiv cov LED los ntawm kev kos ntau dhau yog li tus tiv thaiv tsis tas yuav txuas rau hauv koob. Tus neeg hais lus siv yog qhov ib txwm pom hauv daim npav tos txais suab paj nruag, txhua tus neeg hais lus me me yuav ua, muab qhov no tso tawm lub suab yoj plaub fab, nws tsis tseem ceeb heev rau kev txhawj xeeb txog kev tsav tus hais lus lossis lub suab zoo.

Kauj Ruam 2: Soldering AVR rau LEDs thiab Tus Hais Lus

Soldering AVR rau LEDs thiab Hais Lus
Soldering AVR rau LEDs thiab Hais Lus
Soldering AVR rau LEDs thiab Hais Lus
Soldering AVR rau LEDs thiab Hais Lus

Rau cov LEDs mus ncav tes zoo li caj npab ib tus pin tau khoov ntawm AVR txhua sab. Kev taw qhia AVR txoj hauv kev no ua rau nws yooj yim los txuas rau tus hais lus (duab thib ob) txij li kev sib txuas yog nyob rau ntawm ob sab hauv qab. nws yog txuas.

Kauj Ruam 3: Programming Attiny13a

Programming Attiny13a
Programming Attiny13a

Muaj ntau qhov kev xaiv sib txawv rau cov phiaj xwm AVRs rau txoj haujlwm no USBtiny tau siv uas muaj cov khoom siv los ntawm ladyada lub vev xaib https://www.ladyada.net/make/usbtinyisp/index.html Txhawm rau txuas AVR rau tus programmer koj tuaj yeem ob qho txuas cov xov hluav taws xob rau tus poj niam lub qhov (socket) thiab ntsaws lawv rau hauv lub khob cij lossis zoo dua tseem tau txais AVR cov phiaj xwm pheej yig zoo li qhov no.

Kauj Ruam 4: Tsim Firmware rau Marioman

Tsim Firmware rau Marioman
Tsim Firmware rau Marioman

Cov attiny13A muaj 1K ntawm qhov programmable flash, thiab 64bytes ntawm SRAM. Cov ntaub ntawv txuas nrog tar muaj cov ntaub ntawv nrog rau kev suav sau cov firmware rau rub tawm.

  • freq - zaus ntawm txhua daim ntawv
  • ntev - ntev ntawm txhua daim ntawv
  • ncua - ncua ntawm txhua daim ntawv

Qhov ntau zaus tsis muaj qhov ntau zaus tab sis zoo dua tus nqi tso rau hauv TTCROB sau npe los tsim lub xwmfab yoj tawm ntawm PB0 tus pin. Ntawm no yog cov ntsiab lus luv luv ntawm kev suav thiab tus pin teeb tsa rau cov xwm txheej yoj tiam:

  • Attiny13A muaj cov oscillator sab hauv teeb tsa rau 9.6MHz
  • Lub moos sab hauv rau IO yog oscillator faib los ntawm 8 lossis 1.2MHz
  • Tus timer sab hauv tau teeb tsa hauv 8 tus lej rau npe kom suav txhua lub voj voog nrog prescale ntawm 8.
  • Qhov no tshwm sim hauv ib qho zuam sib npaug rau 1 / (1.2MHz / 8) =.006667ms
  • Attiny13A tau teeb tsa los sib piv dab tsi hauv 8bit TCCR0B sau npe nrog lub sijhawm thiab hloov tus pin thaum lawv sib phim.
  • Piv txwv li, txhawm rau tsim kom muaj lub voos xwmfab ntawm 524Hz (ib lub octave saum nruab nrab C) uas muaj lub sijhawm 1.908ms.

1.908ms = 286 moos zuam (1.908/.0067) Faib 286 los ntawm 2 toggle tus pin ntawm t/2 (286/2 = 143) Muab 143 rau hauv TTCR0B sau npe los tsim daim ntawv no. Qhov no yog txhua txoj cai uas tsim nyog los teeb tsa lub sijhawm, ua qhov sib piv thiab tso tawm ib puag ncig yoj:

TCCR0A | = (1 << WGM01); // teeb tsa timer 1 rau CTC hom TCCR0A | = (1 << COM0A0); // toggle OC0A ntawm kev sib piv sib tw TCCR0B | = (1 << CS01); // clk/8 prescale TTCR0B = 143; // tsim cov xwm txheej yoj ntawm 524HzTxhawm rau ncua lub suab nrov thiab ncua ntawm lawv ib qho yooj yim ncua kev ua haujlwm tau siv

pw tsis tsaug zog (int ms) {int cnt; rau (cnt = 0; cnt <(ms); cnt ++) {int kuv = 150; thaum (i--) {_asm ("NOP"); }}}Qhov no suav los ntawm 150 qhov twg txhua lub NOP lub voj voog yog kwv yees li.006667ms. Qhov kawg qhov chaws ua yog hla ntawm cov kab, tsim cov nkauj thiab ntsais ob lub LEDs. Qhov no ua tiav txuas ntxiv rau lub voj nrog cov cai hauv qab no

const uint8_t freq PROGMEM = {… data}; const uint8_t ntev PROGMEM = {… data}; const uint8_t ncua PROGMEM = {… data};… thaum (1) {rau (cnt = 0; cnt < 156; cnt ++) {OCR0A = pgm_read_byte (& freq [cnt]); output_toggle (PORTB, PB3); output_toggle (PORTB, PB4); pw tsaug zog (pgm_read_byte (& ntev [cnt])); output_toggle (PORTB, PB3); output_toggle (PORTB, PB4); // nres timer TCCR0B = 0; pw tsaug zog (pgm_read_word (& ncua [cnt])); // pib timer TCCR0B | = (1 << CS01); // clk/8 prescale}}Muaj 156 cov ntsiab lus hauv qhov zaus/ntev/ncua arrays, lub voj no hla lawv. Pin PB3 thiab PB4 yog txhua tus toggled yog li lawv yuav hloov pauv nrog txhua qhov ceeb toom Thawj qhov pw tsaug zog yog qhov ntev ntawm daim ntawv peb ua si tom qab teeb tsa OCR0A rau tus nqi tsim nyog. Qhov kev pw tsaug zog thib ob yog ncua ntawm cov ntawv peb ua si. Hauv cov cai saum toj no koj yuav tau pom ob lub luag haujlwm pgm_read_byte () thiab pgm_read_word () ntxiv rau lo lus tseem ceeb PROGMEM. With nrog cov ntiv tes kos zoo li attiny tus nqi ntawm SRAM tsawg heev, qhov no tsuas yog 64bytes. Cov kab ntawv peb tab tom siv rau txhua qhov ntawm cov zaus/ncua/ntev cov ntaub ntawv loj dua 64bytes thiab yog li ntawd tsis tuaj yeem thauj khoom mus rau lub cim xeeb. Los ntawm kev siv qhov tshwj xeeb PROGMEM avr-gcc cov lus qhia cov ntaub ntawv loj no tau tiv thaiv los ntawm kev nkag mus rau hauv lub cim xeeb, hloov lawv tau nyeem los ntawm nyem.

Kauj Ruam 5: Tso Marioman Xoob

Cov vis dis aus saum toj no qhia Marioman hauv kev nqis tes ua. Qhov nruab nrab siv hluav taws xob yog kwv yees li 25mA yog li nws tuaj yeem ntsais thiab ua suab nrov txog li 10 teev ua ntej tso lub lithium npib ntawm tes. Qhov tsuas yog txoj hauv kev los txhawb nws rau thiab tawm yog tshem tawm cov npib ntawm cov roj teeb, qhov ruaj khov uas tau teev tseg hauv cov ntaub ntawv yog zoo haum rau qhov no. Hloov tau ntxiv tau tab sis muaj qee yam yuav tsum tau hais kom ua kom yooj yim.

Pom zoo: