【ARM】s3c2410之gpio调试

调试准备

   编译工具:MDK470a

   开发板:s3c2410

   调试方式:经mdk编译后得到 hex文件,用hex2bin工具转换成bin文件,通过usb下载,在DNW上观察


<Code-1>

 
 
  1. #define GPFCON (*(volatile unsigned long*)0x56000050)

  2. #define GPFDAT (*(volatile unsigned long*)0x56000054)

  3. //===PORT F GROUP

  4. //端口:     GPF7      GPF6     GPF5     GPF4     GPF3     GPF2        GPF1     GPF0

  5. //信号:     LED_1     LED_2    LED_3    LED_4    FS2_INT  GPLD_INT1   KEY_INT  BUT_INT1

  6. //设置属性:  output    output   output   output   EINT3    EINT2       EINT1    EINT0

  7. //二进制值:  01        01       01       01       00       00          00       00

  8. int i,nout;  

  9. int Main()  

  10. {  

  11.       GPFCON = 0x00005500;  

  12. //     GPFDAT = 0x00000050;    

  13.            nout=0x000000F0;  

  14. while(1)  

  15.            {  

  16.                GPFDAT=nout & 0x00000070;    

  17. for(i=0;    i<1000000;  i++);  

  18.                GPFDAT=nout & 0x00000030;    

  19. for(i=0;    i<1000000;  i++);  

  20.                GPFDAT=nout & 0x00000010;  

  21. for(i=0;    i<1000000;  i++);  

  22.                GPFDAT=nout & 0x00000000;    

  23. for(i=0;    i<1000000;  i++);  

  24. //led();

  25.            }      

  26. //return(0);

  27. }  

现象:LED1~4按等时间间隙顺序循环亮灭


<Code-2>

 
 
  1. #define GPFCON (*(volatile unsigned long*)0x56000050)

  2. #define GPFDAT (*(volatile unsigned long*)0x56000054)


  3. int i,nout;

  4. void led(void)

  5. {

  6.    GPFDAT=nout & 0x00000070;  

  7. for(i=0;    i<1000000;  i++);

  8.    GPFDAT=nout & 0x00000030;  

  9. for(i=0;    i<1000000;  i++);

  10.    GPFDAT=nout & 0x00000010;  

  11. for(i=0;    i<1000000;  i++);

  12.    GPFDAT=nout & 0x00000000;  

  13. }

  14. int Main()

  15. {

  16.       GPFCON = 0x00005500;

  17. //     GPFDAT = 0x00000050;

  18.            nout=0x000000F0;

  19. while(1)

  20.            {

  21.                GPFDAT=nout & 0x00000070;   //μãááLED1

  22. for(i=0;    i<1000000;  i++);

  23.                GPFDAT=nout & 0x00000030;   //μãááLED1/LED2

  24. for(i=0;    i<1000000;  i++);

  25.                GPFDAT=nout & 0x00000010;   //μãááLED1/LED2/LED3

  26. for(i=0;    i<1000000;  i++);

  27.                GPFDAT=nout & 0x00000000;   //μãááLED1/LED2/LED3/LED4

  28. for(i=0;    i<1000000;  i++);

  29. //led();

  30.            }    

  31. //return(0);

  32. }

现象:LED1与LED3几乎同时亮,一小段时间后LED2亮,一段时间后LED4亮,然后不再循环

注意:Code-2只是在Code-1的前面加了一个函数,但是并没有调用


<Code-3>

 
 
  1. #define GPFCON (*(volatile unsigned long*)0x56000050)

  2. #define GPFDAT (*(volatile unsigned long*)0x56000054)


  3. int i,nout;

  4. void led(void)

  5. {

  6.    GPFDAT=nout & 0x00000070;  

  7. for(i=0;    i<1000000;  i++);

  8.    GPFDAT=nout & 0x00000030;  

  9. for(i=0;    i<1000000;  i++);

  10.    GPFDAT=nout & 0x00000010;  

  11. for(i=0;    i<1000000;  i++);

  12.    GPFDAT=nout & 0x00000000;  

  13. }

  14. int Main()

  15. {

  16.       GPFCON = 0x00005500;

  17. //     GPFDAT = 0x00000050;

  18.            nout=0x000000F0;

  19. while(1)

  20.            {

  21. /*

  22.                GPFDAT=nout & 0x00000070;   //μãááLED1

  23.                for(i=0;    i<1000000;  i++);

  24.                GPFDAT=nout & 0x00000030;   //μãááLED1/LED2

  25.                for(i=0;    i<1000000;  i++);

  26.                GPFDAT=nout & 0x00000010;   //μãááLED1/LED2/LED3

  27.                for(i=0;    i<1000000;  i++);

  28.                GPFDAT=nout & 0x00000000;   //μãááLED1/LED2/LED3/LED4

  29.                for(i=0;    i<1000000;  i++);

  30.                */

  31.                led();

  32.            }    

  33. //return(0);

  34. }

现象:和Code-2现象一样


<Code-4>

 
 
  1. #define rGPFCON (*(volatile unsigned *)0x56000050)  

  2. #define rGPFDAT (*(volatile unsigned *)0x56000054)

  3. //#define rGPFUP  (*(volatile unsigned *)0x56000058)  

  4. void port_init(void)    

  5. {


  6.    rGPFCON=0x00005500;

  7. //  rGPFUP=0x0000ff;    

  8. }

  9. void led_on(void)  

  10. {

  11. int i,nout;

  12.    nout=0x000000F0;

  13.    rGPFDAT=nout & 0x00000070;  

  14. for(i=0;    i<100000;   i++);

  15.    rGPFDAT=nout & 0x00000030;  

  16. for(i=0;    i<100000;   i++);

  17.    rGPFDAT=nout & 0x00000010;  

  18. for(i=0;    i<100000;   i++);

  19.    rGPFDAT=nout & 0x00000000;  

  20. for(i=0;    i<100000;   i++);

  21. }

  22. /*

  23. void led_off(void)  

  24. {

  25.    int i,nout;

  26.    nout=0;

  27.    rGPFDAT=0;

  28.    for(i=0;    i<100000;   i++);

  29.    rGPFDAT=nout | 0x00000080;      

  30.    for(i=0;    i<100000;   i++);

  31.    rGPFDAT=nout | 0x00000040;      

  32.    for(i=0;    i<100000;   i++);

  33.    rGPFDAT=nout | 0x00000020;  

  34.    for(i=0;    i<100000;   i++);

  35.    rGPFDAT=nout | 0x00000000;  

  36.    for(i=0;    i<100000;   i++);

  37. }

  38. void led_on_off(void)  

  39. {

  40.    int i;

  41.    rGPFDAT=0;  

  42.    for(i=0;    i<100000;   i++);

  43.    rGPFDAT=0x000000F0;

  44.    for(i=0;    i<100000;   i++);

  45. }

  46. */

  47. int main(void)

  48. {

  49. //  port_init();

  50.        rGPFCON=0x00005500;

  51. while(1)

  52.    {

  53.        led_on();

  54. //      led_off();

  55. //      led_on_off();

  56.    }

  57. return(0);

  58. }

  59. /*

  60. int i,nout;

  61. void led(void)

  62. {

  63.    GPFDAT=nout & 0x00000070;  

  64.    for(i=0;    i<1000000;  i++);

  65.    GPFDAT=nout & 0x00000030;  

  66.    for(i=0;    i<1000000;  i++);

  67.    GPFDAT=nout & 0x00000010;  

  68.    for(i=0;    i<1000000;  i++);

  69.    GPFDAT=nout & 0x00000000;  

  70. }

  71. int Main()

  72. {

  73.       GPFCON = 0x00005500;

  74. //     GPFDAT = 0x00000050;

  75.            nout=0x000000F0;

  76.            while(1)

  77.            {

  78.                GPFDAT=nout & 0x00000070;  

  79.                for(i=0;    i<1000000;  i++);

  80.                GPFDAT=nout & 0x00000030;  

  81.                for(i=0;    i<1000000;  i++);

  82.                GPFDAT=nout & 0x00000010;  

  83.                for(i=0;    i<1000000;  i++);

  84.                GPFDAT=nout & 0x00000000;  

  85.                for(i=0;    i<1000000;  i++);

  86.                //led();

  87.            }

  88.       //return(0);

  89. }

  90. */

现象:下载完成后,先y运行时开发板直接重启


分析

目前看来达到效果的就只有Code-1,我在源码中是有很多注释的,因为粘贴过来都是乱码,所以就全部删掉了。

Code-1与Code-2在PC平台上看应该是一样的,但是运行结果大相径庭,应该不是开发板缓存引起的,估计是编译器动了手脚

<1>可能MDK对代码作了优化,应该不是链接器,可能是编译的时候

<2>Code-4致使板子直接重启,原因是什么呢?

这两个个问题好像现在还搞不定,先放一放吧,下次问老师,或者大手帮忙解决下啊……



本文出自 “成鹏致远” 博客,请务必保留此出处http://infohacker.blog.51cto.com/6751239/1190765

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值