【028】正反流水灯2007-05-02 16:18:00
【评论】
【打印】
【字体:大 中 小】
本文链接:http://blog.pfan.cn/wentao/25471.html
org 0000h
ajmp start
start: mov a,#0xfe
mov 30h,#7
left: mov p1,a
lcall delay100ms
rl a
djnz 30h,left
mov 30h,#7
right: mov p1,a
lcall delay100ms
rr a
djnz 30h,right
ajmp start
delay100ms: mov r5,#195
temp: mov r6,#255
djnz r6,$
djnz r5,temp
ret
end
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
void delay_ms(uchar ms);
void main()
{
uchar led;
uchar i;
while(1)
{
led = 0xfe;
for(i = 0; i < 7; i++)
{
P1 = led;
delay_ms(100);
led = _crol_(led, 1);
}
for(i = 0; i < 7; i++)
{
P1 = led;
delay_ms(100);
led = _cror_(led, 1);
}
}
}
void delay_ms(uchar ms)
{
uchar i;
while(ms--)
for(i = 0; i < 124; i++);
}
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
void delay_ms(uchar ms);
void main()
{
uchar led;
uchar i;
while(1)
{
led = 0x01;
for(i = 0; i < 7; i++)
{
P1 = ~led;
delay_ms(100);
led = led << 1;
}
for(i = 0; i < 7; i++)
{
P1 = ~led;
delay_ms(100);
led = led >> 1;
}
}
}
void delay_ms(uchar ms)
{
uchar i;
while(ms--)
for(i = 0; i < 124; i++);
}
阅读(4276) | 评论(1)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论