数码相框项目模块【一】 跑马灯

来源:互联网 发布:网络专线是什么意思 编辑:程序博客网 时间:2024/06/02 17:39


LED 灯控制的C代码如下: 

Code:
  1. /*  Copyright (C), 2010.  
  2. File  name  :   led.c  
  3. Author      :    
  4. version     :   V1.0  
  5. Date         :   2010-6-23  
  6. Description :  led module function  implement    
  7. History     :           
  8. */  
  9.   
  10. #include "2440addr.h"   
  11. #include "led.h"   
  12.   
  13. /*  
  14. Function  name  :  led_init  
  15. Description     :  the initialization of led  
  16. Input parameter :  none  
  17. Return          :  none       
  18. Others          :  none                                            
  19. */  
  20.   
  21. void led_init(void)   
  22. {   
  23.     volatile unsigned int val;   
  24.     val = rGPFCON;   
  25.     val &= ~((3<<14)|(3<<12)|(3<<10)|(3<<8));     
  26.     val |=  ((1<<14)|(1<<12)|(1<<10)|(1<<8));//01010101  
  27.     rGPFCON = val;   
  28.        
  29.     val = rGPFUP;   
  30.     val |= (1<<7)|(1<<6)|(1<<5)|(1<<4);   
  31.     rGPFUP = val;   
  32.        
  33.     val = rGPFDAT;   
  34.     val |= (1<<7)|(1<<6)|(1<<5)|(1<<4);   
  35.     rGPFDAT = val;   
  36. }   
  37.   
  38. /*  
  39. Function  name  :   led_concrol  
  40. Description     :   control the led  
  41. Input parameter :   the int value -- lednumber and ledstatus 
  42. Return          :   none          
  43. Others          :   none                                           
  44. */  
  45.   
  46. void led_concrol( int lednumber, int ledstatus)   
  47. {   
  48.     switch(lednumber)   
  49.     {   
  50.         case LED4:   
  51.         {   
  52.             if(ON==ledstatus)   
  53.             {   
  54.                 rGPFDAT &= ~(1<<4);    //0001 0000   1110 1111  
  55.             }   
  56.             else  
  57.             {   
  58.                 rGPFDAT |= (1<<4);       
  59.             }   
  60.             break;   
  61.         }   
  62.         case LED3:   
  63.         {   
  64.             if(ON==ledstatus)   
  65.             {   
  66.                 rGPFDAT &= ~(1<<5);    //0010 0000  
  67.             }   
  68.             else  
  69.             {   
  70.                 rGPFDAT |= (1<<5);    
  71.             }   
  72.                 break;   
  73.         }   
  74.         case LED2:   
  75.         {   
  76.             if(ON==ledstatus)   
  77.             {   
  78.                 rGPFDAT &= ~(1<<6);    
  79.             }   
  80.             else  
  81.             {   
  82.                 rGPFDAT |= (1<<6);    
  83.             }   
  84.                 break;   
  85.         }   
  86.         case LED1:   
  87.         {   
  88.             if(ON==ledstatus)   
  89.             {   
  90.                 rGPFDAT &= ~(1<<7);    
  91.             }   
  92.             else  
  93.             {   
  94.                 rGPFDAT |= (1<<7);    
  95.             }   
  96.                 break;   
  97.         }   
  98.         case LEDALL:   
  99.         {   
  100.             if(ON==ledstatus)   
  101.             {   
  102.                 rGPFDAT &= ~(15<<4);// 11110000  
  103.             }   
  104.             else  
  105.             {   
  106.                 rGPFDAT |= (15<<4);    
  107.             }   
  108.                 break;   
  109.         }   
  110.     }   
  111. }   
  112.   
  113. /*  
  114. Function  name  :   Delay  
  115. Description     :   Delay the time  
  116. Input parameter :   the int value -- time 
  117. Return          :   none          
  118. Others          :   none                                           
  119. */  
  120.   
  121. void Delay(int time)   
  122. {   
  123.     int i,j;   
  124.     for(i=0;i<time;i++)   
  125.     {   
  126.         for(j=0;j<time;j++)   
  127.         ;   
  128.     }   
  129. }   


相关头文件 led.h 的代码如下:

Code:
  1. #ifndef _LED_H   
  2. #define _LED_H   
  3.   
  4. #define LEDALL 0   
  5. #define LED1   1   
  6. #define LED2   2   
  7. #define LED3   4   
  8. #define LED4   3   
  9.   
  10. #define ON     1   
  11. #define OFF    0   
  12.   
  13. extern void led_init(void);   
  14. extern void led_concrol( int lednumber,int ledstatus);   
  15. extern void Delay(int time);   
  16.   
  17. #endif  

执行代码后生成的 .bin 文件 ,通过串口工具 DWN 将 .bin 文件烧写到开发板上,就会产生跑马灯的效果!!

原创粉丝点击