Chinaunix首页 | 论坛 | 博客
  • 博客访问: 217049
  • 博文数量: 121
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1393
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-11 12:17
个人简介

www.vibexie.com vibexie@qq.com

文章分类

全部博文(121)

文章存档

2015年(55)

2014年(66)

我的朋友

分类: 嵌入式

2014-11-14 12:46:05

JZ2440开发板功能实现,通过按下3个开关键,控制3个LED灯的亮灭

crt0.S

  1. .text
  2. .global _start
  3. _start:
  4.     ldr r0,=0x53000000
  5.     mov r1,#0x0
  6.     str r1,[r0]

  7.     ldr sp,=1024*4

  8.     bl main
  9. loop:
  10.     b loop

leds_key.c

  1. #define GPFCON (*(volatile unsigned long*)0x56000050)
  2. #define GPFDAT (*(volatile unsigned long*)0x56000054)

  3. #define GPGCON (*(volatile unsigned long*)0x56000060)
  4. #define GPGDAT (*(volatile unsigned long*)0x56000064)

  5. /*LEDs*/
  6. #define GPF4_OUT (1<<(2*4))
  7. #define GPF5_OUT (1<<(2*5))
  8. #define GPF6_OUT (1<<(2*6))

  9. #define GPF4_MSK (3<<(2*4))
  10. #define GPF5_MSK (3<<(2*5))
  11. #define GPF6_MSK (3<<(2*6))

  12. /*KEYs*/
  13. #define GPF0_IN (0<<(2*0))
  14. #define GPF2_IN (0<<(2*2))
  15. #define GPG3_IN (0<<(2*3))

  16. #define GPF0_MSK (3<<(2*0))
  17. #define GPF2_MSK (3<<(2*2))
  18. #define GPG3_MSK (3<<(2*3))

  19. int main()
  20. {
  21.     unsigned long DAT;
  22.     /*set LED1 LED2 LED4 for output*/
  23.     GPFCON&=~(GPF4_MSK | GPF5_MSK | GPF6_MSK);
  24.     GPFCON|=(GPF4_OUT | GPF5_OUT | GPF6_OUT);

  25.     /*set KEY2 KEY3 for input*/
  26.     GPFCON&=~(GPF0_MSK | GPF2_MSK);
  27.     GPFCON|=(GPF0_IN | GPF2_IN);
  28.     
  29.     /*set KEY4 for input*/
  30.     GPGCON&=~GPG3_MSK;
  31.     GPGCON|=GPG3_IN;

  32.     while(1)
  33.     {
  34.         DAT=GPFDAT;
  35.         if(DAT & (1<<0))/*no press KEY2*/
  36.             GPFDAT|=(1<<4);/*light down*/
  37.         else
  38.             GPFDAT&=~(1<<4);/*light on*/
  39.         
  40.         if(DAT & (1<<2))/*no press KEY3*/
  41.             GPFDAT|=(1<<5);
  42.         else
  43.             GPFDAT&=~(1<<5);

  44.         DAT=GPGDAT;
  45.         if(DAT & (1<<3))/*no press KEY4*/
  46.             GPFDAT|=(1<<6);
  47.         else
  48.             GPFDAT&=~(1<<6);
  49.     }


  50.     return 0;
  51. }

Makefile

  1. leds_key.bin:crt0.S leds_key.c
  2.     arm-linux-gcc -g -c -o crt0.o crt0.S
  3.     arm-linux-gcc -g -c -o leds_key.o leds_key.c
  4.     arm-linux-ld -Ttext 0x00000000 -g crt0.o leds_key.o -o leds_key_elf
  5.     arm-linux-objcopy -O binary -S leds_key_elf leds_key.bin
  6. clean:
  7.     rm -f *.o leds_key_elf leds_key.bin
阅读(672) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册