做一个裸机程序,点亮LED灯,想要达到使得LED灯闪烁的效果,
但是用下面的程序生成的bin文件,下载到
开发板,为什么LED1一直亮,而不闪烁?
C代码如下:
- #define GPFCON (*(volatile unsigned long *)0x56000050)
- #define GPFUP (*(volatile unsigned long *)0x56000058)
- #define GPFDAT (*(volatile unsigned long *)0x56000054)
- #define GPF0_Out (1<<(0*2))
- #define GPF1_Out (1<<(1*2))
- #define GPF2_Out (1<<(2*2))
- #define GPF3_Out (1<<(3*2))
- #define LED1_ON (GPFDAT &= (~(1<<0)));
- #define LED1_OFF (GPFDAT |= (1<<0));
- #define LED2_ON (GPFDAT &= (~(1<<1)));
- #define LED2_OFF (GPFDAT |= (1<<1));
- #define LED3_ON (GPFDAT &= (~(1<<2)));
- #define LED3_OFF (GPFDAT |= (1<<2));
- #define LED4_ON (GPFDAT &= (~(1<<3)));
- #define LED4_OFF (GPFDAT |= (1<<3));
- void Delay(void);
- int main()
- {
- GPFCON = GPF0_Out|GPF1_Out|GPF2_Out|GPF3_Out; //将LED1,2,3,4对应的GPF0,1,2,3的三个引脚设为输出
-
- //先熄灭所有的LED灯
- LED1_OFF;
- LED2_OFF;
- LED3_OFF;
- LED4_OFF;
-
- while(1)
- {
- Delay();
- LED1_ON;//单独运行该行代码,可以点亮LED1
- Delay();
- LED1_OFF;//单独运行该行代码,可以熄灭LED1
- }
-
- return 0;
- }
- void Delay(void)
- {
- volatile unsigned long MaxNum1 = 9000;
- volatile unsigned long MaxNum2 = 9000;
- volatile unsigned long MaxNum3 = 9000;
- volatile unsigned long i = 0;
- volatile unsigned long j = 0;
- volatile unsigned long k = 0;
-
- for(i=0;i<MaxNum1;i++)
- {
- for(j=0;j<MaxNum2;j++)
- {
- for(k=0;k<MaxNum3;k++)
- {
- ;
- }
- }
- }
-
- return;
- }
复制代码
你这个很明显是延时时间不够长,身边要是有示波器可以测试下对应的引脚输出,应该有方波输出
一周热门 更多>