S3C2440 GPIO (使用miniARM 2440)


S3C2440 GPIO (使用miniARM 2440):

  1. #ifndef LDE_H   
  2. #define LED_H   
  3.   
  4. #include "2440addr.h"   
  5. //GPB 有 PIN0 到 PIN10 共11个引脚   
  6. //rGPBCON 寄存器的每两个位控制一个IO的输入输出方向   
  7. //其中00表示输入   
  8. //    01表示输出   
  9. //    10为使用第二功能   
  10. //    11为出厂保留   
  11. //***************************************************   
  12.   
  13. //功能:流水灯   
  14. //接口:      GPB5 -> LED1   低 灯亮   
  15. //            GPB6 -> LED2   
  16. //            GPB7 -> LED3   
  17. //            GPB8 -> LED4   
  18. //            GPB0 -> 蜂鸣器 高 蜂鸣器响   
  19. //***************************************************   
  20. extern void delay(U32 tt);  
  21. extern void BeeperInit(void);  
  22. extern void BeeperControl(U8 flag);  
  23. extern void LedInit(void);  
  24. extern void LedControl(U8 led,U8 flag );  
  25. #endif  

 

  1. #include "led.h"   
  2.   
  3. void delay(U32 tt)  
  4. {  
  5.      U32 i;  
  6.    for(;tt>0;tt--)  
  7.    {  
  8.      for(i=0;i<10000;i++){}  
  9.    }  
  10.   
  11. }  
  12. void BeeperInit(void)  
  13. {  
  14.     //   
  15.     rGPBCON &= 0xfffffffc; //清除   
  16.     rGPBCON |= 0x00000001; //置低位为0001,使PIN0输出   
  17. }  
  18. void BeeperControl(U8 flag)  
  19. {  
  20.     if(flag)  
  21.         rGPBDAT |=0x00000001;  
  22.     else  
  23.         rGPBDAT &=0xfffffffe;  
  24. }  
  25. void LedInit(void)  
  26. {  
  27.     //设置GPB PIN5678 输出   
  28.     rGPBCON &= 0xfffc03ff;  
  29.     rGPBCON |= (0x00000001<<10) |(0x00000001<<12)|(0x00000001<<14)|(0x00000001<<16);  
  30.     //rGPBCON |= 0x155555;   
  31. }  
  32. void LedControl(U8 led,U8 flag )  
  33. {  
  34.     if(flag==0)  
  35.         rGPBDAT &= ~(0x00000001<<(led+4));  
  36.     else  
  37.         rGPBDAT |= (0x00000001<<(led+4));       
  38. }  

相关内容