Cov txheej txheem:

Pib Pib Nrog Bascom AVR: 5 Kauj Ruam
Pib Pib Nrog Bascom AVR: 5 Kauj Ruam

Video: Pib Pib Nrog Bascom AVR: 5 Kauj Ruam

Video: Pib Pib Nrog Bascom AVR: 5 Kauj Ruam
Video: 20 MOMENTS YOU WOULDN'T BELIEVE IF NOT FILMED 2024, Kaum ib hlis
Anonim
Pib Pib Nrog Bascom AVR
Pib Pib Nrog Bascom AVR

Nov yog qhov pib ntawm kab lus qhia koj program koj AVR microcontroller nrog Bascom AVR.

Vim li cas kuv thiaj ua li no.

Feem ntau ntawm cov qauv qauv hauv kab ntawv no koj tuaj yeem ua nrog Arduino.

Qee qhov yooj yim dua thiab qee qhov nyuaj dua, tab sis thaum kawg ob qho tib si yuav khiav ntawm tib tus tswj.

Tab sis txoj hauv kev ntawm cov phiaj xwm sib txawv hauv txhua qhov kev txhim kho ib puag ncig. Arduino xav tau lub tsev qiv ntawv rau txhua yam tshwj tsis yog lub hauv paus haujlwm. Bascom kuj ua haujlwm nrog tsev qiv ntawv, tab sis kuv tsis tshua muaj suav nrog. Nrog Arduino, txhua qhov kho vajtse tshwj xeeb teeb tsa tau ua los ntawm cov tsev qiv ntawv. koj muaj kev cuam tshuam me me ntawm lub zog tiag tiag ntawm lub microcontroller. Pib nrog cov timers uas tus tswj muaj. nrog arduino koj xav tau lub tsev qiv ntawv dua. yog tias koj muaj lub sijhawm ua haujlwm kom txog thaum nws ua haujlwm, nws yuav yog lwm lub tsev qiv ntawv sib tsoo nrog koj cov chaw. Ntawm bascom koj muaj kev nkag tau dawb mus rau cov cuab yeej ua tiav suav nrog cov khau raj uas yog nyob ntawm arduino. piv txwv li, qee lub tsev qiv ntawv ntawm bascom nug koj lub sijhawm twg uas koj xav siv. ntawm qhov tod tes, txij li arduino ua rau nws yooj yim heev los tsim lub tsev qiv ntawv koj tus kheej, nws ib txwm ua rau nws yog lub platform uas kho vajtse thiab cov cuab yeej tshiab feem ntau muaj lub tsev qiv ntawv ncaj qha. dab tsi feem ntau cuam tshuam nrog kev tshawb fawb ntau ntawm bascom thiab lub luag haujlwm uas lub tsev qiv ntawv ib txwm siv rau yuav tsum yog tom qab ntawd tau mob siab rau koom nrog hauv txoj haujlwm program. tab sis xov xwm zoo hauv zej zog bascom kuj tseem loj heev uas yog vim li cas thiaj muaj kev daws teeb meem rau txhua lub tswv yim.

Yog li nws nyob ntawm ib feem ntawm txoj haujlwm uas siv rau kev tsim kho ib puag ncig thiab ib nrab ntawm kev paub-paub ntawm tus neeg txoj haujlwm li cas.

tab sis vim li cas kuv thiaj ua qhov koob no. ntawm ib sab nws txuag nyiaj ntau. Kuv tsis tas yuav yuav ib lub rooj tsav xwm arduino rau txhua qhov haujlwm. Piv txwv li: Ib tus neeg tsis paub npe Arduino uno tus nqi kwv yees li 12 € tus tswj hwm uas nyob ntawm nws tus nqi tsuas yog 2.5 € nrog qhov tsawg kawg nkaus Circuit Court xav tau rau kev ua haujlwm ruaj khov, nws raug nqi ib ncig 4 €. ntawm qhov tod tes koj muaj kev xaiv ua tiav ntawm avr chips uas tau txais kev txhawb nqa. atmegas 8 txog 256 thiab attiny 8 txog 2313 thiab ntau yam xmega txog yam uas kuv tsis muaj kev paub. Yog tias koj tsuas xav siv lub servo thiab lub ntsuas hluav taws xob ultrasonic uas tuaj yeem lees paub txhais tes, piv txwv li, thiab tom qab ntawd qhib lub hau ntawm lub thoob khib nyiab, koj tuaj yeem siv qhov me me ua tau. Yog li muaj ntau yam laj thawj los kawm hom lus thib ob.

Yog li cia peb pib

Khoom siv

Nov yog cov npe ntawm yam tsawg kawg nkaus uas yuav tsum tau ua rau kev ua haujlwm ruaj khov ntawm cov nti thiab lub cajmeem.

Breadboard rau kev sim

Atmega 8-16PU (zoo dua koj yuav 2 lossis 3 yog tias koj tua lawv yuam kev)

7805 5V qhov ntsuas hluav taws xob

10 Kohm resistor

100nF zaj duab xis capacitor

10µF electrolytic capacitor

100µF electrolytic capacitor

qee cov xov hlau rau lub khob cij

Windows PC 7/8/8.1/10

ISP Programmer (Kuv yuav siv USBasp ntawm no koj tuaj yeem yuav nws ntawm amazon kom tau nyiaj tsawg)

Bascom AVR (koj tuaj yeem rub tawm DEMO ntawm no. Txhua qhov kev ua haujlwm tau qhib, tab sis koj tuaj yeem sau cov cai nkaus xwb txog 4Kb loj uas txaus rau ntau tus lej).

Yeem qhov:

LED nrog resistors

thawb hloov

qhov tshwj xeeb qhov project

Kauj ruam 1: Kev teeb tsa ntawm Bascom thiab Teeb

Kev teeb tsa ntawm Bascom thiab Teeb
Kev teeb tsa ntawm Bascom thiab Teeb
Kev teeb tsa ntawm Bascom thiab Teeb
Kev teeb tsa ntawm Bascom thiab Teeb
Kev teeb tsa ntawm Bascom thiab Teeb
Kev teeb tsa ntawm Bascom thiab Teeb

Rub tawm cov ntawv thiab teeb tsa Bascom AVR. Nruab txhua qhov ntawm nws suav nrog lub npov kawg tom qab teeb tsa.

Tom qab ntawd reboot koj lub PC txwv tsis pub bascom yuav tsis pib.

Tom qab reboot pib bascom.

Mus rau Options -> Programmer thiab xaiv USBasp los ntawm cov npe, khaws cov chaw thiab kaw Bascom.

Siv qhov program no los nruab usbasp. Tom qab ntawd, reboot koj lub PC dua. Tam sim no txuas USBasp nrog koj lub PC thiab pib tus thawj tswj ntaus ntawv. USBasp yuav tsum tshwm ntawm cov khoom siv libusb.

Stat Bascom dua thiab tsim cov ntawv tshiab. Txuag nws rau koj lub PC thiab ntaus F7 khawm ntawm koj cov keyboard.

Tus compiler pib thiab suav sau qhov kev pab cuam khoob. Tam sim no koj tuaj yeem sim ua haujlwm ntawm tus programmer.

Ntaus F4 khawm ntawm koj cov keyboard kom pib lub programmer window. Tam sim no mus rau nti -> txheeb xyuas kom pib sib cuam tshuam. LED los ntawm USBasp yuav tsum tam sim no ntsais ntsais. Koj yuav tsum tau txais cov lus zoo li nti ID FFFFFF tsis tuaj yeem nyeem ntawv. Qhov ntawd yog lub cim zoo uas Programmer tab tom ua haujlwm tab sis nws pom tsis muaj nti.

Tam sim no peb tuaj yeem pib tsim thawj Circuit Court.

Kauj Ruam 2: Cia Li Saib Kom Zoo Dua ntawm Chip

Cia Li Los ze Saib Hauv Chip
Cia Li Los ze Saib Hauv Chip

Yog tias koj saib ntawm pinout ntawm lub nti nws zoo li lub nti tsis muaj qhov zoo sib xws rau pawg thawj coj saib. Tseeb, peb siv Atmega8 thiab ntawm Arduino uno yog Atmega328. Tab sis Pinout yog yuav luag zoo ib yam tab sis nws nti ntawm Arduino Uno board muaj ntau txoj haujlwm. Nov yog cov npe ntawm cov pins. VCC thiab GND yog tus pin rau lub hwj chim.

AREF thiab AVCC yog cov pins rau qhov ntsuas hluav taws xob thiab lub zog siv hluav taws xob rau kev hloov pauv mus rau digital.

PB 0-7 PC 0-6 PD 0-7 yog lub hom phiaj dav dav tso zis pins nrog ntau tus neeg nyob.

pib tus pin yog dab tsi lub npe hais. Txhawm rau rov pib dua lub nti. Kab kab saum toj sau npe lub npe txhais tau tias tsis zoo. Qhov ntawd txhais tau tias, kom rov pib dua lub nti koj yuav tsum rub nws mus rau 0V.

Rau cov pins hauv qab no cais cov lus qhia uas yuav los sai sai.

RXD TXD yog cov pins kho vajtse rau kev sib txuas lus txuas UART.

INT0 INT1 yog kho vajtse cuam tshuam pins

XCK /T0 UART Clock source /Timer /Counter0 Clock source

XTAL /TOSC pins yog rau sab nraud siv lead ua txog 16MHz (qauv sib txawv txog 20MHz) /Crystal pins rau sab hauv RTC

T1 zoo ib yam li T0

AIN pins yog rau kev sib piv analog

ICP1 zoo ib yam li T0/T1

OC1A yog tus lej kho vajtse tus pin rau pwm timer1 channel A

SS / OC2 nti xaiv tus pin rau SPI / zoo li OC1B tab sis channel B.

MOSI MISO SCK / OC2 yog kho vajtse SPI pins thiab tus pin rau kev ua haujlwm / PWM tso zis timer2

ADC0 txog ADC5 yog cov tswv yim analog

SDA SCL yog Pins rau kho vajtse I2C

Cov nti ib txwm tuaj yeem ua haujlwm los ntawm 4, 5V txog 5, 5V Atmega 8L tuaj yeem ua haujlwm nrog qis dua Voltage.

Koj pom txawm tias lub nti no tuaj yeem ua ntau dua li Arduino Uno zoo li tsis tuaj yeem ua. Tab sis Arduino tuaj yeem ua nws ib yam nkaus, koj tsuas yog yuav tsum tau teeb tsa nws.

Kauj Ruam 3: Thawj Circuit

Thawj Circuit Court
Thawj Circuit Court
Thawj Circuit Court
Thawj Circuit Court

Tam sim no nws yog lub sijhawm los tsim koj thawj Circuit Court.

Dab tsi feem ntau yog thawj Circuit Court? Yog lawm! Cia peb ntsais muag LED.

LED txuas nrog PB0. Cov resistor ib sab ntawm lub nti muaj 10k Ohms.

Cov resistor ib sab ntawm LED muaj 470 Ohms.

Tam sim no koj tuaj yeem txuas USBasp nrog Atmega raws li qhia hauv daim duab.

Tab sis ua ntej koj hloov lub zog cia peb sau qhov program.

Kauj Ruam 4: Sau Thawj Txoj Haujlwm

Sau Thawj Txoj Haujlwm
Sau Thawj Txoj Haujlwm

Tsim cov ntawv tshiab hauv Bascom thiab ntaus hauv cov ntawv hauv qab no.

$ regfile "m8def.dat"

$ crystal = 1000000 teeb tsa portb.0 = tso tawm rau portb.0 = 1 tos 1 portb.0 = 0 tos 1 lub voj

Tom qab ntawv suav nws los ntawm kev ntaus F7 ntawm koj cov keyboard.

Tam sim no peb tuaj yeem teeb tsa lub nti los ntawm nias F4. Qhov programmer window tshwm. Tam sim no nws yog lub sijhawm los hloov lub zog los ntawm daim ntawv qhia zaub mov. Koj yuav tsum siv qee yam ntawm 6 thiab 12 Volts.

Tam sim no mus rau nti -> autoprogram. Yog hais tias lub programmer qhov rai kaw cia qhov kev ua haujlwm tau ua tiav.

LED yuav tsum tau ntsais muag hauv ib pliag thib ob.

Tam sim no ua tib zoo saib mus rau qhov program kom nkag siab cov syntax.

$ regfile "m8def.dat"

$ crystal = 1000000

nrog $ regfile peb qhia tus neeg sib tham hom kev siv nti lub npe ntawm Arduino nti yuav yog "m328pdef.dat"

nrog $ siv lead ua peb qhia nws qhov cpu nrawm txog 1MHz.

config portb.0 = Cov zis

uas txhais tau tias PB0 yuav tsum ua raws li cov zis.

Los ntawm txoj kev, cov ntawv luv PB0 txhais tau tias chaw nres nkoj B me 0. Qhov nti tau muab faib ua ntau qhov chaw nres nkoj. Txhua qhov chaw nres nkoj tau muab tsab ntawv kom pom tseeb. thiab txhua tus pinpin me ntsis los ntawm 0 txog 7. Piv txwv li, Kuv tuaj yeem sau ua tiav byte rau hauv qhov chaw tso npe tso tawm, uas yuav tso tawm ntawm tus kheej chaw nres nkoj pins.

ua

voj

Nov yog dab tsi hauv Arduino qhov khoob khoob khoob khoob khoob khoob khoob khoob khoob khoob khawm. Txhua qhov ntawm ob lo lus txib yuav rov ua mus ib txhis. (nrog qee qhov kev zam tab sis tom qab ntau ntxiv txog qhov ntawd)

Portb.0 = 1

tos 1 portb.0 = 0 tos 1

Ntawm no peb gernerate qhov ntsais ntawm tus coj.

Portb.0 = 1 qhia lub nti kom hloov PB0 rau 5V

qhov tos 1 hais kom cia nti tos ib pliag. Yog tias koj xav hloov tus coj sai dua koj yuav tsum hloov qhov tos tos nrog tos tam sim no koj tuaj yeem nkag mus qee lub sijhawm tam sim no hauv milliseconds piv txwv li waitms 500. (waitus txhais tau tias tos hauv nanoseconds)

Portb.0 = 0 qhia lub nti kom hloov PB0 rau 0V.

Kauj Ruam 5: Ntxiv Khawm los Siv Cov Tswv Yim

Ntxiv khawm kom siv cov tswv yim
Ntxiv khawm kom siv cov tswv yim

Tam sim no peb ntxiv lub pob kom pom kev coj yog tias lub pob nyem.

Ntxig lub pob raws li qhia hauv daim duab.

tam sim no ntaus hauv qhov program ua raws.

$ regfile "m8def.dat"

$ crystal = 1000000 config portb.0 = output config portd.7 = input Portd.7 = 1 do if pind.7 = 0 then portb.0 = 1 else portb.0 = 0 loop

Yog tias koj tso qhov program ntawd mus rau lub nti, cov coj tsuas yog teeb thaum lub pob nyem. Tab sis vim li cas?

qhov kev zov me nyuam pib zoo ib yam li qhov kawg txog

config portd.7 = tswv yim. Qhov ntawd txhais tau tias, tus pin PD7 uas txuas nrog khawm ua lub luag haujlwm.

Portd.7 = 1 tsis hloov tus pin kom siab, tab sis nws ua rau sab hauv rub tawm tus tiv thaiv ntawm Atmega.

Yog tias statemend zoo li me ntsis wierd yog tias koj tau siv rau arduino.

yog tias koj siv cov lus hais yog koj yuav tsum siv lo lus "tom qab". Hauv qhov piv txwv no yog tias nqe lus tau siv rau kev ua haujlwm ib leeg. Yog tias koj xav siv ntau cov lus txib koj yuav tsum sau nws zoo li no.

yog pind.7 = 0 ces

portb.0 = 1 qee qhov chaws qee qhov chaws qee qhov chaws lwm qhov portb.0 = 0 kawg yog

rau qhov siv cov lus hais no koj yuav tsum siv lo lus "kawg yog" thaum kawg.

dab tsi tseem ceeb. Tej zaum koj twb pom nws lawm. cov tswv yim tsis nug nrog portx.x, tab sis nrog pinx.x koj tuaj yeem nco tau yooj yim. Cov zis tawm muaj "o" (chaw nres nkoj) hauv lo lus thiab cov khoom siv muaj "i" (tus pin).

Tam sim no nws yog koj tig los ua si ib puag ncig me ntsis.

Kuv cov lus qhia tom ntej yuav los sai sai no (cov lus hais zoo li thaum, xaiv rooj plaub, rau, thiab hloov pauv.)

Yog tias koj nyiam kuv cov lus qhia thiab xav tau ntau ntxiv qhia rau kuv hauv cov lus.

Pom zoo: