单片机程序 流水灯、单管、多管等相关程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验一流水灯的显示:ORG 0000H

BEG:SJMP START

ORG 0030H

START:

MOV P1,#0FEH LCALL DELAY

MOV P1,#0F1H

LCALL DELAY

MOV P1,#70H

LCALL DELAY

MOV P1,#10H

LCALL DELAY

MOV P1,#0F3H

LCALL DELAY

MOV P1,#0F0H

LCALL DELAY

MOV P1,#30H

LCALL DELAY

MOV P1,#00H

LCALL DELAY

AJMP START DELAY:PUSH 00H

PUSH 01H

MOV R0,#200

N1:MOV R1,#250

N2:NOP

NOP

NOP

NOP

NOP

NOP

NOP

NOP

NOP

NOP

DJNZ R1,N2

DJNZ R2,N1

POP 01H

POP 00H

RET

END BEG

实验二单管显示:

ORG 0000H BEG:AJMP START

START:MOV SP,#60H

MOV DPTR,#DM

MOV B,#00H

MOV R1,#9

NEXT:MOV A,B

MOVC A,@A+DPTR

MOV P1,A

LCALL DELAY

INC B

DJNZ R1,NEXT

LJMP START

DELAY:PUSH 00H

PUSH 01H

MOV R0,#200

DL1:MOV R1,#250

DL2:NOP

NOP

NOP

NOP

NOP

NOP

NOP

NOP

NOP

NOP

DJNZ R1,DL2

DJNZ R0,DL1

POP 01H

POP 00H

RET

DM: DB 089H,086H,0C7H,0C7H,0C0H,0A4H,0C 0H,0F9H,0B0H

END BEG

实验三多管显示:

ORG 0000H

BEG:AJMP START

START:

MOV SP,#60H

MOV DPTR,#DM

N1:

MOV R0,#0

MOV R1,#16

MOV R2,#0FEH

N2:

SETB P3.4

MOV A,R0

MOVC A,@A+DPTR

MOV P1,A

CLR P3.4

SETB P3.5

MOV P1,R2

CLR P3.5

LCALL DELAY

MOV P1,#00H

MOV A,R2

RL A

MOV R2,A

INC R0

DJNZ R1,N2

LCALL DELAY

SJMP START

DM: DB 76H,3FH,73H,79H,38H,79H,6DH,6DH,3 FH,06H,5BH,4FH,66H,6DH,7DH,07H DELAY:PUSH 00H

PUSH 01H

MOV R0,#150

M3:MOV R1,#250

M4:NOP

NOP

NOP

NOP

NOP

NOP

NOP

NOP

NOP

NOP

DJNZ R1,M4

DJNZ R0,M3

POP 01H

POP 00H

RET

DM1: DB

END BEG 实验四LCD的显示

#include<reg52.h>

#include<intrins.h>

#define uint unsigned int

#define uchar unsigned char sbit c_rs=P2^4;

sbit c_rw=P2^5;

sbit c_e=P2^6;

char msg1[]=" It's May 12th. "; char msg2[]=" A sunny day. "; char *M=msg1;

char *N=msg2;

void delay(uint i)

{

while(i--);

}

void write_cmd(uchar dd)

{

c_e=0;

c_rs=0;

c_rw=0;

delay(50);

P0=dd;

c_e=1;

delay(50);

c_e=1;

delay(50);

}

void write_dat(uchar dd)

{

c_e=0;

c_rs=1;

c_rw=0;

delay(50);

P0=dd;

c_e=1;

delay(50);

c_e=0;

delay(50);

}

void lcd_init()

{

write_cmd(0x38);

相关文档
最新文档