科技学科吧 关注:12贴子:81
  • 2回复贴,共1

51单片机实现简单的流水灯功能

只看楼主收藏回复

应用C语言来进行编程,延迟时间为5000ms
#include <REGX52.H>
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<0;j++);
}
main()
{
unsigned char LEDIndex = 0;
bit LEDDirection = 1;
while(1)
{
if(LEDDirection)
P2 = ~(0x01<<LEDIndex);
else
P0 = ~(0x80>>LEDIndex);
if(LEDIndex==7)
LEDDirection = !LEDDirection;
LEDIndex = (LEDIndex+1)%8;
Delay1ms(5000);
}
}


IP属地:浙江1楼2014-05-27 22:48回复
    逗比……


    IP属地:贵州来自Android客户端2楼2014-05-28 19:43
    收起回复