我弄了好久这个LED灯 闪的好快根本看不来任何一中效果 新手狗想哭!

2019-07-18 10:26发布

void Delay(void)
{
unsigned int i,j;
for(i=600;i>0;i--)
{
  for(j=600;j>0;j--)
  ;
}
}

//主函数 程序从这里开始运行
void main(void)
{int k;
unsigned char position=0;
  PORTA = 0xff;
  DDRA = 0xff;
  while(1){
  for(k=0;k<16;k++)
  {
   PORTA = 0xaa;     //1脚为高,0脚为低,0脚灯亮
   Delay();
   Delay();     //延时
   PORTA = 0x55;       //0脚为高,1脚为低,1脚灯亮
   Delay();
    //延时
  }
  for(k=0;k<16;k++)
  {
   PORTA = ~(1<<position);    //1脚为高,0脚为低,0脚灯亮
   if(++position>=8)
   position=0;
   Delay();     //延时
   Delay();
   Delay();
  }
  for(k=0;k<16;k++)
  {
   PORTA = ~(0x80>>position);    //1脚为高,0脚为低,0脚灯亮
   if(++position>=8)
   position=0;
   Delay();     //延时
  Delay();
  Delay();}

    for(k=0;k<16;k++)
  {
   PORTA = rand();
   Delay();
  Delay();}
  }
}




延迟加到10000*10000都不行


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
6条回答
JQ_Lin
2019-07-18 11:07
在程序中通过加入延时、或加长延时、甚至加入断点等措施进行调试,人为地貌似减缓了原有程序的运行速度,让看不清的效果显现出来。 最佳答案

一周热门 更多>