野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9308|回复: 3

寄存器LED闪烁

[复制链接]
发表于 2019-5-17 15:39:32 | 显示全部楼层 |阅读模式
[mw_shl_code=c,true]//蓝灯
int main(void)
{
        unsigned int i = 1000;
        *(unsigned int *)0X40021018 |= (1<<3);
        *(unsigned int *)0X40010C00 |= (1<<4);
        while(1)
        {
                *(unsigned int *)0X40010C0C &= ~(1<<1);
                while(i--);
                *(unsigned int *)0X40010C0C |= (1<<1);
        }
}[/mw_shl_code]

请问怎么不能实现小灯闪烁,一直亮
回复

使用道具 举报

发表于 2019-5-17 19:32:24 | 显示全部楼层
你的 while(i--);  每次都只执行了那个;空语句   

然后,就算你改正为了 while(i--)  也是只是一直执行后面那条语句  

回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2019-5-17 20:26:27 | 显示全部楼层
本帖最后由 saber 于 2019-5-17 20:31 编辑
WishWish 发表于 2019-5-17 19:32
你的 while(i--);  每次都只执行了那个;空语句   

然后,就算你改正为了 while(i--)  也是只是一直执行 ...

void delay1s(void)   //误差 -1us
{
    unsigned char a,b,c,n;
    for(c=205;c>0;c--)
        for(b=171;b>0;b--)
            for(a=8;a>0;a--);
    for(n=1;n>0;n--);
}
int main(void)
{
                *(unsigned int *)0X40021018 |= (1<<3);
                *(unsigned int *)0X40010C00 |= (1<<4);
          while(1)
          {
                        *(unsigned int *)0X40010C0C &= ~(1<<1);
                        delay1s();
                        *(unsigned int *)0X40010C0C |= (1<<1);
     }
}
这么写也不行  我有点迷
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-5-17 20:31:21 | 显示全部楼层
saber 发表于 2019-5-17 20:26
void delay1s(void)   //误差 -1us
{
    unsigned char a,b,c,n;

我懂了  我这少了个延时 感谢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-5-15 02:15 , Processed in 0.048938 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表