Cov txheej txheem:

AVRSH: Tus Hais Lus Txhais Lus Plhaub rau Arduino/AVR: 6 Cov Kauj Ruam (nrog Duab)
AVRSH: Tus Hais Lus Txhais Lus Plhaub rau Arduino/AVR: 6 Cov Kauj Ruam (nrog Duab)

Video: AVRSH: Tus Hais Lus Txhais Lus Plhaub rau Arduino/AVR: 6 Cov Kauj Ruam (nrog Duab)

Video: AVRSH: Tus Hais Lus Txhais Lus Plhaub rau Arduino/AVR: 6 Cov Kauj Ruam (nrog Duab)
Video: Nraug txuj kev hlub 2024, Hlis ntuj nqeg
Anonim
AVRSH: Tus Hais Lus Txhais Lus Plhaub rau Arduino/AVR
AVRSH: Tus Hais Lus Txhais Lus Plhaub rau Arduino/AVR

Puas tau xav kom "nkag mus" rau koj li AVR microcontroller? Puas tau xav tias nws yuav txias rau "miv" sau npe kom pom nws cov ntsiab lus? Koj puas ib txwm xav tau txoj hauv kev kom muaj zog thiab ua kom muaj zog ib leeg cov khoom sib txuas ntawm koj li AVR lossis Arduino hauv * lub sijhawm tiag tiag *? Kuv, ib yam, yog li kuv tau sau AVR Plhaub, lub plhaub zoo li UNIX. Nws yog UNIX-zoo li nws tau nco txog lub plhaub nyiaj koj tau tawm mus thiab yuav los khiav koj li irc nick sib tsoo bots rau, ntxiv rau muaj qhov hais kom ua lossis ob qho tib si. Nws kuj tseem muaj cov ntaub ntawv txheej txheem uas zoo ib yam li UNIX extfs, siv EEPROM sab nraud, tab sis qhov ntawd tau dhau los ua ib qhov haujlwm rau nws tus kheej yog li kuv yuav tso qhov module cais raws li qhov qhia tau sib txawv thaum nws tau npaj lawm. Nov yog cov npe ntawm yam uas koj tuaj yeem ua tam sim no nrog AVR Plhaub:

  • Nyeem tag nrho koj Cov Ntaub Ntawv Qhia Txog Cov Lus Qhia (DDRn), chaw nres nkoj, thiab tus pin hauv lub sijhawm tiag
  • Sau rau tag nrho koj DDRn's, chaw nres nkoj, thiab pins kom tig rau lub cav, LED's, lossis nyeem cov cim hauv lub sijhawm tiag tiag
  • Sau tag nrho cov npe sau npe ntawm cov kab ke
  • Tsim thiab khaws cov txiaj ntsig hauv cov neeg siv txhais cov kev hloov pauv los ntawm EEPROM.
  • Tsim lub hauv paus lo lus zais thiab txheeb xyuas qhov tseeb rau nws (siv rau kev nkag mus rau telnet)
  • Nyeem qhov teeb tsa CPU moos ceev
  • Hloov koj li CPU moos nrawm los ntawm kev teeb tsa prescaler
  • Pib thiab nres 16-ntsis timers rau lub sijhawm ntawm ntau yam
  • Fais fab thiab/lossis lub zog qis dua ib puag ncig cov kab ke: Analog rau Digital Converters (ADC), Serial Peripheral Interface (SPI), Ob txoj kab sib txuas (TWI/I2C), UART/USART. Pab tau rau thaum koj xav txo hwj chim siv lub microcontroller lossis kom pab tau qee yam haujlwm.
  • Sau hauv C ++ nrog cov khoom siv tau.

Cov lus qhia no yuav taug kev los ntawm kev teeb tsa, siv, thiab kev hloov kho avrsh.

Kauj ruam 1: Yam Koj Yuav Tsum Tau

Yam Koj Yuav Tsum Tau
Yam Koj Yuav Tsum Tau

Cov lus qhia no tsis xav tau ntau tshwj tsis yog koj:

  • Muaj Arduino lossis ATmega328P. Lwm qhov AVR tuaj yeem ua haujlwm, tab sis koj yuav tsum tau hloov kho txoj cai kom teev ib qho kev sau npe tshwj xeeb rau koj li MCU. Cov npe tsuas yog xav tau kom phim qhov uas tau teev tseg hauv kab ntawv header tshwj xeeb rau koj li MCU. Coob leej ntawm cov npe sau npe zoo ib yam ntawm AVRs, yog li koj qhov kev ncua yuav txawv thaum thauj khoom.
  • Muaj txoj hauv kev los txuas rau USART cov lej ntawm koj Arduino/AVR. Lub kaw lus tau raug tshuaj xyuas ntau tshaj nrog AVR Terminal, lub Windows app uas ua rau muaj kev sib txuas ntawm koj lub USB lossis COM chaw nres nkoj. Ua haujlwm nrog Arduinos siv USB txuas thiab ib qho AVR siv USB-BUB los ntawm Moderndevice.com. Lwm qhov kev xaiv dav dav suav nrog: Putty, minicom (Linux thiab FreeBSD), tshuaj ntsuam (Linux/FreeBSD), Hyperterminal, Teraterm. Kuv tau pom putty thiab teraterm xa qee cov thoob khib nyiab thaum txuas mus yog li koj thawj cov lus txib yuav tsis quav ntsej.
  • Muaj AVR Plhaub firmware nruab thiab khiav, uas koj tuaj yeem rub tawm los ntawm cov nplooj ntawv no, lossis ib txwm tau txais qhov hloov tshiab kawg ntawm BattleDroids.net.

Txhawm rau nruab AVR Terminal, tsuas yog unpack nws thiab khiav nws. Txhawm rau nruab AVR Plhaub firmware, rub nws thiab ncaj qha upload cov ntaub ntawv hex thiab txuas koj lub davhlau ya nyob twg ntawm 9600 baud, lossis suav nws tus kheej nrog "ua" thiab tom qab ntawd "ua haujlwm" txhawm rau upload hex. Nco tseg, koj yuav xav hloov AVRDUDE teeb tsa los cuam tshuam koj qhov chaw nres nkoj COM. Nco tseg: Tus cwj pwm PROGMEM tau tawg hauv qhov tam sim no AVR GCC siv rau C ++ thiab qhov no yog kab laum paub. Yog tias koj suav nws, cia siab tias yuav tau txais ntau cov lus ceeb toom hais tias "ceeb toom: tsuas yog pib qhov hloov pauv tuaj yeem tso rau hauv qhov chaw nco." Dhau li ua rau tsis txaus ntseeg pom, qhov lus ceeb toom no tsis muaj kev phom sij. Raws li C ++ ntawm lub platform kos tsis siab nyob rau hauv AVR GCC cov npe ua ntej, nws tsis paub thaum twg qhov no yuav raug kho. Yog tias koj txheeb xyuas cov cai, koj yuav pom qhov twg kuv tau ua haujlwm nyob ib puag ncig kom txo cov lus ceeb toom no los ntawm kev ua raws li kuv tus kheej cov lus hais tseg. Zoo nkauj yooj yim. Rub tawm thiab teeb tsa ib yam dab tsi uas koj yuav xav tau tom qab tig lub nplooj ntawv thiab cia tau crackin '.

Kauj ruam 2: Nyeem thiab Sau Npe Sau Npe

Nyeem thiab Sau Sau Npe
Nyeem thiab Sau Sau Npe

AVR Plhaub tau sau ua ntej kom nkag tau qee qhov ntsuas uas kuv tau txuas nrog kuv AVR. Nws pib nrog qhov yooj yim LED tom qab ntawd txav mus rau lub teeb pom kev zoo, ntsuas kub, thiab thaum kawg mus rau ob lub tshuab ntsuas ultrasonic. avrsh tuaj yeem teeb tsa cov khoom siv digital ntawm cov ntsuas no los ntawm kev sau ntawv rau npe uas tswj hwm lawv. Kev tswj hwm AVR cov npe thaum khiav Yuav kom tau txais cov npe ntawm txhua tus paub sau npe ntawm koj Arduino, ntaus:

sau npe sau npe thiab koj yuav tau txais cov ntawv luam tawm zoo li qhov no

Kuv paub txog cov npe hauv qab no:

TIFR0 PORTC TIFR1 PORTD TIFR2 DDRD PCIFR DDRB EIFR DDRC EIMSK PINB EECR PINC EEDR PIND SREG EEARL GPIOR0 EEARH GPIOR1 GTCCR GPIOR2 TCCR0A TCCR0B TCNT0 OCR0A OCR0B SPCR SPDR ACSR SMCR MCUSR MCUCR SPMCSR WDTCSR CLKPR PRR OSCCAL PCICR EICRA PCMSK0 PCMSK1 TIMSK0 TIMSK1 TIMSK2 ADCL ADCH ADCSRA ADCSRB ADMUX DIDR0 DIDR1 TCCR1A TCCR1B TCCR1C TCNT1L TCNT1H ICR1L ICR1H OCR1AL OCR1AH OCR1BL OCR1BH TCCR2A TCCR2B TCNT2 OCR2A OCR2B ASSR TWBR TWB0 TWR0 TWR TWR UR0 TWR TWR TWS UT0 TWR TWS UT0 TWR TWR TWS UC0 TWR TWR TWS UC0 TWR TWR TWR TWS TWR TWR TWS TWR TWS Txhawm rau pom yuav ua li cas tus kheej cov khoom tau teeb tsa hauv ib qho kev sau npe, siv miv lossis echo hais kom ua

miv %GPIOR0 Ntawm no kuv nug tus kws txhais lus kom pom, lossis ncha, cov ntsiab lus ntawm Lub Hom Phiaj General I/O Sau npe #0. Nco tseg qhov feem pua kos npe (%) nyob rau hauv ntej ntawm lub npe sau npe. Koj xav tau qhov no los qhia rau lub plhaub tias qhov no yog cov ntsiab lus tshwj tseg qhia txog kev sau npe. Qhov raug tso tawm los ntawm kev hais lus ncha zoo li qhov no

GPIOR0 (0x0) teeb tsa rau [00000000] Cov zis tso tawm qhia lub npe ntawm tus lej sau npe, tus lej hexadecimal pom hauv tus lej sau npe thiab tus lej binary sawv cev ntawm kev sau npe (qhia txhua qhov me me li 1 lossis 0). Txhawm rau teeb tsa tshwj xeeb me ntsis hauv ib qho kev tso npe, siv "index of" operator . Piv txwv li, cia peb hais tias kuv xav tau qhov thib 3 rau 1

%GPIOR0 [3] = 1 thiab lub plhaub yuav muab lus teb rau koj qhia tias nws ua thiab qhov tshwm sim

GPIOR0 (0x0) teeb tsa rau [00000000] (0x8) teeb tsa rau [00001000] Tsis txhob hnov qab qhov feem pua kos npe los qhia lub plhaub uas koj tab tom ua haujlwm nrog rau npe. Tsis tas li nco ntsoov tias los ntawm kev teeb tsa tus thib 3, uas yog 4 qhov khoom vim tias peb AVR siv qhov ntsuas xoom. Hauv lwm lo lus, suav rau tus thib 3 koj suav 0, 1, 2, 3, uas yog tus thib plaub, tab sis tus thib 3. Koj tuaj yeem tshem me ntsis hauv tib txoj kev los ntawm kev teeb tsa me ntsis rau xoom. Los ntawm teeb tsa cov khoom zoo li no koj tuaj yeem hloov pauv kev ua haujlwm ntawm koj AVR ntawm qhov yoov. Piv txwv li, los ntawm kev hloov CTC lub sijhawm sib tw tus nqi pom hauv OCR1A. Nws tseem tso cai rau koj saib mus rau qhov chaw tshwj xeeb uas koj yuav tsum tau tshuaj xyuas hauv koj li kev cai, xws li UBBR tus nqi rau koj tus nqi baud. Ua haujlwm nrog DDRn, PORTn, thiab PINn Cov I/O pins kuj tseem raug tso npe rau npe thiab tuaj yeem teeb tsa tib yam nkaus, tab sis tau tsim cov syntax tshwj xeeb los ua haujlwm nrog cov npe no. Hauv txoj cai, muaj txheej txheem ib txwm rau, hais, tig lub LED lossis lwm yam cuab yeej uas xav tau digital siab lossis qis. Nws yuav tsum teeb tsa Cov Ntawv Qhia Taw Qhia kom qhia tus pin yog rau cov zis, thiab tom qab ntawv sau 1 lossis 0 rau qhov tshwj xeeb me ntsis hauv qhov chaw nres nkoj raug. Piv txwv tias peb muaj LED txuas nrog tus lej digital 13 (PB5) thiab peb xav qhib nws, ntawm no yog yuav ua li cas thaum koj AVR tab tom khiav

teeb tus pin pb5 outputwrite tus pin pb5 siab Cov zis, dua li tuaj yeem pom koj li LED tuaj, yuav zoo li qhov no

hauv paus@ATmega328p> teeb tus pin pb5 tso tawm Teeb pb5 rau outputroot@ATmega328p> sau tus pin pb5 siab "Hauv paus@ATmega328p>" yog lub plhaub tam sim uas qhia tias nws tau npaj txhij los txais cov lus txib los ntawm koj. Txhawm rau tua LED, koj tsuas yog sau qis rau tus pin. Yog tias koj xav nyeem cov ntawv digital los ntawm tus pin, siv qhov hais kom ua nyeem. Siv peb qhov piv txwv saum toj no

hauv paus@ATmega328p> nyeem tus pin pb5Pin: pb5 yog HIGH Xwb, tsuas yog ncha tus lej npe uas tswj hwm tus pin chaw nres nkoj. Piv txwv li, yog tias peb muaj cov hloov pauv txuas nrog tus lej digital 7 thiab 8 (PD7 thiab PD8), koj tuaj yeem xa cov lus txib

ncha %PIND thiab lub plhaub yuav tso tawm cov ntsiab lus ntawm kev tso npe ntawd, qhia koj txhua qhov kev nkag/tawm lub xeev ntawm cov khoom siv sib txuas thiab seb lub xeev hloov pauv los yog tawm.

Kauj Ruam 3: Nyeem thiab Sau Fuses

Nyeem thiab Sau Fuses
Nyeem thiab Sau Fuses

Fuses yog hom tshwj xeeb ntawm kev sau npe. Lawv tswj txhua yam los ntawm lub moos nrawm ntawm koj lub microcontroller mus rau yam txheej txheem txheej txheem twg muaj los sau-tiv thaiv EEPROM. Qee lub sij hawm koj yuav tsum tau hloov cov chaw no, tshwj xeeb tshaj yog tias koj tab tom tsim lub kaw lus AVR ib leeg. Kuv tsis paub tseeb tias koj yuav tsum hloov koj cov fuse teeb tsa ntawm Arduino. Ceev faj nrog koj cov fuses; Koj tuaj yeem kaw koj tus kheej yog tias koj teeb tsa lawv tsis raug. Ntawm no, Kuv yuav qhia koj yuav ua li cas rov nyeem koj cov fuses ntawm lub sijhawm ua haujlwm kom pom tias koj li MCU tau teeb tsa lawv li cas tiag. Nco tseg, qhov no tsis yog lub sijhawm teev tseg uas koj tau txais los ntawm cov lus txhais hauv tab sis qhov tseeb fuses raws li MCU nyeem lawv thaum lub sijhawm khiav. Los ntawm Rooj 27-9 hauv ATmega328P cov ntawv (cov ntaub ntawv khaws cia, ntau dua li nws) cov khoom ntawm Fuse Low Byte muaj raws li hauv qab no:

CKDIV8 CKOUT SUT1 SUT0 CKSEL3 CKSEL2 CKSEL1 CKSEL0Ib qho txaus nyiam kom nco ntsoov yog tias nrog fuses, 0 txhais tau tias yog programmed thiab 1 txhais tau tias qhov tshwj xeeb me ntsis tsis tau npaj tseg. Me ntsis counter-intuitive, tab sis thaum koj paub nws koj paub nws.

  • CKDIV8 teeb tsa koj lub moos CPU los sib faib los ntawm 8. Lub ATmega328P los ntawm lub Hoobkas programmed los siv nws cov oscillator sab hauv ntawm 8MHz nrog CKDIV8 programmed (piv txwv li teem rau 0) muab koj zaum kawg F_CPU lossis CPU zaus ntawm 1MHz. Ntawm Arduino's, qhov no tau hloov pauv txij li lawv tau teeb tsa los siv cov oscillator sab nraud ntawm 16MHz.
  • CKOUT thaum programmed yuav tso koj lub moos CPU ntawm PB0, uas yog tus lej digital 8 ntawm Arduinos.
  • SUT [1..0] qhia lub sijhawm pib rau koj li AVR.
  • CKSEL [3..0] teeb tsa lub moos qhov chaw, xws li sab hauv RC oscillator, sab nraud oscillator, thiab lwm yam.

Thaum koj nyeem koj cov fuses, nws yuav xa rov qab rau koj hauv hexadecimal. Nov yog hom ntawv uas koj xav tau yog tias koj xav sau cov fuses ntawm avrdude. Ntawm kuv arduino, ntawm no yog qhov kuv tau txais thaum kuv nyeem qis fuse byte:

hauv paus@ATmega328p> nyeem lfuseLower Fuse: 0xffYog li, txhua qhov khoom tau teeb tsa rau 1. Kuv tau ua tib cov txheej txheem ntawm Arduino clone thiab tau txais tus nqi zoo ib yam. Txheeb xyuas ib qho ntawm kuv tus kheej AVR cov kab ke, Kuv tau txais 0xDA uas yog tus nqi uas kuv tau teeb tsa qee lub sijhawm rov qab thaum teeb tsa lub nti. Qhov txheej txheem tib yam yog siv rau kev tshuaj xyuas High Fuse Byte, Extended Fuse Byte, thiab Lock fuses. Kev ntsuas ntsuas thiab kos npe fuse bytes tau raug xiam oob qhab hauv cov cai nrog #if 0 cov txheej txheem ua ntej, uas koj tuaj yeem hloov pauv yog tias koj xav tias tsis zoo.

Kauj Ruam 4: Lwm Cov Lus txib

Lwm Cov Lus txib
Lwm Cov Lus txib

Muaj ntau ntau lwm cov lus txib uas tus txhais lus hais ua ntej nkag siab tias koj yuav pom muaj txiaj ntsig. Koj tuaj yeem pom txhua qhov kev siv thiab yav tom ntej-tso lus txib los ntawm kev muab kev pab lossis ntawv qhia zaub mov ntawm qhov hais kom sai. Kuv yuav npog lawv sai sai no vim lawv feem ntau piav qhia tus kheej. CPU Clock Frequency Settings Koj tuaj yeem tshawb pom dab tsi koj lub khoos phis tawj tau teeb tsa los siv ua CPU moos teeb tsa nrog fcpu hais kom ua:

hauv paus@ATmega328p> fcpuCPU Freq: 16000000Qhov ntawd yog 16 lab, lossis 16 lab herz, feem ntau hu ua 16 MHz. Koj tuaj yeem hloov qhov no ntawm yoov, vim li cas los xij, nrog lub moos hais kom ua. Cov lus txib no siv ib qho kev sib cav: tus kws qhia noj zaub mov siv thaum faib koj lub moos nrawm. Lub moos hais kom nkag siab txog cov txiaj ntsig prescaler:

  • ckdiv 2
  • ckdiv 4
  • ckdiv 8
  • ckdiv 16
  • ckwv 32
  • ckdiv 64
  • ckdiv128
  • cwj 256

Siv cov lus txib:

xov ckdiv2 thaum koj lub cpu nrawm yog 16MHz yuav ua rau koj lub moos hloov pauv mus rau 8MHz. Siv prescaler ntawm ckdiv64 nrog lub moos moos ceev ntawm 16MHz yuav ua rau lub moos kawg ntawm 250 KHz. Vim li cas hauv Ntiaj Teb koj xav ua kom koj MCU qeeb? Zoo, rau ib qho, lub moos qis dua siv hluav taws xob tsawg dua thiab yog tias koj muaj koj lub MCU khiav tawm ntawm lub roj teeb hauv ib qhov chaw ntim khoom koj yuav tsis xav tau nws kom khiav ntawm qhov nrawm tshaj plaws, thiab yog li ntawd tuaj yeem txo qhov nrawm thiab txo nws lub zog siv., nce roj teeb lub neej. Tsis tas li, yog tias koj siv lub moos rau txhua qhov teeb meem ntawm lub sijhawm nrog lwm MCU, hais tias, siv software UART lossis qee yam zoo li no, koj yuav xav teeb tsa nws rau tus nqi tshwj xeeb uas yooj yim kom tau txais qhov zoo txawm tias baud tus nqi qis tus nqi yuam kev Ua Kom Lub Hwj Huam Muaj zog thiab Ua Kom Muaj Hluav Taws Xob Hauv Ib Sab Hauv Cov Lus Cim ib yam li txo qis kev siv hluav taws xob tau hais ua ntej, koj yuav xav txo qis zog ntxiv los ntawm kev kaw qee qhov ntawm cov khoom siv sab hauv uas koj tsis siv. Tus neeg txhais lus hais kom ua thiab lub plhaub tam sim no tuaj yeem ua kom muaj zog thiab txo qis cov khoom siv hauv qab no:

  • Analog-rau-Digital Converter (ADC). Cov khoom siv sab nraud no tau siv thaum koj muaj lub ntsuas hluav taws xob sib piv muab cov ntaub ntawv (zoo li kub, lub teeb, nrawm dua, thiab lwm yam) thiab xav hloov nws mus rau tus nqi digital.
  • Serial Peripheral Interface (SPI). Lub tsheb npav SPI tau siv los sib txuas lus nrog lwm yam khoom siv SPI, zoo li kev nco sab nraud, cov tsav tsheb LED, sab nraud ADC's, thiab lwm yam. SPI tau siv rau ISP cov phiaj xwm, lossis tsawg kawg yog tus pin, yog li ceev faj thaum kaw qhov no. yog tias koj tab tom ua haujlwm ntawm ISP.
  • Ob-Hlau Interface. Qee lub cuab yeej sab nraud siv I2C lub tsheb npav los sib txuas lus, txawm hais tias cov no tau hloov pauv sai sai los ntawm SPI-cov cuab yeej siv tau raws li SPI muaj qhov nkag mus ntau dua.
  • USART. Nov yog koj li kev sib txuas. Tej zaum koj yuav tsis xav muab qhov no tshem tawm yog tias koj txuas nrog AVR ntawm qhov txuas txuas nrog! Txawm li cas los xij, Kuv tau ntxiv qhov no nyob ntawm no ua lub cev pob txha rau kev xa mus rau cov khoom siv uas muaj ntau yam USART zoo li ATmega162 lossis ATmega644P.
  • tag nrho. Qhov kev sib cav no rau lub hwj chim lossis lub zog hais kom ua tig rau txhua yam ntawm cov khoom siv hais los lossis tig lawv tag nrho nrog ib qho lus txib. Ib zaug ntxiv, siv cov lus txib no kom ntse.

hauv paus@ATmega328p> powerdown twiPowerdown ntawm twi complete.root@ATmega328p> powerup twiPowerup ntawm twi tiav

Pib thiab Nres Timers Lub plhaub muaj lub built-in 16-ntsis timer uas muaj rau siv. Koj pib lub timer nrog timer hais kom ua:

timer pibthiab nres lub sijhawm nrog qhov kev sib cav nres

timer nresLub sijhawm ntsuas no yuav tsis cuam tshuam nrog lub sijhawm USART sab hauv. Saib cov cai rau kev siv cov ntsiab lus ntawm USART lub sijhawm, yog tias qhov kev xav paub meej txog qhov koj nyiam

hauv paus@ATmega328p> timer startStarted timer.root@ATmega328p> timer nres Sijhawm dhau los: ~ 157 vib nas this Kev lees paub tseeb Lub plhaub tuaj yeem khaws tus lej 8 tus cim rau hauv EEPROM. Tus txheej txheem lo lus zais no tau tsim los txhawb nqa lub peev xwm nkag mus hauv telnet, tab sis tuaj yeem nthuav dav los tiv thaiv lwm yam. Piv txwv li, koj tuaj yeem xav tau qee cov lus txib, xws li hloov pauv tus lej muaj txiaj ntsig, los ntawm kev txheeb xyuas qhov tseeb. Qhov tus lej nrog tus password hais kom ua

hauv paus@ATmega328p> passwd blah Sau cov lus zais hauv paus rau EEPROMTso cai tawm tsam nws tus password (lossis xav tau kev tso cai ua haujlwm dhau los ntawm tus lej) nrog daim ntawv lees paub. Nco tseg, tias yog koj sim hloov tus lej nkag hauv paus thiab twb tau tsim lub hauv paus tus lej nkag, koj yuav tsum tso cai koj tus kheej tiv thaiv tus lej qub ua ntej tso cai hloov nws mus rau tus lej tshiab

hauv paus@ATmega328p> passwd blinkyKoj yuav tsum tso cai rau koj tus kheej ua ntej.root@ATmega328p> auth blahAuthorized.root@ATmega328p> passwd blinkyTau kawg, koj yuav tsum tau thauj cov ntaub ntawv avrsh.eep yog tias koj lwv cov firmware kom muaj koj li qub qhov tseem ceeb thiab hloov pauv. Makefile yuav tsim cov ntaub ntawv EEPROM rau koj. Variables Cov plhaub nkag siab qhov kev xav ntawm cov neeg siv txhais cov ntsiab lus. Txoj cai txwv qhov no rau 20, tab sis koj tuaj yeem hloov qhov ntawd yog tias koj nyiam los ntawm kev hloov pauv txhais MAX_VARIABLES hauv script.h. Koj tuaj yeem txuag ib qho 16-ntsis tus nqi (uas yog, tus lej txog 65, 536) rau qhov sib txawv kom rov nco tau tom qab. Cov syntax zoo ib yam rau kev sau npe tshwj tsis yog kos npe daus ($) yog siv los qhia qhov txawv txav rau lub plhaub. Sau tag nrho koj cov kev hloov pauv nrog cov ntawv hloov pauv hais kom ua

Cov cim siv tus lej txhais: Cov Npe Index -> Tus Nqi (01): $ DAWB $ -> 0 (02): $ DAWB $ -> 0 (03): $ DAWB $ -> 0 (04): $ DAWB $ -> 0 (05): $ DAWB $ -> 0 (06): $ DAWB $ -> 0 (07): $ DAWB $ -> 0 (08): $ DAWB $ -> 0 (09): $ DAWB $ -> 0 (10): $ DAWB $ -> 0 (11): $ DAWB $ -> 0 (12): $ DAWB $ -> 0 (13): $ DAWB $ -> 0 (14): $ DAWB $ -> 0 (15): $ DAWB $ -> 0 (16): $ DAWB $ -> 0 (17): $ DAWB $ -> 0 (18): $ DAWB $ -> 0 (19): $ DAWB $ -> 0 (20): $ DAWB $ -> 0 Ua tiav. Teeb ib qho txawv txav

$ newvar = 25 $ sijhawm siv = 23245Tau txais tus nqi ntawm qhov muab sib txawv

hauv paus@ATmega328p> ncha $ newvar $ newvar 25Koj tuaj yeem pom dab tsi txhua qhov kev hloov pauv uas koj tau tam sim tam sim no nrog cov ntawv hais kom ua uas koj twb paub lawm

Tus neeg siv cov ntsiab lus hloov pauv: Index Name -> Value (01): newvar -> 25 (02): timeout -> 23245 (03): $ FREE $ -> 0 (04): $ FREE $ -> 0 (05): $ DAWB $ -> 0 (06): $ DAWB $ -> 0 (07): $ DAWB $ -> 0 (08): $ DAWB $ -> 0 (09): $ DAWB $ -> 0 (10): $ DAWB $ -> 0 (11): $ DAWB $ -> 0 (12): $ DAWB $ -> 0 (13): $ DAWB $ -> 0 (14): $ DAWB $ -> 0 (15): $ DAWB $ -> 0 (16): $ DAWB $ -> 0 (17): $ DAWB $ -> 0 (18): $ DAWB $ -> 0 (19): $ DAWB $ -> 0 (20): $ DAWB $ -> 0 Ua tiav.$ DAWB $ lub npe tsuas yog qhia tias qhov chaw sib txawv tsis pub dawb thiab tseem tsis tau muab lub npe hloov pauv tseem.

Kauj Ruam 5: Kho lub Plhaub

Customizing Plhaub
Customizing Plhaub

Koj muaj kev ywj pheej rau hack ntawm tus lej thiab hloov kho nws rau koj tus kheej xav tau, yog tias koj nyiam. Yog tias kuv tau paub tias kuv yuav tso tsab cai no, kuv yuav tau cais cais cov neeg txhais lus hauv chav kawm thiab cov qauv hais kom ua thiab tsuas yog rov ua qhov no los ntawm kev hu xov tooj ua haujlwm. Nws yuav txo tus nqi ntawm cov cai, tab sis raws li nws sawv cev lub plhaub parses kab hais kom ua thiab hu rau cov txheej txheem tsim nyog. Txhawm rau ntxiv rau hauv koj tus kheej cov lus txib, ua cov hauv qab no: 1. Ntxiv koj cov lus txib rau cov npe parse Cov lus txib parser yuav cais cov kab hais kom ua thiab muab koj cov lus txib thiab ib qho kev sib cav sib cais. Cov lus sib cav tau dhau los ua tus taw qhia rau tus taw qhia, lossis kab ntawv taw qhia, txawm li cas los xij koj nyiam ua haujlwm nrog lawv. Qhov no tau pom hauv shell.cpp. Qhib shell.cpp thiab nrhiav ExecCmd txoj kev ntawm chav AVRShell. Koj tuaj yeem xav ntxiv cov lus txib rau lub cim xeeb program. Yog tias koj ua, ntxiv cov lus txib hauv progmem.h thiab progmem.cpp. Koj tuaj yeem ntxiv cov lus txib rau kev ua haujlwm nco ncaj qha siv PSTR () macro, tab sis koj yuav tsim lwm qhov ceeb toom ntawm hom uas tau hais ua ntej. Ib zaug ntxiv, qhov no yog kab paub paub ua haujlwm nrog C ++, tab sis koj tuaj yeem nyob ib puag ncig qhov no los ntawm kev ntxiv cov lus txib ncaj qha rau hauv qhov kev kawm.* Cov ntaub ntawv, raws li kuv tau ua tiav. Yog tias koj tsis mloog ntxiv rau koj qhov kev siv SRAM, koj tuaj yeem ntxiv cov lus txib raws li kuv tau piav qhia nrog "moos" hais kom ua. Hais tias koj xav ntxiv cov lus txib tshiab hu ua "newcmd." Mus rau AVRShell:: ExecCmd thiab nrhiav qhov chaw yooj yim rau ntxig cov cai hauv qab no:

lwm tus yog (! strcmp (c, "newcmd")) cmdNewCmd (args);Qhov no yuav ntxiv koj cov lus txib thiab hu rau cmdNewCmd txoj kev uas koj yuav sau hauv cov kauj ruam tom ntej. 2. Sau koj cov cai hais kom ua Nyob hauv tib cov ntawv, ntxiv koj cov cai hais kom ua. Nov yog txheej txheem txhais. Koj tseem yuav xav ntxiv qhov tshaj tawm rau shell.h. Tsuas yog ntxiv nws rau lwm cov lus txib. Hauv qhov piv txwv dhau los, cov cai yuav zoo ib yam li qhov no

voidAVRShell:: cmdNewCmd (char ** args) {sprintf_P (buff, PSTR ("Koj cov lus txib yog %s / r / n", args [0]); WriteRAM (buff);}Muaj ntau yam nyob ntawm no. Ua ntej, "buff" yog 40-character array array buffer muab hauv cov cai rau koj siv. Peb siv qhov kev nco nco ntawm sprintf txij li peb tau hla nws PSTR. Koj tuaj yeem siv qhov qub yog tias koj nyiam, tab sis xyuas kom koj tsis hla cov hom ntawv hauv PSTR. Tsis tas li, cov lus sib cav yog nyob hauv args array. Yog tias koj ntaus "newcmd arg1 arg2" koj tuaj yeem tau txais ntawm cov lus sib cav nrog cov args [0] thiab args [1] cov ntawv sau npe. Koj tuaj yeem hla qhov siab tshaj ntawm MAX_ARGS cov lus sib cav, raws li tau hais tseg hauv txoj cai. Xav tias yuav hloov pauv tus nqi ntawd thaum koj rov sau dua yog tias koj xav tau ntau qhov kev sib cav kom dhau mus ib zaug. Lub WriteLine thiab WriteRAM yog lub luag haujlwm thoob ntiaj teb uas xa rov qab UART txoj hauv kev tib lub npe. Qhov kev sib cav zaum thib 2 rau txoj haujlwm no muaj feem cuam tshuam. Yog tias koj hla tsis muaj dab tsi, cov lus txib yuav sau tom qab. Yog tias koj hla 0 raws li qhov kev sib cav zaum 2, yuav tsis sau ntawv sai. Qhov no muaj txiaj ntsig thaum koj xav sau ob peb txoj hlua sib cais rau qhov tso tawm ua ntej cov lus hais kom xa rov qab mus rau tus neeg siv. 3. Muaj lub plhaub ua raws txoj cai hais kom ua Koj tau hais rau tus tswj lub plhaub kom ua txoj hauv kev cmdNewCmd thaum koj teeb tsa cov lus txib tshiab, tab sis ntxiv rau hauv shell.h ntawv kom nws nkag siab los ntawm lub plhaub kwv. Tsuas yog ntxiv nws hauv qab cov lus txib kawg lossis ua ntej ntawm thawj lo lus txib, lossis txhua qhov chaw nyob ntawd thiab qhov ntawd yog nws. Recompile thiab xa cov firmware rau koj Arduino thiab koj cov lus txib tshiab muaj los ntawm lub plhaub ntawm qhov hais kom sai.

Kauj Ruam 6: Cov ntsiab lus

Koj yuav tsum paub yuav teeb tsa thiab txuas rau koj li AVR/Arduino thiab tau txais kev qhia tam sim ntawm koj lub microcontroller uas khiav. Koj paub ntau cov lus txib uas yuav rub cov ntaub ntawv runtime los ntawm MCU lossis teeb tsa qhov tseem ceeb rau hauv MCU ntawm qhov yoov. Koj kuj tseem tau qhia pom yuav ua li cas ntxiv koj tus kheej kev cai los tsim koj tus kheej cov lus txib tshwj xeeb rau lub plhaub kom txuas ntxiv kho nws rau koj tus kheej xav tau. Koj tseem tuaj yeem hais tus kws txhais lus kom nws tsuas muaj koj cov lus txib tshwj xeeb, yog tias qhov haum rau koj cov kev xav tau. raws li kev kawm paub siv koj tus kheej. Ua li ib txwm, Kuv tos ntsoov yuav muaj lus tawm tswv yim los yog qhia seb yuav qhia li cas thiaj tuaj yeem txhim kho! Muaj kev lom zem nrog koj AVR!

Pom zoo: