The lighting led s3c2440

Led operation principle is connected to the CPU pin GPIO, GPIO specific operation which is required to view the schematic. GPIO configured to output a corresponding mode, and sets the corresponding bit in the GPIO lighting led to a low level, contrast, setting the corresponding bit is high then led off

Wei to Dongshan JZ2440, for example, schematics:

3 it can be seen led respectively GPF4, GPF5, GPF6 to the output state, see Handbook chip:

 

 

That GPFCON register address 0x56000050, GPFDAT register address 0x56000054, GPF4, GP5, respectively corresponding to the configuration GPF6 8-9,10-12,12-13 bits, these need to be set to 6 consecutive bits can configure 010101 GPF4-6 set to the output mode, then the control bits GPFDAT 4-6, lighting 0, 1 off.

The following code, compiled:

. 1  .global _start
 2  
. 3  _start: 
. 4      // Close the watchdog
 . 5      LDR r0 of, = 0x53000000
 . 6      LDR R1, = 0 
. 7      STR R1, [r0 of]
 . 8    // initialize stack 
. 9 MOV SP, # 4096
10 BL main

 

c Code:

  1 #define GPFCON  (*(volatile unsigned int *) 0x56000050)
  2 #define GPFDAT  (*(volatile unsigned int *) 0x56000054)
  3 
  4 
  5 void delay()
  6 {
  7     volatile int d = 100000;
  8     while(d--);
  9 }
 10 
 11 void led_all_off()
 12 {
 13     GPFDAT |= (7 << 4); 
 14 }
 15 
 16 void led_all_on()
 17 {
 18     
 19     GPFDAT &= ~(7 << 4);
 20 }
 21 
 22 
 23 void led_light_one(int index)
 24 {
 25     GPFDAT &= ~(1 << (4 + index));
 26 }
 27 
 28 void led_off_one(int index)
 29 {
 30     GPFDAT |= (1 << (4 + index));
 31 }
 32 
 33 void config_gpio()
 34 {
 35     //清0
 36     GPFCON    &= ~ ((3 << 8) | (3 << 10)    | (3 << 12));
 37     //设置1
 38     GPFCON    |= ((1 << 8) | (1    << 10)    | (1 << 12));
 39 }
 40 
 41 void horse_left()
 42 {
 43     int i;
 44     for(i =0; i < 3;i ++)
 45     {
 46         led_light_one(i);
 47         delay();
 48         led_off_one(i);
 49         
 50     }
 51 }
 52 
 53 void horse_right()
 54 {
 55     int i;
 56     for(i =3; i >= 0;i --)
 57     {
 58         led_light_one(i);
 59         delay();
 60         led_off_one(i);
 61     }
 62 }
 63 
 64 void horse_race()
 65 {
 66     int i;
 67     for(i =0 ; i < 3;i ++)
 68     {
 69         horse_left();
 70         horse_right();
 71     }
 72 } 
 73 
 74 
 75 void twinkle()
 76 {
 77     int i;
 78     led_all_off();
 79     for(i =0 ; i < 3;i ++)
 80     {
 81         led_all_on();
 82         delay();
 83         led_all_off();
 84         delay();
 85     }
 86 }
 87 
 88 void one_by_one_on()
 89 {
 90     int i;
 91     for(i =0; i < 3;i ++)
 92     {
 93         led_light_one(i);
 94         delay();
 95     }
 96 }
 97 
 98 void one_by_one_off()
 99 {
100     int i;
101     for(i =3; i >= 0;i --)
102     {
103         led_off_one(i);
104         delay();
105     }
106 }
107 void one_by_one()
108 {
109     int i;
110     led_all_off();
111     for(i =0 ; i < 3;i ++)
112     {
113         one_by_one_on();
114         one_by_one_off();
115     }
116 }
117 
118 int main()
119 {
120     config_gpio();
121     while(1)
122     {
123         twinkle();
124         horse_race();
125         one_by_one();
126     }
127     
128     return 0;
129 }

Makefile

all:
	arm-linux-gcc -O3 -c -o led.o led.S 
	arm-linux-gcc -O3 -c -o main.o main.c
	arm-linux-ld -Ttext 0 led.o main.o -o led.elf
	arm-linux-objcopy -O binary -S led.elf led.bin 

clean:
	rm led.o led.ef led.bin -rf

 

此代码实现了3个led同时闪烁,流水灯。

 

Guess you like

Origin www.cnblogs.com/mcran/p/10975376.html