您好,欢迎来到刀刀网。
搜索
您的当前位置:首页电子钟的程序(汇编)

电子钟的程序(汇编)

来源:刀刀网


一下程序是利用C51单片机实现电子钟的实用汇编程序:

ORG 0000H BEGIN: LJMP INIT

ORG 0003H ;INT0 RETI

ORG 000BH ;T0 INT T0: LJMP T0INTSR RETI

ORG 0013H ;1NT1 RETI

ORG 001BH ;T1 INT RETI

ORG 0023H ;S PORT INT RETI

ORG 002BH ;T2 INT RETI

ORG 0100H

;===================================================== ;8032 RAM 00H--FFH CLEAR 0 INIT: MOV B,#0FFH MOV R0,#00H MOV A, #00H CLE0FFH:INC R0

MOV @R0,A DJNZ B,CLE0FFH ;SET STACK AREA 70H--7FH MOV SP,#70H ;TIMER INIT

MOV TMOD,#01H

MOV TL0,#0B0H ;2 E+16 = 65536 = 15536 + 50000(0.05S) MOV TH0,#03CH ;3CB0H=15536 ;RAM INTI

MOV 2FH,#3FH ;2FH IS FLASH TAG

MOV 2EH,#00H ;2EH IS T0 INTERRUPT COUNTER MOV 2DH,#00H ;2DH IS THE SECOND COUNTER CLR P1.0 CLR P1.1 ;ENABLE INTERRUPT SETB EA SETB ET0 ;START UP T0

SETB TR0

;SYSTEM NORMAL ,IDENTIFIER \"0.0\" MOV PSW,#00H

;==================================================================== ENTRK1: LCALL KEYSCAN;KEY SACN SUBRUTIN

LCALL TICHANG;DISPLAY CHARACTER CHANGE LCALL DIFLASH;DISPLAY FLASHING LCALL DISPLAY;DISPLAY SUBRUTIN LCALL TIMECAL;TIME CALCULATE SJMP ENTRK1

;==================================================================== ; 1. KEYSCAN......KEY SCAN SUBRUTIN

; 2. TICHANG......TIME DATA CHARACTER CHANGE ; 3. DIFLASH......DISPLAY FLASHING ; 4. DISPLAY......DISPLAY SUBRUTIN ; 5. TIMECAL......TIME CALCULATE ; 6. DELAY60......DELAY 60mS

; 7. DCCHANG......DISPLAY CHARACTER CHANGE ;-------------------------------------------------------------------- ;1. ----------------------------------------------------------------- ;KEYSCAN:

; KEY SCAN SUBRUTIN ;

; 1. 8032 P1 PORT PIN DEFINITION ;

; P3.2== +1 KEY BIT ; P3.3==TIMESET KEY ;

; 2. RAM BIT 00H --PRESS TIMESET KEY FLAG 1=PRESSED, 0=NOT ; 02H --PRESS ADD 1 KEY PIN PONG FLAG ; 03H --PRESS TIMESET KEY PIN PONG FLAG ;

;-------------------------------------------------------------------- KEYSCAN:NOP

PUSH PSW

MOV PSW,#08H

JB P3.2,KEYTIM0

LCALL DELAY60 ;DELAY 60mS JB P3.2,KEYTIM0 SETB 03H

LJMP KEYSOUT

KEYTIM0:JNB 03H,KEYJMP0 JB P3.2,TIMSET0

LCALL DELAY60 ;DELAY 60mS JB P3.2,TIMSET0 LJMP KEYSOUT KEYJMP0:LJMP KEYSCA0

TIMSET0:NOP

CLR 03H

JB 00H,TIMESOK

SETB 00H ;TIMESET KEY IS PRESSED CLR MOV MOV MOV LJMP TIMESOK:NOP

DEC DEC CJNE CLR SETB TTTTT: LJMP

KEYSCA0:NOP

JB LCALL JB SETB LJMP

KEYP6H: JB LCALL JB KEYJMP:

ADD1PRS:CLR JB JNB ADD1IN: INC MOV CJNE CJNE EQ67H0: JC ET0

2DH,#00 R0,#67H R1,#6FH KEYSOUT R0 ;TIMESET KEY IS PRESSED R1

R0,#63H,TTTTT ;KEYSOUT 00H ET0 KEYSOUT P3.5,KEYP6H

DELAY60 ;DELAY 60mS P3.5,KEYP6H 02H

KEYSOUT JNB 02H,KEYJMP P3.5,ADD1PRS

DELAY60 ;DELAY 60mS P3.5,ADD1PRS

LJMP KEYSOUT 02H

00H,ADD1IN 01H,EQ67H1

MOV A,@R0 ;+1 KEY IS PRESSED A

@R0,A

R0,#67H,LESS67H A,#03H,EQ67H0 EQ67H1

MOV @R0,#0

EQ67H1: LJMP KEYSOUT

LESS67H:CJNE R0,#66H,LESS66H CJNE A,#0AH,EQ66H0 EQ66H0: JC EQ66H1 MOV @R0,#0

EQ66H1: LJMP KEYSOUT

LESS66H:CJNE R0,#65H,LESS65H CJNE A,#06H,EQ65H0 EQ65H0: JC EQ65H1 MOV @R0,#0

EQ65H1: LJMP KEYSOUT

LESS65H:CJNE R0,#H,KEYSOUT CJNE A,#0AH,EQH0 EQH0: JC KEYSOUT MOV @R0,#0 KEYSOUT:NOP

POP PSW RET

;-------------------------------------------------------------------- ;2.------------------------------------------------------------------ ;TICHANG

; TIME DATA CHARACTER CHANGE

; 2. RAM BIT 00H --PRESS TIMESET KEY FLAG 1=PRESSED, 0=NOT ;

;-------------------------------------------------------------------- TICHANG:NOP

MOV R7,#4 MOV R0,#6FH MOV R1,#67H TCHANG0:MOV A,@R1

LCALL DCCHANG ;DISPLAY CHARACTER CHANGE CPL A

MOV @R0,A DEC R0 DEC R1

DJNZ R7,TCHANG0 TICHOUT:NOP RET

;-------------------------------------------------------------------- ;3.------------------------------------------------------------------

;DIFLASH

; DISPLAY FLASHING CHANGE

; 1. RAM BIT 00H --PRESS TIMESET KEY FLAG 1=PRESSED, 0=NOT ;

; 2. RAM 2FH IS FLASH TAG ; ;

;-------------------------------------------------------------------- DIFLASH:NOP

JB 00H,FLASHIN AJMP FLASOUT FLASHIN:MOV A,2FH RL A

MOV 2FH,A ANL A,#03H

CJNE A,#03H,FLASOUT PUSH PSW

MOV PSW,#08H MOV @R1,#0FFH POP PSW FLASOUT:RET NOP

;-------------------------------------------------------------------- ;4.------------------------------------------------------------------ ;DISPLAY:

; DISPLAY SUBRUTIN ;

; RAM:6FH CLOCK HORE 10 BIT ; 6EH CLOCK HORE 1 BIT ; 6DH CLOCK MIN 10 BIT ; 6CH CLOCK MIN 1 BIT ;

;-------------------------------------------------------------------- DISPLAY:NOP

SETB P1.3 MOV P0,6FH CLR P1.0

LCALL DELAY60 ;DELAY 60MS LCALL DELAY60 ;DELAY 60MS SETB P1.0

MOV P0,6EH CLR P1.1

LCALL DELAY60 ;DELAY 60MS

LCALL DELAY60 ;DELAY 60mS SETB P1.1

MOV P0,6DH CLR P1.2

LCALL DELAY60 ;DELAY 60MS LCALL DELAY60 ;DELAY 60MS SETB P1.2

MOV P0,6CH CLR P1.3

LCALL DELAY60 ;DELAY 60MS LCALL DELAY60 ;DELAY 60MS SETB P1.4 SETB P1.7 SETB P1.6 SETB P1.5 RET

;-------------------------------------------------------------------- ;5.------------------------------------------------------------------ ; TIMECAL:

; TIME CALCULATE ;

; 1. RAM BIT 00H --PRESS TIMESET KEY FLAG 1=PRESSED, 0=NOT ; 2. RAM 2EH T0 INTERRUPT COUNTER ; 3. RAM 2DH IS THE SECOND COUNTER ; 4. RAM:6FH CLOCK HORE 10 BIT ; 6EH CLOCK HORE 1 BIT ; 6DH CLOCK MIN 10 BIT ; 6CH CLOCK MIN 1 BIT

;-------------------------------------------------------------------- TIMECAL:NOP

JB 00H,TIMEOU1

MOV A,2EH ;HOUR DISPLAY FLASH CJNE A,#10,TIMECA1 ; TIMECA1:JNC TIMECA2 ; MOV A,66H ; CJNE A,#18H,TIMECA5 ; TIMECA5:JNC TIMEOU1 ; ADD A,#18H ; CLR P1.0

MOV 66H,A ; mov a,65h add a,#18h

mov 65h,a

TIMEOU1:LJMP TIMEOUT ; TIMECA2:CJNE A,#20,TIMECA3 ; TIMECA3:JNC TIMECAJ ; MOV A,66H ; CJNE A,#18H,TIMECA6 ; TIMECA6:JC TIMEOU2 ; SUBB A,#18H ; SETB MOV mov subb mov

TIMEOU2:LJMP

TIMECAJ:MOV MOV CJNE TIMECAF:JNC INC MOV LJMP

TIMECAG:MOV MOV INC JNB DEC CLR TIMEFAS:CJNE TIMECA7:JNC MOV LJMP

TIMECA8:MOV MOV INC CJNE TIMECA9:JNC MOV LJMP P1.0

66H,A a,65h a,#18h 65h,a TIMEOUT 2EH,#00H A,2DH A,#59,TIMECAF TIMECAG A 2DH,A TIMEOUT 2DH,#00 A,H A ;

06H,TIMEFAS A 06H

A,#10,TIMECA7 TIMECA8 H,A TIMEOUT H,#0 A,65H A A,#6,TIMECA9 TIMECAA 65H,A TIMEOUT ; ;HOUR DISPLAY FLASH ;SECONDE ADD 1 ; ; ; ; ;

;SECONDE ADD 1 ;MINIUT 0X ADD 1 ; ; ; ;

;MINIUTE 0X ADD 1 ;MINIUTE XO ADD 1 ; ; ; ; ;

;MINIUTE X0 ADD 1

TIMECAA:MOV 65H,#0 ;HOUR 0X ADD 1 MOV A,66H ; INC A ; CJNE A,#10,TIMECAB ; TIMECAB:JC TIMECAH ; LJMP TIMECAC ;

TIMECAH:MOV 66H,A ;HOUR 0X ADD 1

MOV A,67H ;IF HOUR IS 24 CJNE A,#2,TIMEN24 ; MOV A,66H ; CJNE A,#4,TIMECAI ;

TIMECAI:JNC TIME24H ;IF HOUR IS 24 TIMEN24:LJMP TIMEOUT

TIME24H:MOV H,#00 ;MIN 0X MOV 65H,#00 ;MIN X0 MOV 66H,#00 ;HOUR 0X MOV 67H,#00 ;HOUR X0

MOV 44H,#04 ;FIRST PROGRAM 1997-11-17 LJMP TIMEOUT ;NEW ONE DAY

TIMECAC:MOV 66H,#0 ;HOUR X0 ADD 1 MOV A,67H ; INC A ; CJNE A,#3,TIMECAD ; TIMECAD:JNC TIMECAE ; MOV 67H,A ;

LJMP TIMEOUT ;HOUR X0 ADD 1

TIMECAE:MOV 67H,#0 TIMEOUT:NOP RET

;-------------------------------------------------------------------- ;6.------------------------------------------------------------------ ;DELAY60:

; DELAY 100mS FOR NEXT RANGING

;-------------------------------------------------------------------- DELAY60:PUSH PSW

MOV PSW,#00H

MOV R3,#6 ;#10 0.5ms * 10 = 5ms 1997-9-3 W60MS: MOV R4,#0FAH ;0FAH =250

W500US1:DJNZ R4,W500US1 ;TIME = 2US 2 US * 250 = 0.5 MS DJNZ R3,W60MS POP PSW RET

;------------------------------------------------------------------- ;7.------------------------------------------------------------------ ;DCCHANG:

; DISPLAY CHARACTERS CHANGE ROUTINE ; NOTE:

; 1. ENTRY A-----LOAD SETOFF

; 2. RET A-------DISPLAY CHARACTER

;-------------------------------------------------------------------- DCCHANG:MOV DPTR,#CHARAL MOVC A,@A+DPTR RET

;CHARACTERS LIST

CHARAL: DB 3FH,06H,5BH,4FH,66H,6DH ;SETOFF : 00H,01H,02H,03H,04H,05H, ;CHARACTERS: 0, 1, 2, 3, 4 , 5 DB 7DH,07H,7FH,6FH,77H,7CH ; 06H,07H,08H,09H,0AH,0BH, ; 6, 7, 8, 9, A, B, DB 39H,5EH,79H,71H,73H,3EH ; 0CH,0DH,0EH,0FH,10H,11H, ; C, D, E, F, P, U, DB 76H,38H,40H,6EH,0FFH,00H ; 12H,13H,14H,15H,16H, 17H ; H, L, -, Y, 8., \" \"

DB 0BFH,86H,0DBH,0CFH,0E6H,0EDH ; 18H,19H, 1AH, 1BH, 1CH, 1DH, ; 0., 1., 2., 3., 4., 5.,

DB 0FDH,87H,0FFH,0EFH,0F7H,0FCH ; 1EH, 1FH,20H, 21H, 22H, 23H, ; 6., 7., 8., 9., A., B.,

DB 0B9H,0CEH,0F9H,0F1H,0F3H,0BEH ; 24H, 25H, 26H, 27H, 28H, 29H, ; C., D., E., F., P., U.,

DB 0F6H,0B8H,0C0H,0DEH,0FFH,80H ; 2AH, 2BH, 2CH, 2DH, 2EH, 2FH ; H., L., -., Y., 8., \" .\"

;-------------------------------------------------------------------- ;-------------------------------------------------------------------- ; T0,T1 INTERRUPT SUBROUTINE

; 1. T0INTSR.......T0 INTERRUPT SERVE ROUTINE

;-------------------------------------------------------------------- ;-------------------------------------------------------------------- ;1.T0INTSR:

; T0 INTERRUPT SERVE ROUTINE ;

; 1. T0 IS SETED AS 0.05S TIMER(MODE 1) ; 2. T0 IS SET AS: ; TL0=B0H

; TH0=3CH 3CB0H = 15536 = 65536(2 E+16) - 50000 ; AFTER 50000 uS ,INTRUPT IS HAPPEN ; IN THIS STATES, T0 TIME IS 50 MS ;-------------------------------------------------------------------- T0INTSR:CLR ET0 CLR TR0 INC 2EH

MOV TL0,#0B0H MOV TH0,#03CH SETB TR0 SETB ET0 RETI

;==================================================================== END

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- gamedaodao.com 版权所有 湘ICP备2022005869号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务