Osless programming on mini2440--GPIO LED

  1 @ file  : led_on.S 
  2 @ date  : 02-01-2013 
  3 @ author: asicer@live.cn 
  4 
  5 @ nLED_1 <-> GPB5  
  6 @ nLED_2 <-> GPB6  
  7 @ nLED_3 <-> GPB7  
  8 @ nLED_4 <-> GPB8  
  9 @ n means low value enable light on. 
 10 @ That is, 0 turn light on and 1 turn it off. 
 11 
 12 @ GPBCON 0x56000010 Port B control  
 13 @ GPBDAT 0x56000014 Port B data  
 14 @ GPBUP  0x56000018 Pull-up control B  
 15 
 16 @  ________________________________________________  
 17 @ | PBCON | BIT       | Discription                |  
 18 @ |-------|-----------|----------------------------|  
 19 @ | GPBx  | [2x+1:2x] | 00 = Input 01 = Output     |  
 20 @ |       |           | 10 = nXDREQ0 11 = reserved |  
 21 @ |_______|___________|____________________________|  
 22 
 23 @  ___________________________________________________________________________________________________  
 24 @ | GPBDAT    | Bit    | Description                                                                  |  
 25 @ |-----------|--------|------------------------------------------------------------------------------|  
 26 @ | GPB[10:0] | [10:0] | When the port is configured as input port, the corresponding bit is the pin  |  
 27 @ |           |        | state. When the port is configured as output port, the pin state is the same |  
 28 @ |           |        | as the corresponding bit. When the port is configured as functional pin, the |  
 29 @ |           |        | undefined value will be read.                                                |  
 30 @ |___________|________|______________________________________________________________________________|  
 31 
 32 @  ___________________________________________________________________________________________________ 
 33 @ | GPBUP     | Bit    | Description                                                                  |  
 34 @ |-----------|--------|------------------------------------------------------------------------------|  
 35 @ | GPB[10:0] | [10:0] | 0: The pull up function attached to the corresponding port pin is enabled.   |  
 36 @ |           |        | 1: The pull up function is disabled.                                         |  
 37 @ |___________|________|______________________________________________________________________________|  
 38 
 39 @ The ARM microprocessor has 16 general-purpose registers.  
 40 @ THUMB has eight general-purpose registers, R0-R7, and access to the high registers, R8-R15.   
 41 
 42 @ The ARM Instruction Set  
 43 @  ________________________________________________________  
 44 @ | Mnemonic | Instruction               | Action          |  
 45 @ |----------|---------------------------|-----------------|  
 46 @ | LDR      | Load register from memory | Rd: = (address) |  
 47 @ |----------|---------------------------|-----------------|  
 48 @ | MOV      | Move register or constant | Rd: = Op2       |  
 49 @ |----------|---------------------------|-----------------|  
 50 @ | STR      | Store register to memory  | <address>: = Rd |  
 51 @ |__________|___________________________|_________________|  
 52 
 53 .text  
 54 .global _start  
 55 
 56 _start:  
 57 
 58     @ following three instructions set the GBPCON  
 59 
 60     @ load register R0 from addr 0x56000010, it's GPBCON register.  
 61     LDR R0,=0x56000010  
 62 
 63     @ move immediate value 0x00015400 to register R1,  
 64     @ it's value is 0000_0000_0000_00_01_01_01_01_00_00_00_00_00 in binary,  
 65     @ that is, GPB5, GPB6, GPB7 and GPB8 all set to 01, function as output.  
 66     MOV R1,#0x00015400 
 67 
 68     @ store register R1 to memory at addr R0, that is, set GPBCON.  
 69     STR R1,[R0] 
 70
 71 
 72     @ following three instructions set the GBPDAT  
 73 
 74     @ load register R0 from addr 0x56000014, it's GPBDAT register.  
 75     LDR R0,=0x56000014 
 76 
 77     @ move immediata value to register R1,  
 78     @ it's value is 0000_0000_0000_0000_0000_000x_xxx0_0000 in binary,  
 79     @ 0x00000000 GPB5/6/7/8=0/0/0/0 all on 
 80     @ 0x000001e0 GPB5/6/7/8=1/1/1/1 all off 
 81     @ 0x000001c0 GPB5/6/7/8=0/1/1/1 only LED_1 on xxx1_110x 
 82     @ 0x000001a0 GPB5/6/7/8=0/1/1/1 only LED_2 on xxx1_101x 
 83     @ 0x00000160 GPB5/6/7/8=0/1/1/1 only LED_3 on xxx1_011x 
 84     @ 0x000000e0 GPB5/6/7/8=0/1/1/1 only LED_4 on xxx0_111x 
 85     MOV R1,#0x000000e0 
 86 
 87     @ store register R1 to memory at addr R0, that is, set GPBDAT.  
 88     STR R1,[R0] 
 89 
 90 MAIN_LOOP:  
 91     B   MAIN_LOOP   

  1 # file  : Makefile 
  2 # date  : 02-01-2013 
  3 # author: asicer@live.cn 
  4 
  5 led_on.bin : led_on.S 
  6     arm-linux-gcc -g -c -o led_on.o led_on.S 
  7     arm-linux-ld -Ttext 0x0000000 -g led_on.o -o led_on_elf 
  8     arm-linux-objcopy -O binary -S led_on_elf led_on.bin 
  9 clean: 
 10     rm -f   led_on.bin led_on_elf *.o 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值