;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
Previous article:16-bit single-chip computer for connecting information appliances to the Internet
Next article:PIC microcontroller software asynchronous serial port implementation method
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- When BLE meets MEMS——Introduction to HID Report Descriptor
- MSP430 SPI Hardware Interface
- Understand the role and use of capacitors in one article
- The results of the GD32F350 contest (sharing experience & interaction) are as follows: Thanks to all the cool people in the contest
- Serial port printing problem after BLUENRG-1 wakes up from sleep
- 【I-Prober 520】Test Summary
- How can I wire this circuit to minimize interference?
- [Help] I need help drawing a simple PCB board.
- [RVB2601 Creative Application Development] + Stickman Player
- [Project source code] stmdb and ldmia assembly instructions