用8051单片机控制八个发光二极管,每隔一个灯亮的左循环程序
答案:2 悬赏:50 手机版
解决时间 2021-11-10 15:38
- 提问者网友:人生佛魔见
- 2021-11-10 06:46
用8051单片机控制八个发光二极管,每隔一个灯亮的左循环程序
最佳答案
- 五星知识达人网友:风格不统一
- 2021-11-10 07:45
; P1口接8个LED.上拉电阻1K
ORG 0000H
AJMP STARTUP
ORG 0030H
STARTUP:
MOV SP,#60H
MOV A,#0AAH
LOOP: MOV P1,A
ACALL DELAY
RLC A
SJMP LOOP; 延时的多少决定灯移动速度的快慢
DELAY:
MOV R7,#5
DL2:
MOV R6,#100
DL1:
MOV R5,#100
DJNZ R5,$
DJNZ R6,DL1
DJNZ R7,DL2
RET END
ORG 0000H
AJMP STARTUP
ORG 0030H
STARTUP:
MOV SP,#60H
MOV A,#0AAH
LOOP: MOV P1,A
ACALL DELAY
RLC A
SJMP LOOP; 延时的多少决定灯移动速度的快慢
DELAY:
MOV R7,#5
DL2:
MOV R6,#100
DL1:
MOV R5,#100
DJNZ R5,$
DJNZ R6,DL1
DJNZ R7,DL2
RET END
全部回答
- 1楼网友:低血压的长颈鹿
- 2021-11-10 09:11
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit key=P3^4;
uchar i,a,keycount;
void delay_ms(uint s) ;
void main()
{
key=1;
P1=0xfe;
a=0xfe;
while(1)
{
if(!key)
{
//keycount =100;
for(i=0;i<100;i++)
{
if(!key)
{
keycount ++;
}
else
{
break;
}
delay_ms(1);
}
//while(!key);
}
if(keycount>=98)
{
//a=0xfe;
keycount =0;
//P1=a;
delay_ms(500) ;
//for(i=0;i<2;i++)
// {
a=_crol_(a,1);//左移
if(a==0xff)a=0xfe;
P1=a;
delay_ms(500) ;
// }
}
}
}
void delay_ms(uint s)
{
uint x;
for(s;s>0;s--)
{
x=98;
while(x--);
}
}
#include
#define uchar unsigned char
#define uint unsigned int
sbit key=P3^4;
uchar i,a,keycount;
void delay_ms(uint s) ;
void main()
{
key=1;
P1=0xfe;
a=0xfe;
while(1)
{
if(!key)
{
//keycount =100;
for(i=0;i<100;i++)
{
if(!key)
{
keycount ++;
}
else
{
break;
}
delay_ms(1);
}
//while(!key);
}
if(keycount>=98)
{
//a=0xfe;
keycount =0;
//P1=a;
delay_ms(500) ;
//for(i=0;i<2;i++)
// {
a=_crol_(a,1);//左移
if(a==0xff)a=0xfe;
P1=a;
delay_ms(500) ;
// }
}
}
}
void delay_ms(uint s)
{
uint x;
for(s;s>0;s--)
{
x=98;
while(x--);
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯