原理圖

image.png

image.png

image.png

image.png

image.png
.text
.global _start
_start:
ldr sp,=0x80000000+0x100000
bl main
void main()
{
volatile unsigned int *pRegLed;
volatile unsigned int *pRegKey;
/* 時(shí)鐘使能GPIO1 CCM_CCGR1寄存器 */
pRegLed = (volatile unsigned int *)(0x020C406C);
*pRegLed |= (0b11 << 26);
/* 把GPIO1_3設(shè)置為GPIO功能 IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO03 */
pRegLed = (volatile unsigned int *)(0x020E0068);
*pRegLed &= ~(0xf);
*pRegLed |= 0x05;
/* 把GPIO1_18設(shè)置為GPIO功能 IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO018*/
pRegKey = (volatile unsigned int *)(0x020E008C);
*pRegKey &= ~(0xf);
*pRegKey |= 0x05;
/* 設(shè)置GPIO1_3引腳為輸出 GPIO1_GDIR*/
pRegLed = (volatile unsigned int *)(0X0209C004);
*pRegLed |= (0b1 << 3);
/* 設(shè)置GPIO1_1引腳為輸入 GPIO1_GDIR*/
pRegKey = (volatile unsigned int *)(0X0209C004);
*pRegKey &= ~(0b1 << 1);
/*GPIO1_DR GPIO data register GPIO數(shù)據(jù)寄存器 */
pRegLed = (volatile unsigned int *)(0X0209C000);
/*GPIO1_DR GPIO data register GPIO數(shù)據(jù)寄存器 */
pRegKey = (volatile unsigned int *)(0X0209C000);
while (1)
{
/* 讀取GPIO1_1引腳 */
if((*pRegKey & (1<<18)) == 0) /* 被按下 */
{
*pRegLed |= (0b1 << 3); //滅
}
else
{
*pRegLed &= ~(0b1 << 3); //亮
}
}
}