本文主要是介绍6410裸板程序,led、蜂鸣器、按键…,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//*****************************************************************
//作者:昊天
//
//功能:在ok6410板子上跑裸板程序,用四个按键控制四个led灯的两灭及蜂鸣器的叫声,
// 当按键1按下时(此时为低电平)点亮led1同时蜂鸣器响,当松手时,led1灭及蜂鸣器不响
// 以此类推剩下三个键
//时间:2012/12/13 22:01
//******************************************************************
//蜂鸣器---GPF15
#define GPFCON (*(volatile unsigned *)(0x7f0080a0))
#define GPFDAT (*(volatile unsigned *)(0x7f0080a4))
#define GPFPUD (*(volatile unsigned *)(0x7f0080a8))
//按键(6个)---GPN0--GPN5
#define GPNCON (*(volatile unsigned *)(0x7f008830))
#define GPNDAT (*(volatile unsigned *)(0x7f008834))
#define GPNPUD (*(volatile unsigned *)(0x7f008838))
//LED(四个)----GPM0--GPM3
#define GPMCON (*(volatile unsigned long *)(0x7F008820))
#define GPMDAT (*(volatile unsigned long *)(0x7F008824))
#define GPMPUD (*(volatile unsigned long *)(0x7F008828))
void msDelay(volatile unsigned int time)
{
volatile unsigned int i;
volatile unsigned int j;
for(i=0;i<200000;i++)
{
for(j=0;j
}
}
GPFCON = GPFCON & (~(0x1<<(31))); //最高位31至0
GPFCON = GPFCON | (0x1<<(2*15)); //第30位置1 这样01表示输出
GPFPUD = GPFPUD & (~(0x3<<(2*15))); //上拉电阻禁用
GPFDAT = GPFDAT & 0x7fff; //第16管脚输出为0 也就是buzzer不响
//初始化按键
GPNCON = GPNCON & (0xffffffff<<12);
{
GPFDAT = GPFDAT &0x7fff;
}
void BeepOn(void)
{
GPFDAT = GPFDAT | 0x8000;
}
unsigned int KeyScan(void)
{
else if((GPNDAT & 0x3f)==0x3d)
else if((GPNDAT & 0x3f)==0x3b)
else if((GPNDAT & 0x3f)==0x37)
else
}
void KeyTest(void)
{
}
void main(void)
{
GPIO_Init();
}
下面是启动代码init.o:
PRESERVE8
IMPORT main
AREA init,CODE,READONLY
ENTRY
CODE32
START
ldr r0,=0x70000000
orr r0,r0,#0x13
mcr p15,0,r0,c15,c2,4
ldr r0,=0x7E004000
mov r1,#0
str r1,[r0]
ldr sp,=8*1024
bl main
这篇关于6410裸板程序,led、蜂鸣器、按键…的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!