C51单片机 一些题目 求高手帮忙解答。 也可以邮箱372014019@qq.com...
发布网友
发布时间:2024-10-21 22:31
我来回答
共2个回答
热心网友
时间:2024-11-07 08:04
下面三个都是流水灯程序,你自己看要哪个吧
方法1:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
void delayxms(uint xms);
uchar code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//流水灯数据表
void delayxms(uint xms)//xms延时函数
{
uint i,j;
for(i=xms;i>0;i--)
for(j=113;j>0;j--);
}
void main()//主函数
{
uchar i;
while(1)
{
for(i=0;i<8;i++)
{
P1=tab[i];
delayxms(200);
P1=0xff;
}
}
}
方法2:
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp;
void delayxms(uint xms);
void main()
{
temp=0xfe;
P1=temp;
while(1)
{
delayxms(200);
temp=_crol_(temp,1);
P1=temp;
}
}
void delayxms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
方法3:(这个是汇编)
ORG 0000H
AJMP MAIN
ORG 0030H
MAIN: MOV SP,#5FH
MOV A,#FEH
CLR C
LOOP: RRC A
MOV P1,A
LCALL DELAY
LJMP LOOP
DELAY: MOV R7,#255
D1: MOV R6,#255
D2: NOP
NOP
NOP
NOP
DJNZ R6,D2
DJNZ R7,D1
RET
END
热心网友
时间:2024-11-07 08:01
EQU P2.6
STP EQU P2.7
CLRR EQU P3.0
SEC EQU P3.5
MIN EQU P3.6
HOUR EQU P3.7
ORG 00H
SJMP MAIN
ORG 0BH
AJMP T0INT0
ORG 30H
MAIN: MOV SP,#60H
MOV R4,#20
MOV TMOD,#01H
MOV TH0,#03CH;#9EH 12M晶振时定时初值取#3CB0H
MOV TL0,#0B0H;#58H
SETB ET0
SETB EA
;MOV 28H,#12
kS: LCALL DISP
JB SEC,KM
LCALL DISP
JNB SEC,$-3
AJMP SINC
kM: JB MIN,KH
LCALL DISP
JNB MIN,$-3
AJMP MINC
KH: JB HOUR,K1
LCALL DISP
JNB HOUR,$-3
AJMP HINC
SINC: INC 26H
MOV A,26H
CJNE A,#60,SINC0
MOV 26H,#0
SINC0: AJMP KS
MINC: INC 27H
MOV A,27H
CJNE A,#60,MINC0
MOV 27H,#0
MINC0: AJMP KM
HINC: INC 28H
MOV A,28H
CJNE A,#24,HINC0
MOV 28H,#0
HINC0: AJMP KH
k1: LCALL DISP
JB STRT,K2
LCALL DISP
JNB STRT,$-3
AJMP START
k2: JB STP,K3
LCALL DISP
JNB STP,STOP
K3: JB CLRR,KS
LCALL DISP
JNB CLRR,CLEAR
AJMP KS
START: SETB TR0
AJMP K1
STOP: CLR TR0
AJMP K2
CLEAR: CLR TR0
MOV A,#0
MOV 20H,A
MOV 21H,A
MOV 22H,A
MOV 23H,A
MOV 24H,A
MOV 25H,A
MOV 26H,A
AJMP KS
DISP:
MOV A,26H
MOV B,#10
DIV AB
MOV 20H,B ;余数(秒个位数)
MOV 21H,A ;商(秒十位数)
MOV A,27H
MOV B,#10
DIV AB
MOV 22H,B ;余数(分个位数)
MOV 23H,A ;商(分十位数)
MOV A,28H
MOV B,#10
DIV AB
MOV 24H,B ;余数(时个位数)
MOV 25H,A ;商(时十位数)
MOV A,20H ;秒个位
ACALL SEG7
MOV P0,A
CLR P2.0
ACALL DLY
SETB P2.0
MOV A,21H ;秒十位
ACALL SEG7
MOV P0,A
CLR P2.1
ACALL DLY
SETB P2.1
MOV A,22H ;分个位
ACALL SEG7
MOV P0,A
SETB P0.7
CLR P2.2
ACALL DLY
SETB P2.2
MOV A,23H ;分十位
ACALL SEG7
MOV P0,A
CLR P2.3
ACALL DLY
SETB P2.3
MOV A,24H ;时个位
ACALL SEG7
MOV P0,A
SETB P0.7
CLR P2.4
ACALL DLY
SETB P2.4
MOV A,25H ;时十位
ACALL SEG7
MOV P0,A
CLR P2.5
ACALL DLY
SETB P2.5
RET
T0INT0: MOV TH0,#03CH;#9EH ;定时中断子程序。重装定时常数
MOV TL0,#0B0H;#58H
DJNZ R4,T0INTR ;50msX20=1S,未满20次,跳出中断子程序
MOV R4,#20
INC 26H
MOV A,26H
CJNE A,#60,T0INTR
MOV 26H,#0
INC 27H
MOV A,27H
CJNE A,#60,T0INTR
MOV 27H,#0
INC 28H
MOV A,28H
CJNE A,#24,T0INTR
MOV 28H,#0
AJMP T0INTR
T0INTR: RETI
DLY10: MOV R3,#30
D0: ACALL DLY
DJNZ R3,D0
RET
DLY: MOV R7,#2
D1: MOV R6,#40
DJNZ R6,$
DJNZ R7,D1
RET
SEG7: INC A
MOVC A,@A+PC
RET
DB 03FH ;0
DB 006H ;1
DB 05BH ;2
DB 04FH ;3
DB 066H ;4
DB 06DH ;5
DB 07DH ;6
DB 007H ;7
DB 07FH ;8
DB 06FH ;9
END