51单片机 跑马灯程序
发布网友
发布时间:2022-04-23 14:03
我来回答
共4个回答
热心网友
时间:2023-10-17 05:43
org 0000h
jmp start
org 0030h
start:
mov p0,#11111110b ; 此时第一个灯亮
call t10s
mov p0,#11111101b ;此时第二个灯亮
call t10s
mov p0,#11111011b
call t10s
mov p0,#11110111b
call t10s
mov p0,#11101111b
call t10s
mov p0,#11011111b
call t10s
jmp start ;此处跳到开始 即 循环
;延时子程序10秒=250usX2X200X100
t10s:mov r5,#100
lpr5:mov r6,#200
lpr6:mov r7,#250
djnz r7,$
djnz r6,lpr6
djnz r5,lpr5
ret
end
把灯的正极接电源正极 即vcc 负极分别接p0.0-p0.5
此时 给p0 送0灯就亮 1灯就不亮
程序已经过调试 可用
仿真如下:
热心网友
时间:2023-10-17 05:43
用汇编语言实现的程序如下。
本程序已经经过在Proteus上验证、仿真成功。
ORG 0000H
SJMP _START
ORG 0050H
_START:
MOV P1, #0xFE
CALL DL10S
MOV P1, #0xFD
CALL DL10S
MOV P1, #0xFB
CALL DL10S
MOV P1, #0xF7
CALL DL10S
MOV P1, #0xEF
CALL DL10S
MOV P1, #0xDF
CALL DL10S
SJMP _START
DL10S:
MOV R5, #100
_DELAY100MS:
MOV R6, #200 ;1T
DL250T:
MOV R7, #250 ;1T
D2:
DJNZ R7, D2 ;2T, 原地转移250遍, 共用500T
DJNZ R6, DL250T ;2T, 转移200遍
DJNZ R5, _DELAY100MS
RET ;2T
END
热心网友
时间:2023-10-17 05:43
#include <reg51.h>
void main()
{
unsigned char ch[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};/*0--9*/
unsigned char i,j;
j=1;
P2=P2&0x00;
P1=0xef;
P0=0xa4;
while(1)
{
i=P1;
i=i;
if(i==0xee)
{
P0=0xb0;
}
}
}
热心网友
时间:2023-10-17 05:44
c还是汇编呀?
#include<reg51.h>
void delay(void);
void main()
{
do{
P1=0xFE;
delay();
P1=0xFD;
delay();
P1=0xFB;
delay();
P1=0xF7;
delay();
P1=0xEF;
delay();
P1=0xDF;
delay();
P1=0xBF;
delay();
P1=0x7F;
delay();
}while(1);
}
void delay()
{
unsigned int x=60000;
do{ x--;
}while(x>1);
}
热心网友
时间:2023-10-17 05:43
org 0000h
jmp start
org 0030h
start:
mov p0,#11111110b ; 此时第一个灯亮
call t10s
mov p0,#11111101b ;此时第二个灯亮
call t10s
mov p0,#11111011b
call t10s
mov p0,#11110111b
call t10s
mov p0,#11101111b
call t10s
mov p0,#11011111b
call t10s
jmp start ;此处跳到开始 即 循环
;延时子程序10秒=250usX2X200X100
t10s:mov r5,#100
lpr5:mov r6,#200
lpr6:mov r7,#250
djnz r7,$
djnz r6,lpr6
djnz r5,lpr5
ret
end
把灯的正极接电源正极 即vcc 负极分别接p0.0-p0.5
此时 给p0 送0灯就亮 1灯就不亮
程序已经过调试 可用
仿真如下:
热心网友
时间:2023-10-17 05:43
用汇编语言实现的程序如下。
本程序已经经过在Proteus上验证、仿真成功。
ORG 0000H
SJMP _START
ORG 0050H
_START:
MOV P1, #0xFE
CALL DL10S
MOV P1, #0xFD
CALL DL10S
MOV P1, #0xFB
CALL DL10S
MOV P1, #0xF7
CALL DL10S
MOV P1, #0xEF
CALL DL10S
MOV P1, #0xDF
CALL DL10S
SJMP _START
DL10S:
MOV R5, #100
_DELAY100MS:
MOV R6, #200 ;1T
DL250T:
MOV R7, #250 ;1T
D2:
DJNZ R7, D2 ;2T, 原地转移250遍, 共用500T
DJNZ R6, DL250T ;2T, 转移200遍
DJNZ R5, _DELAY100MS
RET ;2T
END
热心网友
时间:2023-10-17 05:43
#include <reg51.h>
void main()
{
unsigned char ch[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};/*0--9*/
unsigned char i,j;
j=1;
P2=P2&0x00;
P1=0xef;
P0=0xa4;
while(1)
{
i=P1;
i=i;
if(i==0xee)
{
P0=0xb0;
}
}
}
热心网友
时间:2023-10-17 05:44
c还是汇编呀?
#include<reg51.h>
void delay(void);
void main()
{
do{
P1=0xFE;
delay();
P1=0xFD;
delay();
P1=0xFB;
delay();
P1=0xF7;
delay();
P1=0xEF;
delay();
P1=0xDF;
delay();
P1=0xBF;
delay();
P1=0x7F;
delay();
}while(1);
}
void delay()
{
unsigned int x=60000;
do{ x--;
}while(x>1);
}