编写一个跑马灯程序,用89C51单片机的P1.0到P1.7接八个LED

2024-12-12 10:47:30
推荐回答(3个)
回答1:

注意字符表未经验证, 请自行调试

#include
#define uchar unsigned char
#define uint unsigned int
const unsigned char design[16]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x40,

0x20,0x10,0x08,0x04,0x02,0x10,0x00};

void delay_1ms(uint x)
{
uint i,j;
for (j=0;j for (i=0;i<110;i++);

}
void set_led(uint jiange)
{
uchar i;

for (i=0;i<16;i++);
{

P1=design[i];
delay_1ms(jiange);
}

}
void main(void)
{
uint jg_ms;

jg_ms=500;

set_led(jg_ms);
jg_ms=200;
set_led(jg_ms);
jg_ms=500;
set_led(jg_ms);
}

回答2:

改下这个程序就可以了
ORG 0000H
START: LJMP MAIN
MAIN: MOV A, #0FFH
CPL ACC.0
LOOP: MOV P1, A
LCALL DELAY
RL A
LJMP LOOP
ORG 2000H
DELAY: MOV R4, #200
LOOP2: MOV R5, #248
LOOP3: DJNZ R5, LOOP3
DJNZ R4, LOOP2
RET
END

回答3:

注意字符表未经验证,
请自行调试
#include

#define
uchar
unsigned
char
#define
uint
unsigned
int
const
unsigned
char
design[16]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x10,0x00};
void
delay_1ms(uint
x)
{
uint
i,j;
for
(j=0;jfor
(i=0;i<110;i++);
}
void
set_led(uint
jiange)
{
uchar
i;
for
(i=0;i<16;i++);
{
P1=design[i];
delay_1ms(jiange);
}
}
void
main(void)
{
uint
jg_ms;
jg_ms=500;
set_led(jg_ms);
jg_ms=200;
set_led(jg_ms);
jg_ms=500;
set_led(jg_ms);
}