在80C51单片机中,已知时钟频率为6MHz,请编程使P1.0和P1.1分别输出周期为2S和0.5S的方波

2024-12-19 13:59:33
推荐回答(4个)
回答1:

;下列程序,经过编译、仿真,符合要求:
ORG 0000H
SJMP START
ORG 000BH
SJMP T0_INT
START:
MOV TMOD, #01H
MOV TH0, #9EH
MOV TL0, #58H ;50ms@6MHz
SETB TR0
SETB ET0
SETB EA
MOV R2, #5
MOV A, #0
CLR P1.0
CLR P1.1
SJMP $
T0_INT:
MOV TH0, #9EH
MOV TL0, #58H ;50ms@6MHz
DJNZ R2, T0_END
MOV R2, #5
INC A
MOV C, ACC.0
MOV P1.1, C
MOV C, ACC.2
MOV P1.0, C

T0_END:
RETI
END

回答2:

c的,已经验证过了

#include
#define uchar unsigned char

sbit P10=P1^0;
sbit P11=P1^1;

uchar k=0,s=0;

void timer(void) interrupt 1
{
TH0=0x3c;
TL0=0xB0;

k++;
s++;

if(s==5)
{
P11=~P11;
s=0;
}

if(k==20)
{
P10=~P10;
k=0;
}
}

main()
{
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
while(1);
}

回答3:

t2s_counter data 21h
t05s_counter1 data 22h
t05s_counter2 data 23h

org 0000h
ajmp main
org 000bh
ajmp t0_routine
org 30h
main: mov sp,#30h
mov tmod,#22h
mov tl0,#6
mov th0,#6
mov t05s_counter1,#00h
mov t05s_counter2,#00h
mov t2s_counter,#00h
setb et0
setb tr0
setb ea
sjmp $
t0_routine:
push psw
push acc
inc t05s_counter1
mov a,t05s_counter1
cjne a,#250,return
mov t05s_counter1,#00h
inc t05s_counter2
mov a,t05s_counter2
cjne a,#2,return
mov t05s_counter2,#00h
cpl p1.1
inc t2s_counter
mov a,t2s_counter
cjne a,#4,return
mov t2s_counter,#00h
cpl p1.0
return: pop acc
pop psw
reti
end

回答4:

很简单,具体可以加我50174447
适用内部定时器 就可以