关闭

6410裸板程序,led、蜂鸣器、按键…

487人阅读 评论(0) 收藏 举报
分类:
//*****************************************************************
//作者:昊天
//
//功能:在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
}
}
 void GPIO_Init(void)
 {  //初始化buzzer
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);
  GPNPUD = GPNPUD & (0xffffffff<<12);
  GPNDAT = GPNDAT | (~(0xffffffff<<6));
 
  //led初始化
    GPMCON = GPMCON | (0x00001111);
    GPMPUD = GPMPUD & (0xFFFFFFFF<<8);
    GPMDAT = GPMDAT | (~(0xfffffff0));
    
    
 }
 void BeepOff(void)
{
GPFDAT = GPFDAT &0x7fff;
}

void BeepOn(void)
{
GPFDAT = GPFDAT | 0x8000;
}

unsigned int KeyScan(void)
{

  
    if((GPNDAT & 0x3f)==0x3e)
  return 1;  //说明按键1按下
else if((GPNDAT & 0x3f)==0x3d)
  return 2;   //说明有按键2按下
else if((GPNDAT & 0x3f)==0x3b)
  return 3;     //说明有按键3按下
else if((GPNDAT & 0x3f)==0x37)
  return 4;      //说明有按键4按下
else
  return 0;    //说明没有按键按下
  
}

void KeyTest(void)
{
   unsigned int KeyStatus;
   while(1)
   {
    KeyStatus=KeyScan();
     
    switch(KeyStatus)
    {
    case 0:BeepOff(); 
          GPMDAT = GPMDAT | 0x0000000f;
          break;
    case 1:GPMDAT = (GPMDAT & 0xfffffffe);   //1键按下点亮led1               
              BeepOn();                          
          break;
    case 2:GPMDAT = GPMDAT & 0xfffffffd;
              BeepOn();
              break;
    case 3:GPMDAT = GPMDAT & 0xfffffffb;
              BeepOn();
              break;
       case 4:GPMDAT = GPMDAT & 0xfffffff7;
              BeepOn();
              break;
    }
     
     
   }
}


void main(void)
{
GPIO_Init();
    BeepOff();
    KeyTest();

    
}


下面是启动代码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
            END
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:321146次
    • 积分:5026
    • 等级:
    • 排名:第5612名
    • 原创:162篇
    • 转载:172篇
    • 译文:1篇
    • 评论:24条
    交流分享
    欢迎大家加入QQ群:469897460 一起来分享交流技术
    最新评论