原创 key_led

2009-2-5 16:36 3137 5 6 分类: MCU/ 嵌入式

//看图的时候不仔细,按键顺序乱了,不好意思


a806b5ac-294b-4f11-8d72-6e91986d70bb.JPG


#define GPFCON (*(volatile unsigned long *) 0x56000050)
#define GPFDAT (*(volatile unsigned long *) 0x56000054)
#define GPGCON (*(volatile unsigned long *) 0x56000060)
#define GPGDAT (*(volatile unsigned long *) 0x56000064)
#define GPBCON (*(volatile unsigned long *) 0x56000010)
#define GPBDAT (*(volatile unsigned long *) 0x56000014)


/*
*LED1-4 GPF4-7
*/
#define OUT_4 (1<<(4*2))
#define OUT_5 (1<<(5*2))
#define OUT_6 (1<<(6*2))
#define OUT_7 (1<<(7*2))



/*
*KEY1: GPB6 low GPF0
*KEY2: GPB6 low GPG5
*KEY3: GPB6 low GPG3
*KEY4: GPB6 low GPG11
*KEY5: GPB7 low GPF0
*KEY6: GPB7 low GPG5
*KEY7: GPB7 low GPG3
*KEY8: GPB7 low GPG11
*/


 


#define IN_0 ~(3<<(0*2))
#define IN_3 ~(3<<(3*2))
#define IN_5 ~(3<<(5*2))
#define IN_11 ~(3<<(11*2))


void delay()
{
 int i, j;
 for(i=255; i!=0; i--) {
  for(j=255; j!=0; j--) {
   ;
  }
 }
}
void k1_to_k4()
{
 unsigned long dwDat;
  dwDat = GPFDAT;
  if (dwDat & (1<<0)) {
   GPFDAT |= (1<<4);
  }
  else {
   GPFDAT &= ~(1<<4);
  }
  
  dwDat = GPGDAT;
  if (dwDat & (1<<5)) {
   GPFDAT |= (1<<5);
  }
  else {
   GPFDAT &= ~(1<<5);
  }
 
  dwDat = GPGDAT;
  if (dwDat & (1<<3)) {
   GPFDAT |= (1<<6);
  }
  else {
   GPFDAT &= ~(1<<6);
  }


  dwDat = GPGDAT;
  if (dwDat & (1<<11)) {
   GPFDAT |= (1<<7);
  }
  else {
   GPFDAT &= ~(1<<7);
  }
}


void k5_to_k7()
{
 unsigned long dwDat;
  int i;
  dwDat = GPFDAT;
  if (dwDat & (1<<0)) {
   GPFDAT |= (1<<4);
  }
  else {
   for (i=10; i!=0; i--) {
    GPFDAT |= (1<<4);
    GPFDAT &= ~(1<<4);
    delay();
   }
  }
  
  dwDat = GPGDAT;
  if (dwDat & (1<<5)) {
   GPFDAT |= (1<<5);
  }
  else {
   for (i=10; i!=0; i--) {
    GPFDAT |= (1<<5);
    GPFDAT &= ~(1<<5);
    delay();
   }
  }
 
  dwDat = GPGDAT;
  if (dwDat & (1<<3)) {
   GPFDAT |= (1<<6);
  }
  else {
   for (i=10; i!=0; i--) {
    GPFDAT |= (1<<6);
    GPFDAT &= ~(1<<6);
    delay();
   }
  }


  dwDat = GPGDAT;
  if (dwDat & (1<<11)) {
   GPFDAT |= (1<<7);
  }
  else {
   for (i=10; i!=0; i--) {
    GPFDAT |= (1<<7);
    GPFDAT &= ~(1<<7);
    delay();
   }
  }
}


int main()
{
/*
*GPB6 GPB7 GPF4-7 设为OUT
*GPF0 GPG5 GPG3 GPG11 设为IN
*/
 GPFCON = OUT_4 | OUT_5 | OUT_6 | OUT_7 & IN_0;
 GPBCON = OUT_6 | OUT_7;
 
 GPGCON = IN_3 & IN_5 & IN_11;


 while(1) {
  GPBDAT = ~(1<<6) & (1<<7);
  k1_to_k4();


  GPBDAT = (1<<6) & ~(1<<7);
  k5_to_k7();



 }
 


}
https://static.assets-stash.eet-china.com/album/old-resources/2009/2/5/39a42e2b-44c2-47d3-a417-611b695f3927.rar

文章评论1条评论)

登录后参与讨论

yannzi 2009-2-5 19:36

GPFDAT |= (1<<5); GPFDAT &= ~(1<<5); delay(); 这些地方逻辑弄错了,本想闪烁的,不好意思
相关推荐阅读
yannzi 2009-08-14 22:45
C++课程设计指导书之二 媒體庫管理系統
一、課程設計目的l        通過設計、實現媒體庫管理系統,熟悉面向對象的設計思想;l        進一步熟悉、掌握STL中有關類型及其使用方法,泛型編程的風格。二、系統設計要求在這個課程設計中...
yannzi 2009-08-10 16:17
C++课程设计指导书之一 学生考勤管理系统,已添加自己的程序
https://static.assets-stash.eet-china.com/album/old-resources/2009/5/15/cc35849a-1226-4015-829a-f5fe...
yannzi 2009-08-10 11:54
痛苦并快乐着
今天图书馆下了一堆资料,可能是猛过头了,所以用死了两台电脑,还有一台电脑根本开不了机。。。帮同学影印了九章奖状,有机会可以剥削人家一把,影印太费时了。在宿舍,还有工人忙着修宿舍,噪音很吵,就快开始看资...
yannzi 2009-08-09 22:21
实用软件介绍 (Q-Dir、UE编辑器、Beyond Compare)
Q-Dir 3.93http://www.onlinedown.net/soft/66200.htmUltraEdit-32 (文本编辑器)http://www.orsoon.com/Soft/780...
yannzi 2009-08-09 22:09
实习第8天
      昨天也没什么好写的,就这样跳过了,都是自己在看一些有关嵌入式的视频。      原本今天也没什么好写的,倒数第二天了,发现有些东西还是挺人性化的,比如不用现在就把电脑还了之类的,要不然还真...
yannzi 2009-08-09 22:08
实习第6天
       这天吃了早餐来到公司,过了半个钟,就退还了两本Windows相关的编程书,放弃MFC相关的编程了,然后再借了两本与嵌入式有关的书。       就这样开始一天的读书之旅。看来要开始准备辞...
我要评论
1
5
关闭 站长推荐上一条 /2 下一条