LED 灯控制的C代码如下:
- /* Copyright (C), 2010.
- File name : led.c
- Author :
- version : V1.0
- Date : 2010-6-23
- Description : led module function implement
- History :
- */
- #include "2440addr.h"
- #include "led.h"
- /*
- Function name : led_init
- Description : the initialization of led
- Input parameter : none
- Return : none
- Others : none
- */
- void led_init(void)
- {
- volatile unsigned int val;
- val = rGPFCON;
- val &= ~((3<<14)|(3<<12)|(3<<10)|(3<<8));
- val |= ((1<<14)|(1<<12)|(1<<10)|(1<<8));//01010101
- rGPFCON = val;
- val = rGPFUP;
- val |= (1<<7)|(1<<6)|(1<<5)|(1<<4);
- rGPFUP = val;
- val = rGPFDAT;
- val |= (1<<7)|(1<<6)|(1<<5)|(1<<4);
- rGPFDAT = val;
- }
- /*
- Function name : led_concrol
- Description : control the led
- Input parameter : the int value -- lednumber and ledstatus
- Return : none
- Others : none
- */
- void led_concrol( int lednumber, int ledstatus)
- {
- switch(lednumber)
- {
- case LED4:
- {
- if(ON==ledstatus)
- {
- rGPFDAT &= ~(1<<4); //0001 0000 1110 1111
- }
- else
- {
- rGPFDAT |= (1<<4);
- }
- break;
- }
- case LED3:
- {
- if(ON==ledstatus)
- {
- rGPFDAT &= ~(1<<5); //0010 0000
- }
- else
- {
- rGPFDAT |= (1<<5);
- }
- break;
- }
- case LED2:
- {
- if(ON==ledstatus)
- {
- rGPFDAT &= ~(1<<6);
- }
- else
- {
- rGPFDAT |= (1<<6);
- }
- break;
- }
- case LED1:
- {
- if(ON==ledstatus)
- {
- rGPFDAT &= ~(1<<7);
- }
- else
- {
- rGPFDAT |= (1<<7);
- }
- break;
- }
- case LEDALL:
- {
- if(ON==ledstatus)
- {
- rGPFDAT &= ~(15<<4);// 11110000
- }
- else
- {
- rGPFDAT |= (15<<4);
- }
- break;
- }
- }
- }
- /*
- Function name : Delay
- Description : Delay the time
- Input parameter : the int value -- time
- Return : none
- Others : none
- */
- void Delay(int time)
- {
- int i,j;
- for(i=0;i<time;i++)
- {
- for(j=0;j<time;j++)
- ;
- }
- }
相关头文件 led.h 的代码如下:
- #ifndef _LED_H
- #define _LED_H
- #define LEDALL 0
- #define LED1 1
- #define LED2 2
- #define LED3 4
- #define LED4 3
- #define ON 1
- #define OFF 0
- extern void led_init(void);
- extern void led_concrol( int lednumber,int ledstatus);
- extern void Delay(int time);
- #endif
执行代码后生成的 .bin 文件 ,通过串口工具 DWN 将 .bin 文件烧写到开发板上,就会产生跑马灯的效果!!