Cov txheej txheem:

PART 2 - GPIO ARM ASSEMBLY - RGB - FUNCTION CALLS - Hloov: 6 Kauj Ruam
PART 2 - GPIO ARM ASSEMBLY - RGB - FUNCTION CALLS - Hloov: 6 Kauj Ruam

Video: PART 2 - GPIO ARM ASSEMBLY - RGB - FUNCTION CALLS - Hloov: 6 Kauj Ruam

Video: PART 2 - GPIO ARM ASSEMBLY - RGB - FUNCTION CALLS - Hloov: 6 Kauj Ruam
Video: Part 2 ARM Assembly MSP432 TI RSLK Write GPIO LED Lab 6 2024, Kaum ib hlis
Anonim
TSHOOJ 2 - GPIO ARM ASSEMBLY - RGB - FUNCTION CALLS - Hloov
TSHOOJ 2 - GPIO ARM ASSEMBLY - RGB - FUNCTION CALLS - Hloov

Hauv Ntu 1, peb tau kawm paub yuav ua li cas thiaj hloov tau ib Liab LED ntawm MSP432 LaunchPad pawg thawj coj loj los ntawm Texas Instruments, siv kev sib dhos tsis yog C / C ++.

Hauv Cov Lus Qhia no, peb yuav ua qee yam zoo sib xws - tswj RGB LED uas tseem nyob ntawm pawg thawj coj ntawd tib yam.

Nrog txoj kev, peb vam tias yuav txuas ntxiv peb cov kev paub ntawm ARM sib dhos, thiab tsis yog muaj kev lom zem teeb pom kev zoo qee qhov LEDs.

Kauj Ruam 1: Cia Peb dhia Txoj Cai Hauv

Tiag tiag, thawj daim vis dis aus hais txhua yam. Tsis ntau ntau ntxiv.

Lub ntsiab lus tseem ceeb ntawm nws yog tsav tsheb hauv tsev lub tswv yim tias txhua qhov chaw nres nkoj I/O ntawm MSP432 muaj qhov thaiv ntawm "sau npe" chaw nyob, uas nyob rau hauv lem suav nrog ntau qhov me me.

Tsis tas li ntawd, cov khoom tau muab tso ua pawg hauv ib qho orthogonal. Ntawd yog, ntsis 0 ntawm txhua qhov chaw sau npe xa mus rau tib tus pin sab nraud I/O.

Peb rov hais dua lub tswv yim tias nws yuav siv ntau qhov chaw sau npe rau qhov chaw nres nkoj ntawd, kom ua qee yam nrog txawm tias tsuas yog ib qho me me lossis tus pin.

Tab sis qhov ntawd hauv qhov no, txij li peb tab tom cuam tshuam nrog RGB LED, peb yuav tsum daws nrog peb qhov me me rau txhua qhov chaw sau npe.

Peb txhawb ntxiv tias peb xav tau ntau daim ntawv sau npe: DIR rau npe, SEL0 rau npe, SEL1 rau npe, thiab OUTPUT rau npe. Thiab peb khoom txhua lub sijhawm.

Kauj Ruam 2: Txhim Kho Txoj Cai - Ntxiv Txoj Haujlwm

Image
Image

Raws li koj tau pom hauv Kauj Ruam saum toj no, txoj haujlwm tseem ceeb hauv lub voj muaj ntau qhov rov ua dua, uas yog, thaum peb tua LEDs.

Yog li peb tuaj yeem ntxiv txoj haujlwm rau qhov program. Peb tseem yuav tsum tau hu txoj haujlwm ntawd txhua lub sijhawm peb xav tua lub LEDs, tab sis nws ua rau qee qhov ntawm cov cai kom tawg mus rau ib nqe lus.

Yog tias peb cov lej LED-tawm tau koom nrog ntau yam lus qhia ntxiv, qhov no yuav yog lub cim xeeb tiag tiag-txuag.

Ib feem ntawm cov phiaj xwm kos thiab micro-controllers tau paub ntau ntxiv txog qhov program loj.

Daim vis dis aus piav qhia.

Qhov tseem ceeb, peb ntxiv nqe lus faib rau peb txoj cai tseem ceeb, thiab peb muaj lwm qhov thaiv ntawm txoj cai uas yog txoj haujlwm uas peb faib rau. Thiab tom qab ntawd thaum peb ua tiav, lossis thaum kawg ntawm txoj haujlwm, peb rov qab mus rau nqe lus tom ntej hauv qhov haujlwm tseem ceeb.

Kauj Ruam 3: Ntxiv Cov Sijhawm Tsis Ncaj Ncees

Hauv Tshooj Kev Tshaj Tawm ntawm cov cai, ntxiv qhov ua kom yooj yim rau tweek rau lub sijhawm xav tau:

; ib lo lus tom qab ib nrab nyuv (';') pib tawm lus.

; cov cai hauv ntu no muab lub npe rau tus nqi.; koj kuj tseem tuaj yeem siv '.equ' tab sis lawv txawv me ntsis.; '.equ' (Kuv xav) tsis tuaj yeem hloov pauv, whereas '.set' txhais tau tias koj tuaj yeem ua tau; hloov tus nqi ntawm 'DLYCNT' tom qab hauv cov cai yog tias koj xav tau.; 'DLYCNT' yuav raug siv ua tus lej suav hauv qhov ncua sijhawm subroutine. DLYCNT.set 0x30000

Ntxiv qhov haujlwm ncua sijhawm tshiab:

ncua:.asmfunc; qhov pib ntawm 'ncua' subroutine lossis kev ua haujlwm.

MOV R5, #DLYCNT; thauj cov tub ntxhais cpu sau npe R5 nrog tus nqi muab rau 'DLYCNT'. dlyloop; qhov no cim pib ntawm ncua kev ncua. assembler txiav txim qhov chaw nyob. SUB R5, #0x1; rho tawm 1 los ntawm tus nqi tam sim no hauv tub ntxhais cpu sau npe R5. CMP R5, #0x0; sib piv tus nqi tam sim no hauv R5 rau 0. BGT dlyloop; ceg yog tus nqi hauv R5 ntau dua 0, rau daim ntawv lo (chaw nyob) 'dlyloop'. BX LR; yog tias peb tuaj txog ntawm no, txhais tau tias R5 tus nqi yog 0. rov qab los ntawm subroutine..endasmfunc; cim qhov kawg ntawm subroutine.

Tom qab ntawd hauv lub cev tseem ceeb, hauv lub voj loj, thov lossis hu rau qhov ua haujlwm qeeb:

; qhov no yog cov lej ib feem, ntawm lub cev tseem ceeb lossis lub luag haujlwm tseem ceeb (saib cov ntawv 'main.asm').

; qhov no yog lub voj nyob hauv 'lub ntsiab', thiab qhia pom tias peb hu lossis siv qhov tshiab 'ncua' ua haujlwm li cas.; tus '#REDON' thiab '#GRNON' kuj yog cov lus tshaj tawm (tsis tu ncua) (saib saum toj ntawm 'main.asm').; lawv tsuas yog txoj hauv kev yooj yim los teeb cov xim tshwj xeeb ntawm RGB LED. voj MOV R0, #REDON; Liab - teeb tsa tub ntxhais cpu sau npe R0 nrog tus nqi muab rau 'REDON'. STRB R0, [R4]; tub ntxhais sau npe R4 yav dhau los tau teeb tsa nrog GPIO qhov chaw nyob tso tawm.; sau dab tsi hauv R0, rau qhov chaw nyob qhia los ntawm R4. BL ncua; ceg mus rau txoj haujlwm tshiab 'ncua'. BL ledsoff; ceg rau qhov ua ntej 'ledsoff' muaj nuj nqi. BL ncua; ditto MOV R0, #GRNON; Ntsuab - ditto STRB R0, [R4]; thiab ntxiv rau. BL ncua BL ledsoff BL ncua

Cov vis dis aus mus kom ntxaws.

Kauj Ruam 4: Txheej Txheem Txheej Txheem ARM Architecture Call Standard (AAPCS)

Tej zaum yog lub sijhawm zoo los qhia qee yam. Nws yog lub rooj sib txoos ua lus. Kuj tseem hu ua Txheej Txheem Hu Tus Qauv rau ARM Architecture.

Muaj ntau qhov no, tab sis nws tsuas yog tus qauv. Nws tsis ua rau peb los ntawm kev kawm cov phiaj xwm sib sau ua ke, thiab peb tuaj yeem siv cov txheej txheem ntawd thaum peb mus, thaum peb zoo siab nrog qee lub ntsiab lus uas peb tab tom kawm.

Txwv tsis pub, peb yuav hnov zoo li peb tau haus los ntawm cov dej loj loj. Cov ntaub ntawv ntau dhau.

Cov Ntawv Sau Npe

Txij li thaum peb tau dhau los paub nrog MSP432 cov ntawv sau npe tseem ceeb, cia peb sim tam sim no siv qee cov qauv no. Peb yuav ua raws qhov no thaum peb sau cov haujlwm tom ntej (qhib / tua lub LED).

1) Peb yuav tsum siv R0 los ua qhov ntsuas ua haujlwm. Yog tias peb xav kom dhau tus nqi rau hauv txoj haujlwm (subroutine), peb yuav tsum siv R0 los ua li ntawd.

2) Peb yuav siv Daim Ntawv Teev Npe Txuas rau nws lub hom phiaj - nws tuav qhov chaw nyob uas qhia tias yuav rov mus rau qhov twg tom qab subroutine tiav.

Koj yuav pom tias peb siv cov no li cas.

Kauj Ruam 5: Ua Haujlwm Nrog Parameter - Zes Ua Haujlwm

Peb tuaj yeem ntxuav peb cov cai thiab txo qhov cim xeeb uas nws nyob los ntawm kev sib txuas ua ntu ntu rau hauv ib qho haujlwm. Tsuas yog qhov sib txawv hauv lub cev loj lub cev yog qhov peb xav tau qhov ntsuas kom peb tuaj yeem hla cov xim sib txawv uas peb xav pom ntawm RGB LED.

Ua tibzoo saib cov vis dis aus kom paub meej. (thov txim rau qhov ntev)

Kauj Ruam 6: GPIO Tswv Yim - Ntxiv Cov Hloov

Cia peb ua kom nws nthuav dua. Nws yog lub sijhawm los ntxiv qee qhov kev hloov pauv-tswj rau peb qhov kev sib dhos.

Cov Lus Qhia no muaj cov duab qhia txog yuav ua li cas ob lub on-board keyboards txuas nrog rau MSP432.

Qhov tseem ceeb: Hloov 1 (SW1 lossis S1) txuas nrog P1.1, thiab Hloov 2 (SW2 lossis S2) txuas nrog P1.4.

Qhov no ua rau qee yam nthuav me ntsis tsis yog vim tias peb tab tom cuam tshuam nrog cov tswv yim hloov chaw tso tawm, tab sis kuj vim tias ob txoj kev hloov pauv nyob lossis siv ob lub khoom ntawm tib qhov chaw sau npe thaiv ib yam li ib qho liab LED uas yog qhov tso tawm.

Peb daws nrog toggling ib leeg liab LED hauv Cov Lus Qhia no, yog li peb tsuas yog xav tau ntxiv cov cai los tswj cov hloov pauv.

Chaw nres nkoj 1 Sau Npe Chaw Nyob

Nco ntsoov tias peb tau npog cov no hauv Cov Lus Qhia yav dhau los, tab sis peb yuav tsum suav nrog qhov tshiab:

  • Chaw nres nkoj 1 Nkag Mus Sau Npe chaw nyob = 0x40004C00
  • Chaw nres nkoj 1 Output Sau npe chaw nyob = 0x40004C02
  • Chaw nres nkoj 1 Qhia rau chaw nyob = 0x40004C04
  • Chaw nres nkoj 1 Resistor Pab Sau Npe chaw nyob = 0x40004C06
  • Chaw nres nkoj 1 Xaiv 0 Sau npe chaw nyob = 0x40004C0A
  • Chaw nres nkoj 1 Xaiv 1 Sau npe chaw nyob = 0x40004C0C

Thaum siv cov chaw nres nkoj raws li cov tswv yim, yog qhov zoo los siv MSP432 qhov rub sab hauv lossis rub tawm sab hauv.

Txij li Launchpad pawg thawj coj txhim kho tau txuas ob lub qhov muag mus rau hauv av (LOW thaum nias), qhov ntawd txhais tau tias peb yuav tsum siv rub UP resistors kom paub tseeb tias peb muaj lub zog HIGH thaum lawv tsis nias.

Rub Tawm / Rub Tawm Resistors

Nws siv ob qhov sib txawv Chaw Nres Nkoj 1 Sau npe chaw nyob txhawm rau khi cov kev hloov pauv mus rau rub tawm cov neeg tawm tsam.

1) Siv Chaw Nres Nkoj 1 Resistor-Enable register (0x40004C06) tsuas yog qhia tias koj xav tau cov neeg tawm tsam (rau ob qho no), 2) thiab tom qab ntawd siv Port 1 Output register (0x40004C02) los teeb tsa tus tiv thaiv raws li rub tawm lossis rub tawm. Cov npe tso tawm yuav luag zoo li ob lub hom phiaj.

Yog li, rov hais dua lwm txoj hauv kev, Cov npe tso tawm tuaj yeem xa tawm HIGH lossis LOW mus rau qhov tso tawm (xws li ib leeg liab LED), thiab / lossis nws tau siv los teeb tsa rub tawm lossis rub tawm qis rau cov khoom siv, TAB SIS XWB yog tias qhov tshwj xeeb tau qhib los ntawm Resistor-Enable register.

Tseem ceeb hauv qhov saum toj no-thaum xa/teeb tsa LOW lossis HIGH rau txhua qhov tso tawm me ntsis, koj yuav tsum tswj hwm lub xeev rub tawm/rub tawm ntawm cov khoom nkag ib txhij.

(daim vis dis aus sim piav qhia)

Nyeem Qhov Chaw Nkag Nkag Me ntsis

  • Teeb SEL0 / SEL1 rau GPIO kev ua haujlwm
  • Teeb DIR sau npe ua tswv yim rau cov khoom hloov pauv, tab sis raws li tso tawm rau LED (ib txhij hauv tib lub byte)
  • Pab kom cov resistors
  • Teem lawv raws li rub-up resistors
  • Nyeem qhov chaw nres nkoj
  • Koj tuaj yeem xav lim tus nqi nyeem kom cais tawm tsuas yog cov khoom koj xav tau (hloov 1 thiab 2)

Pom zoo: