Cov txheej txheem:
- Kauj Ruam 1: Sau Txoj Haujlwm thiab Sau Cov Ntaub Ntawv Hex, Siv Atmel Studio
- Kauj Ruam 2: Hloov Qhov Teeb Meem Me Me ntawm Micro Controller Fuse Bits
- Kauj Ruam 3: Hlawv Txoj Haujlwm Rau Hauv Kev Nco ntawm ATMega328P Microcontroller
- Kauj Ruam 4: Txheeb xyuas Microcontroller Ua Haujlwm Raws Li Cov Lus Qhia ntawm Peb Txoj Haujlwm
- Kauj Ruam 5: Xaus
Video: AVR Microcontroller Fuse Cov Khoom Kho. Tsim thiab Tshaj Tawm hauv Flash Nco ntawm Microcontroller LED Blinking Program: 5 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:27
Hauv qhov no peb yuav tsim txoj haujlwm yooj yim hauv C code thiab hlawv nws mus rau hauv lub cim xeeb ntawm lub microcontroller. Peb yuav sau peb tus kheej txoj haujlwm thiab suav ua cov ntaub ntawv hex, siv Atmel Studio raws li kev txhim kho kev koom ua ke. Peb yuav teeb tsa fuse cov khoom thiab xa cov ntaub ntawv hex rau hauv lub cim xeeb ntawm AVR ATMega328P microcontroller, siv peb tus kheej programmer thiab software AVRDUDE.
AVRDUDE - yog ib txoj haujlwm rau rub tawm thiab tso cov cim nco ntawm Atmel's AVR microcontrollers. Nws tuaj yeem ua haujlwm Flash thiab EEPROM, thiab qhov twg txhawb los ntawm cov txheej txheem txheej txheem txheej txheem, nws tuaj yeem ua haujlwm fuse thiab xauv cov khoom.
Kauj Ruam 1: Sau Txoj Haujlwm thiab Sau Cov Ntaub Ntawv Hex, Siv Atmel Studio
Yog tias koj tsis muaj Atmel Studio, koj yuav tsum rub tawm thiab teeb tsa nws:
Txoj haujlwm no yuav siv C, yog li xaiv GCC C Ua Haujlwm Qhov Kev Xaiv los ntawm daim ntawv teev npe los tsim kom muaj qhov tsis muaj pob txha ua tiav txoj haujlwm.
Tom ntej no, nws yog qhov yuav tsum tau hais kom meej lub cuab yeej twg qhov project yuav tsim rau. Txoj haujlwm no yuav tsim los rau AVR ATMega328P microcontroller.
Ntaus cov cai ntawm txoj haujlwm hauv Cheeb Tsam Tus Thawj Coj ntawm Atmel Studio. Tus Thawj Saib Xyuas Lub Hauv Paus - Lub qhov rai no yog tus kho lub ntsiab rau cov ntaub ntawv hauv qhov haujlwm tam sim no. Tus kws kho mob muaj tshuaj xyuas thiab pib ua tiav cov yam ntxwv.
1. Peb yuav tsum qhia tus neeg xa khoom ntawm qhov nrawm peb lub nti ua haujlwm li cas nws tuaj yeem suav qhov qeeb qeeb.
#ifndef F_CPU
#define F_CPU 16000000UL // qhia cov tswj hwm zaus (16 MHz AVR ATMega328P) #endif
2. Peb suav nrog cov lus hais ua ntej, uas yog qhov uas peb muab peb cov ntaub ntawv suav nrog los ntawm lwm cov ntaub ntawv, uas txhais cov kev hloov pauv thoob ntiaj teb thiab kev ua haujlwm.
#suav nrog // lub taub hau kom pab cov ntaub ntawv ntws tswj tus pin. Txhais pins, chaw nres nkoj, thiab lwm yam.
#suav nrog // lub taub hau kom pab ua haujlwm qeeb hauv qhov haujlwm
3. Tom qab kev npaj ua ntej los ua lub luag haujlwm tseem ceeb ().
int lub ntsiab (tsis muaj dab tsi) {
Lub luag haujlwm tseem ceeb () yog qhov tshwj xeeb thiab sib cais los ntawm txhua lwm txoj haujlwm. Txhua qhov program C yuav tsum muaj ib lub ntsiab lus () muaj nuj nqi. Qhov tseem ceeb () yog qhov uas AVR pib ua tiav koj cov cai thaum lub zog pib ua ntej, yog li nws yog qhov nkag ntawm qhov haujlwm.
4. Set tus pin 0 ntawm PORTB raws li tso tawm.
DDRB = 0b00000001; // Teeb PORTB1 raws li cov zis
Peb ua qhov no los ntawm kev sau tus lej binary rau Cov Ntaub Ntawv Qhia Taw Qhia B. Cov Ntaub Ntawv Qhia Txog Tus Kheej tso cai rau peb ua cov khoom ntawm kev tso npe B tawm lossis tso tawm. Sau 1 ua rau lawv tso tawm, thaum 0 yuav ua rau lawv nkag mus. Ua qhov uas peb tau txuas tus LED los ua qhov tso tawm, peb sau tus lej binary, ua tus pin 0 ntawm PORT B raws li cov zis.
5. Loop.
thaum (1) {
Cov lus no yog lub voj, feem ntau raug xa mus ua lub ntsiab lus tseem ceeb lossis cov xwm txheej. Txoj cai no yeej ib txwm muaj tseeb; yog li ntawd, nws ua ntau thiab ntau dua nyob rau hauv lub voj tsis kawg. Nws yeej tsis tso tseg li. Yog li ntawd, LED yuav ntsais muag hauv qhov tsis muaj qhov kawg, tshwj tsis yog lub hwj chim raug kaw los ntawm lub microcontroller lossis cov lej raug tshem tawm los ntawm lub khoos phis tawj nco.
6. Qhib LED txuas rau chaw nres nkoj PB0
PORTB = 0b00000001; // tig rau LED txuas rau chaw nres nkoj PB0
Kab no, muab 1 rau PB0 ntawm PortB. PORTB yog cov cuab yeej sau npe ntawm AVR nti uas muaj 8 tus pin, PB7-PB0, mus ntawm sab laug mus rau sab xis. Muab 1 rau qhov kawg muab 1 rau PB0; qhov no teeb PB0 siab uas tig nws rau. Yog li ntawd, LED txuas rau tus pin PB0 yuav qhib thiab taws teeb.
7. Ncua sij hawm
_delay_ms (1000); // tsim ncua sijhawm 1-thib ob
Cov lus no tsim kom ncua 1-thib ob, yog li ntawd LED tig thiab nyob twj ywm rau qhov tseeb 1 thib ob.
8. Kaw tag nrho B tus pin, suav nrog PB0
PORTB = 0b00000000; // Tua tawm txhua tus pin B, suav nrog PB0
Cov kab no tawm tag nrho 8 Chaw nres nkoj B pins, yog li txawm tias PB0 tawm, yog li LED tua tawm.
9. Lwm qhov qeeb
_delay_ms (1000); // tsim lwm ncua sijhawm 1-thib ob
Nws tig tawm raws nraim rau 1 thib ob, ua ntej pib lub voj rov ua dua thiab ntsib txoj kab, uas tig nws rov qab, rov ua cov txheej txheem thoob plaws. Qhov no tshwm sim tas mus li kom LED tas li ntsais muag thiab tawm.
10. Rov qab nqe lus
}
rov qab (0); // kab ntawv no yeej tsis tau mus txog}
Kab kawg ntawm peb cov cai yog xa rov qab (0) nqe lus. Txawm hais tias txoj cai no tsis tau ua tiav, vim tias muaj lub voj voos uas tsis muaj qhov xaus, rau peb cov haujlwm uas ua haujlwm ntawm lub khoos phis tawj desktop, nws yog qhov tseem ceeb rau kev ua haujlwm kom paub seb lawv tau ua tiav lossis tsis yog. Vim li ntawd, GCC, peb tus neeg sau, xav kom txhua lub ntsiab () xaus nrog tus lej rov qab. Cov lej rov qab tsis xav tau rau AVR code, uas ua haujlwm ywj pheej ntawm ib qho kev txhawb nqa kev ua haujlwm; Txawm li cas los xij, tus neeg sau ntawv yuav tsa lus ceeb toom yog tias koj tsis xaus qhov tseem ceeb nrog rov qab ().
Kauj ruam kawg yog tsim lub phiaj xwm. Nws txhais tau tias muab tso ua ke thiab thaum kawg txuas tag nrho cov ntaub ntawv cov ntaub ntawv los tsim cov ntaub ntawv ua tiav (.hex). Cov ntaub ntawv hex no tau tsim sab hauv daim nplaub tshev Debug uas yog sab hauv Qhov Project nplaub tshev. Cov ntaub ntawv hex no tau npaj los thauj mus rau hauv lub microcontroller nti.
Kauj Ruam 2: Hloov Qhov Teeb Meem Me Me ntawm Micro Controller Fuse Bits
Nws yog ib qho tseem ceeb kom nco ntsoov tias qee qhov fuse cov khoom tuaj yeem siv los xauv qee yam ntawm cov nti thiab tuaj yeem ua rau cib nws (ua rau nws siv tsis tau)
Muaj tag nrho 19 qhov khoom siv fuse uas tau siv hauv ATmega328P, thiab lawv tau muab cais ua peb qho sib txawv fuse bytes. Peb ntawm cov khoom siv fuse muaj nyob hauv "Extended Fuse Byte", yim muaj nyob hauv "Fuse High Byte," thiab yim ntxiv muaj nyob hauv "Fuse Low Byte". Kuj tseem muaj tus lej byte uas tau siv los teeb tsa cov khoom xauv.
Txhua byte yog 8 ntsis thiab txhua qhov me me yog qhov sib cais lossis tus chij. Thaum peb tham txog teeb tsa, tsis teeb tsa, programmed, tsis programmed fuses peb yeej siv binary. 1 txhais tau hais tias tsis teeb tsa, tsis programmed thiab xoom txhais tau tias teeb tsa, programmed. Thaum tsim cov fuses koj tuaj yeem siv cov cim cim binary lossis ntau dua cov cim hexadecimal.
ATmega 328P chips tau tsim hauv RC oscillator uas muaj 8 MHz zaus. Cov chips tshiab tau xa nrog cov teeb no raws li lub moos moos thiab CKDIV8 fuse nquag, ua rau muaj 1 MHz system moos. Lub sijhawm pib pib tau teeb tsa kom siab tshaj plaws thiab lub sijhawm tawm sijhawm qhib.
Tshiab ATMega 328P chips feem ntau muaj cov teeb tsa hauv qab no:
Tsawg fuse = 0x62 (0b01100010)
High fuse = 0xD9 (0b11011001)
Fuse ncua = 0xFF (0b11111111)
Peb yuav siv ATmega 328 nti nrog sab nraud 16MHz siv lead ua. Yog li ntawd, peb yuav tsum tau npaj cov khoom ntawm "Fuse Low Byte" raws li.
1. Cov khoom 3-0 tswj kev xaiv oscillator, thiab kev teeb tsa lub hauv paus ntawm 0010 yog siv qhov ntsuas ntsuas sab hauv RC oscillator, uas peb tsis xav tau. Peb xav kom lub zog siv lead ua oscillator qis los ntawm 8.0 txog 16.0 MHz, yog li cov khoom 3-1 (CKSEL [3: 1]) yuav tsum tau teeb tsa rau 111.
2. Bits 5 thiab 4 tswj lub sijhawm pib, thiab qhov teeb tsa pib ntawm 10 yog rau kev pib qeeb ntawm rau teev mus los ntawm lub zog-down thiab lub zog-txuag, ntxiv rau ncua sijhawm pib ntxiv ntawm 14 teev mus ntxiv rau 65 milliseconds los ntawm kev rov pib dua.
Txhawm rau kom muaj kev nyab xeeb rau lub zog qis oscillator siv hluav taws xob, peb xav kom ncua sijhawm ntev tshaj plaws ntawm 16, 000 teev mus los ntawm lub zog-down thiab txuag hluav taws xob, yog li SUT [1] yuav tsum tau teeb tsa rau 1, ntxiv rau kev pib qeeb ntxiv ntawm 14 moos mus ntxiv rau 65 milliseconds los ntawm kev rov pib dua, yog li SUT [0] yuav tsum tau teeb tsa rau 1. Ntxiv rau, CKSEL [0] yuav tsum tau teeb tsa rau 1.
3. Ntsis 6 tswj lub moos tso tawm rau PORTB0, uas peb tsis quav ntsej txog. Yog li, ntsis 6 tuaj yeem tso tseg rau 1.
4. Ntsis 7 tswj kev faib ua haujlwm-rau-8 thiab lub hauv paus teeb tsa ntawm 0 muaj cov haujlwm ua haujlwm, uas peb tsis xav tau. Yog li, ntsis 7 yuav tsum tau hloov pauv los ntawm 0 txog 1.
Yog li ntawd, Fuse Low Byte tshiab yuav tsum yog 11111111 uas, hauv hexadecimal notation, yog 0xFF
Txhawm rau tsim cov khoom me me ntawm "Fuse Low Byte" peb tuaj yeem siv peb tus programmer (https://www.instructables.com/id/ISP-Programmer-fo…) thiab software AVRDUDE. AVRDUDE yog kab hais kom ua kab hluav taws xob uas siv los rub tawm los ntawm thiab xa mus rau Atmel microcontrollers.
Rub tawm AVRDUDE:
Ua ntej, peb yuav tsum ntxiv piav qhia peb cov programmer rau cov ntaub ntawv teeb tsa ntawm AVRDUDE. Ntawm Windows teeb tsa cov ntaub ntawv siv tau nyob hauv tib qhov chaw raws li cov ntaub ntawv ua tiav ntawm AVRDUDE.
Yav dhau los cov ntawv hauv cov ntawv teeb tsa avrdude.conf:
# ISPProgv1
programmer id = "ISPProgv1"; desc = "serial port banging, reset = dtr sck = rts mosi = txd miso = cts"; yam = "serbb"; connection_type = txuas; rov pib dua = 4; txq = 7; mas = 3; mas = 8;;
Ua ntej pib AVRDUDE, peb yuav tsum txuas lub microcontroller rau tus programmer, raws li lub tswv yim
Qhib DOS qhov rai qhov rai.
1. Txhawm rau saib cov npe ntawm tus programmer uas avrdude tau txais kev txhawb nqa hom kev hais kom ua avrdude -c c. Yog tias txhua yam zoo, daim ntawv yuav tsum muaj tus programmer id "ISPProgv1"
2. Txhawm rau saib cov npe ntawm Atmel cov cuab yeej uas avrdude tau txais kev txhawb nqa hom hais kom ua avrdude -c ISPProgv1. Cov npe yuav tsum muaj cov cuab yeej m328p rau Atmel ATMega 328P.
Tom ntej no, ntaus avrdude -c ISPProgv1 –p m328p, cov lus txib qhia avrdude yam programmer tau siv thiab dab tsi Atmel microcontroller txuas nrog. Nws nthuav tawm ATmega328P kos npe hauv hexadecimal notation: 0x1e950f. Nws nthuav qhia qhov fuse me ntsis programming tam sim no hauv ATmega328P kuj tseem nyob hauv hexadecimal notation; Hauv qhov no, fuse bytes tau programmed rau ib lub Hoobkas tsis ua haujlwm.
Tom ntej no, ntaus avrdude -c ISPProgv1 mp m328p –U lfuse: w: 0xFF: m, Nws yog lus txib kom qhia avrdude tus programmer tau siv dab tsi thiab Atmel microcontroller txuas nrog thiab hloov Fuse Low Byte rau 0xFF.
Tam sim no lub moos teeb liab yuav tsum los ntawm lub zog qis siv lead ua oscillator.
Kauj Ruam 3: Hlawv Txoj Haujlwm Rau Hauv Kev Nco ntawm ATMega328P Microcontroller
Ua ntej tshaj, the hex file of program we made at the beginning of the instruction in to AVRDUDE directory.
Tom qab ntawd, ntaus hauv DOS qhov rai qhov hais kom ua avrdude –c ISPProgv1 –p m328p –u –U flash: w: [lub npe ntawm koj cov ntaub ntawv hex]
Cov lus txib sau cov ntawv hex rau lub microcontroller lub cim xeeb. Tam sim no, lub microcontroller ua haujlwm raws li cov lus qhia ntawm peb txoj haujlwm. Cia peb kuaj nws!
Kauj Ruam 4: Txheeb xyuas Microcontroller Ua Haujlwm Raws Li Cov Lus Qhia ntawm Peb Txoj Haujlwm
Txuas cov khoom siv raws li daim duab qhia ntawm AVR Tsaus Ntsig LED Circuit
Ua ntej, peb xav tau lub zog, zoo li txhua qhov kev ua haujlwm hauv AVR. Kwv yees li 5 volts ntawm lub zog yog txaus rau kev ua haujlwm ntawm AVR nti. Koj tuaj yeem tau txais qhov no los ntawm roj teeb lossis DC fais fab mov. Peb txuas +5V ntawm lub zog rau tus pin 7 thiab txuas tus pin 8 rau hauv av ntawm lub khob cij. Hauv nruab nrab ntawm ob tus pin, peb tso 0.1μF ceramic capacitor kom du tawm lub zog ntawm lub zog hluav taws xob kom AVR nti tau txais txoj kab hluav taws xob du.
Lub 10KΩ resistor tau siv los muab Lub Hwj Chim Rau Pib Pib (POR) rau lub cuab yeej. Thaum lub zog hloov pauv ON, qhov hluav taws xob hla lub capacitor yuav xoom yog li cov cuab yeej rov pib dua (txij li kev rov pib ua haujlwm qis), tom qab ntawd lub capacitor tsub rau VCC thiab rov pib dua yuav raug xiam oob khab.
Peb txuas qhov anode ntawm peb LED mus rau AVR tus pin PB0. Nov yog tus pin 14 ntawm ATMega328P. Txij li nws yog LED, peb xav txwv tam sim no ntws mus rau LED yog li nws tsis hlawv tawm. Qhov no yog vim li cas peb tso 330Ω resistor hauv koob nrog LED. Lub cathode ntawm LED tau txuas nrog hauv av.
16 MHz siv lead ua tau siv los muab lub moos rau Atmega328 microcontroller thiab 22pF capacitors tau siv los tswj kev ua haujlwm ntawm siv lead ua.
Cov no yog txhua qhov kev sib txuas tsim nyog los teeb lub LED. Fais fab mov.
Ok. LED yog ntsais muag nrog ncua ib pliag. Kev ua haujlwm ntawm microcontroller sib raug rau peb cov haujlwm
Kauj Ruam 5: Xaus
Pom zoo, uas yog cov txheej txheem ntev rau tsuas yog nyem lub LED, tab sis qhov tseeb yog tias koj tau ua tiav tshem tawm cov teeb meem loj: tsim lub platform kho vajtse rau kev teeb tsa AVR microcontroller, Siv Atmel Studio ua kev txhim kho kev sib koom ua ke, siv AVRDUDE ua software rau teeb tsa thiab ua haujlwm rau AVR microcontroller
Yog tias koj xav khaws cov ntaub ntawv tshiab ntawm kuv lub hauv paus microcontrollers cov haujlwm, sau npe rau kuv YouTube! Saib thiab sib qhia kuv cov vis dis aus yog txoj hauv kev los txhawb qhov kuv ua
Sau npe yuav mus rau YouTube FOG channel
Pom zoo:
Yooj Yim Lub Hwj Huam LED Tawm Tawm Tam Sim No Tus Kheej, Hloov Kho & Tshaj Tawm: 3 Cov Kauj Ruam
Yooj Yim Lub Hwj Huam LED Tawm Tawm Tus Kheej Tam Sim No, Hloov Kho & Tshaj Tawm: Cov lus qhia no yog qhov tseem ceeb rov ua dua ntawm Dan txoj kab hluav taws xob tam sim no. Nws cov ntawv yog qhov zoo heev, tau kawg, tab sis tsis muaj qee yam hauv txoj kev kom meej. Nov yog kuv qhov kev sim daws qhov ntawd. Yog tias koj nkag siab thiab tuaj yeem tsim Dan's version
Kho Ob Chav Tawm Tawm Tawm Tawm Tawm Cov Khoom Siv Hluav Taws Xob: 10 Cov Kauj Ruam (nrog Duab)
Kho Ob Chav Tawm Tawm Tawm Tawm Tawm Tawm Cov Khoom Siv Hluav Taws Xob: Nta: AC-DC Hloov pauv ob npaug tso tawm qhov hluav taws xob (Zoo-Hauv av-Tsis Zoo) Kho txoj kab zoo thiab tsis zoo Tsuas yog Ib Leeg Ib Leeg AC hloov pauv cov suab nrov (20MHz-BWL, tsis muaj thauj khoom): Ib puag ncig 1.12mVpp Tsawg suab nrov thiab cov txiaj ntsig ruaj khov (zoo tagnrho
Yuav Ua Li Cas Thiaj Li Tshaj Lij Tshaj Lij Tshaj Lij Tshaj Tawm Hauv Circuit Board: Phau Ntawv Qhia Ua tiav: 10 Kauj Ruam (nrog Duab)
Yuav Ua Li Cas Thiaj Li Tshaj Lij Tshaj Lij Tshaj Tawm Hauv Circuit Board: Phau Ntawv Qhia Tiav: Nyob zoo txhua tus, hnub no kuv yuav qhia koj yuav ua li cas thiaj ua tau PCB zoo, txhawm rau txhim kho koj cov phiaj xwm hluav taws xob. Cia peb pib
Suab Tshaj Tawm thiab Tshaj Tawm Video Siv Raspberry Pi 3.: 6 Cov Kauj Ruam
Suab Tshaj Tawm thiab Tshaj Tawm Video Siv Raspberry Pi 3.: Lub luag haujlwm tseem ceeb ntawm txoj haujlwm no yog tshaj tawm Suab rau Raspberry Pi 3 los ntawm ib qho khoom siv txuas nrog rau WiFi network ib txwm thiab tau txais cov vis dis aus los ntawm Raspberry Pi 3 mus rau ib qho khoom siv txuas nrog ib qho WiFi network ib txwm muaj
Yuav Ua Li Cas Kho Lub Rooj Tog Zaum Lub Hwj Huam Muab Tawm Tawm ntawm Cov Pc Cov Khoom Siv Hluav Taws Xob: 6 Cov Kauj Ruam (nrog Duab)
Yuav Ua Li Cas Hloov Kho Lub Rooj Tog Zaum Lub Hwj Huam Tawm ntawm Cov Pc Cov Khoom Siv Hluav Taws Xob qub: Kuv muaj lub PC qub Lub Hwj Huam Muab tso nyob ib puag ncig.Yog li kuv tau txiav txim siab los ua lub rooj zaum kho kom raug lub zog tawm ntawm nws.Peb xav tau ntau qhov sib txawv ntawm qhov hluav taws xob rau lub zog lossis txheeb xyuas cov hluav taws xob sib txawv lossis cov phiaj xwm. Yog li nws ib txwm zoo kom muaj kev kho tau