The assembly language program of the perpetual calendar based on the single chip microcomputer

Publisher:bemaiiLatest update time:2011-04-11 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;Real perpetual calendar: 84 bytes of 51 ASM

;==SUB_WNL=== Perpetual calendar ==* Deng Miao * 2004-06-01 ***** GuangZhou ******
SJ DATA 30H ; Century BCD 00 TO 99
NH DATA 31H ; Year BCD 00 TO 99 0000 TO 9999
YearYF DATA 32H ; Month BCD 01 TO 12

org 000h
MOV SP, #40H
MOV SJ, #21H ;2004-05
MOV NH, #01H
MOV YF, #4H
ACALL SUB_WNL
SJMP $

;===============SUB_WNL===================
; Entry:
; SJ DATA 30H ; Century BCD 00 TO 99
; NH DATA 31H ; Year BCD 00 TO 99 0000 TO 9999
; YF DATA 32H ; Month BCD 01 TO 12
; Export
; ACC -- Day of the month BCD 28 to 31
; B -- Week number of the 1st of the month 1 to 6 == Monday to Saturday
; 0 -- Sunday
; Use: ACC, B, R5, R6
; STACK: 3 bytes (excluding call)
ORG 50H


SUB_WNL:
PUSH PSW
MOV A, SJ
ACALL BCD2BIN_MOD4
; x 400 years: (large cycle)
; =146097 days = 7 * 20871 + 0 days
; x 100 years:
; 000 years = 7 * 0 + 0 + 1 - 1 1 = 0 * 2 + 1 ****
; 100 years = 7 * 5217 + 7 + 1 - 2 2 = 1 * 2
; 200 years = 7 * 10435 + 7 + 1 - 4 4 = 2 * 2
; 300 years = 7 * 15653 + 7 + 1 - 6 6 = 3 * 2
; {1,2,4,6}
MOV A, R6 ; A=R6= SJ_BIN MOD 4
RLC A ; A=A*2+C A = {1,2,4,6} ****
XRL A, #10000111B ; A = 87H - A ; Boundary adjustment
MOV R5, A ; A = {86H, 85H, 83H, 81H} ; R5: weekday
MOV A, NH
JZ WNL_1
ACALL BCD2BIN_MOD4
XCH A, R5
SUBB A, R5 ; 0 year ; 0 = 0 + 0 + 1 + (-1) ***
MOV R5, A

WNL_1:
MOV A, YF
ADD A, #(WNL_TAB-$-4)
MOVC A, @A+PC
MOV R6, A

SWAP A
ACALL WNL_F0; Prepare for year adjustment if >= March
ADDC A, R5 ; Month adjustment
MOV B, #7
DIV AB ; B = A MOD 7

MOV A, R6
ACALL WNL_F0; Prepare for year adjustment
ADDC A, #28
POP PSW
RET

WNL_TAB:
DB 3*2 + 5 * 32+0 ;1 BIT 0 : "February" flag
DB 0*2+1+1 * 32+0 ;2 ** BIT 1..2: Month size
DB 3*2 + 1 * 32+16 ;3 00: 28 days
DB 2*2 + 4 * 32+16 ;4 01: ----
DB 3*2 + 6 * 32+16 ;5 10: 30 days
DB 2*2 + 2 * 32+16 ;6 11: 31 days
DB 3*2 + 4 * 32+16 ;7 BIT 3: 0 -----
DB 3*2 + 7 * 32+16 ;8 BIT 4: 0: 1/2 month
DB 2*2 + 3 * 32+16 ;9 1: >=3 months
WNL_F0: ; 6 BYTES ; New Year adjustment preparation
RRC A ;0AH
ANL A, #07H ;0BH
;0CH
ANL C, F0 ;0DH
;0EH
RET ;0FH
DB 3*2 + 5 * 32+16 ;10H BIT 5..7: Week adjustment number
DB 2*2 + 1 * 32+16 ;11H 0:---
DB 3*2 + 3 * 32+16 ;12H 1-7: Adjustment number

BCD2BIN_MOD4:
; Function: A. 1 BYTES BCD TO BIN
; B. MOD 4
; C. MUL 2
; Entry:
; A : SJ OR NH
; F0 : Big Century
; Exit
; ACC -- (BIN(A) 4) * 2 - (BIN(A) MOD 4) - F0
; R6 -- BIN(A) MOD 4
; C -- IIF( (BIN(A) MOD 4)=0, 1, 0 )
; Use: ACC, B, R6, PSW
; STACK: 0 bytes (excluding call)

MOV R6, A ; BCD ==> BIN
ANL A, #0F0H ; 16X+Y ==> 10X+Y
SWAP A
MOV B, #(256-6) ; (256-6)*X + (16X+Y)
MUL AB ;
ADD A, R6 ; = 256X + (10X+Y)

MOV R6, A ; MOD4
ANL A, #3
XCH A, R6 ; R6 = BIN MOD 4 = {0,1,2,3}
; X 4 years: 3 * 365 + 366 = 7*209 + (-2) **
XRL A, R6 ; A = (BIN 4)
RR A ; A = (BIN 4 ) * 2 **
MOV C, F0 ; Big century adjustment
SUBB A, R6
; X 1 year:
;0 year 0 = 0 + 0 + 1 + (-1) ***
;1 year 366 = 7*52 + 1 + 1
;2 year 366 + 365 = 7*104 + 2 + 1
;3 year 366 + 365 + 365 = 7*156+3 + 1
; {-1,1,2,3}
CJNE R6, #1, $ + 3 ; C = IIF(R6>=1, 0, 1)
MOV F0, C ; C=1 for big year/big century
RET
;-----------------------------
END ;======== END OF FILE

Reference address:The assembly language program of the perpetual calendar based on the single chip microcomputer

Previous article:16-bit single-chip computer for connecting information appliances to the Internet
Next article:PIC microcontroller software asynchronous serial port implementation method

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号