80c51单片机很简单的一个编程

2024-12-16 06:00:04
推荐回答(3个)
回答1:

;以下程序,经过仿真调试,复合要求.
;------------------------------
ORG 0000h
MOV A, #0DFH ;1101 1111
SETB C
R_SHIFT:
MOV P1, A
CALL DL1S
RRC A
JC R_SHIFT
L_SHIFT:
RLC A
MOV P1, A
CALL DL1S
JB ACC.5, L_SHIFT
RRC A
SJMP R_SHIFT
;------------------------------
DELAY1S: ;延时子程序.
; ....... ;细节略.
RET
END

回答2:

ORG 0000H
SJMP START

;

ORG 0030H
START:
MOV A,#01H

MAIN:
RL A
MOV P1,A
LCALL DELAY_1S
RL A
MOV P1,A
LCALL DELAY_1S
RL A
MOV P1,A
LCALL DELAY_1S
RL A
MOV P1,A
LCALL DELAY_1S
RL A
MOV P1,A
LCALL DELAY_1S

RR A
MOV P1,A
LCALL DELAY_1S
RR A
MOV P1,A
LCALL DELAY_1S
RR A
MOV P1,A
LCALL DELAY_1S
RR A
MOV P1,A
LCALL DELAY_1S
RR A
MOV P1,A
LCALL DELAY_1S
SJMP MAIN

org 0100h
;-------------
DELAY_1S: ;高精度延时0.5s (无中断)
DEY1 DATA 1FH
DEY2 DATA 1EH
DEY3 DATA 1DH
MOV DEY1,#50 ;0.05S
DL1:
MOV DEY2,#100 ;10mS
DL2:
MOV DEY3,#221 ;100uS 11.0592M(5T)
DJNZ DEY3,$
DJNZ DEY2,DL2
DJNZ DEY1,DL1
RET
;-------------

END

注:移位可压缩成循环语句

回答3:

#include"reg51.h"
void delay_ms(unsigned int a)
{
unsigned char;
while(--a)
for(i=0;i<125;i++);
}
int main()
{
unsigned char i,j;
p1=0x01;
while(1)
{
for(j=0;j<5;j++)
for(i=0;i<8;i++)
{
P1&=~(0x01< delay_ms(1000);
}
for(j=0;j<5;j++)
for(i=0;i<8;i++)
{
P1=0x80>>i;
delay_ms(1000);
}

}
}