"Single chip microcomputer 6-bit digital clock
Key words: single chip microcomputer 6-bit digital clock
The electronic clock program made by 51 single chip microcomputer has been introduced in many places. For single chip microcomputer learners, this program is basically a threshold. After mastering the electronic clock program, it can be said that 51 single chip microcomputer has mastered 80%. The common electronic clock program consists of display part, calculation part and clock adjustment part.
Basic display principle of clock: the clock starts to display 0:0:0, that is, the nixie tube displays 000000, and then the second bit per second increases by 1. After 9, the 10 second bit increases by 1, and the second bit returns to 0. After the 10 second bit reaches 5, i.e. 59 seconds, the minute is increased by 1, and the 10 second bit returns to 0. By analogy, the maximum display value of the clock is 23 hours, 59 minutes and 59 seconds. Here, as long as the timing time of 1 second is determined, other bits are accumulated upward based on this.
The program defines seconds, 10 seconds, minutes, hours, ten hours, 6 registers. There are 30h, 31h, 32H, 33H, 34h and 35h units respectively, which are easy to call and understand later.
Six nixie tubes display hour, minute and second respectively. One function key can switch and adjust hour, minute and second, increase value, turn off and save power. Circuit schematic diagram: (for reference only, the improved board will not be notified otherwise)
The following is part of the assembly source program. After purchasing our products, we use CD to send the complete MCU assembly source program and burning files to customers.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interrupt entry program( For reference only);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ORG 0000H ; Program execution start address LJMP start; Skip to label start and execute ORG 0003h; External interrupt 0 interrupt program entry reti; External interrupt 0 returns ORG 000BH; Timer T0 interrupt program entry LJMP intT0; Skip to intto and execute ORG 0013h; External interrupt 1 interrupt program entry reti; External interrupt 1 returns to ORG 001bh; Timer T1 interrupt program entry LJMP intt1; Skip to intt1 and execute ORG 0023h; Serial interrupt program entry address reti; Serial interrupt program return;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Main program;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; START: MOV R0,#70H ; Clear 70h-7ah with 11 memory units mov R7, #0bh; clr P3.7 ; CLEARDISP: MOV @R0,#00H ; INC R0 ; DJNZ R7,CLEARDISP ; MOV 20H,#00H ; Clear 20h (for signs) mov 7Ah, #0ah; Put in the data mov tmod with the "off" character, #11h; Set t0 and T1 as 16 bit timers MOV, tl0, #0b0h; 50ms timing initial value (for t0 timing) mov Th0, #3ch; 50ms timing initial value mov TL1, #0b0h; Initial value of 50ms timing (for T1 flashing timing) mov Th1, #3ch; 50ms timing initial value setb EA; Total interrupt open setb ET0; Allow t0 to interrupt setb tr0; Start t0 timer mov R4, #14h; Initial value for 1s timing (50ms) × 20)START1: LCALL DISPLAY ; Call the display subroutine JNB P3.7, setmm1; When P3.7 port is 0, turn to time adjustment program sjmp start1; When P3.7 port is 1, jump back to start1setmm1: LJMP setmm; Go to the time adjuster setmm;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1 second timing program;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; T0 interrupt service program intT0: push ACC; Accumulator stack protection push PSW; Status word stack protection CLR ET0; Off t0 interrupt allows CLR tr0; Close timer t0mov a, #0b7h; Interrupt response time synchronization correction add a, tl0; Low 8-bit initial value correction mov tl0, a; Reinstall the initial value (lower 8-bit correction value) mov a, #3ch; High 8-bit initial value correction ADDC a, Th0; MOV TH0,A ; The initial value of reassembly (high 8 bit correction value) setb tr0; Start timer t0djnz R4, outt0; Exit addss before 20 interrupts: mov R4, #14h; 20 interrupts to (1s) reset the initial value mov R0, #71h; Pointing second timing unit (71h-72h) acall ADD1; Call the plus 1 Program (plus 1 second operation) mov a, R3; Put the second data into a (R3 is the combination of 2-digit decimal numbers) CLR C; Clear carry flag cjne a, #60h, addmm; ADDMM: JC OUTT0 ; Interrupt and exit acall clr0 when it is less than 60 seconds; When it is greater than or equal to 60 seconds, clear 0mov R0, #77h to the second timing unit; Pointing to the time division unit (76h-77h) acall ADD1; Time division unit plus 1 minute mov a, R3; Put sub data into ACLR C; Clear carry flag cjne a, #60h, addhh; ADDHH: JC OUTT0 ; Interrupt and exit acall clr0 when it is less than 60 minutes; Greater than or equal to 60 minutes, the time division timing unit clears 0mov R0, #79h; Point to hourly time sheet (78h-79h) acall ADD1; Hour timing unit plus 1 hour mov a, R3; Put the data into ACLR C when; Clear carry flag cjne a, #24h, hour; HOUR: JC OUTT0 ; Interrupt and exit acall clr0 less than 24 hours; Greater than or equal to 24-hour timing unit clear 0outt0: mov 72h, 76h; When the interrupt exits, move the time division and timing unit data to mov 73h and 77h; Input the corresponding display units mov 74h, 78h; MOV 75H,79H ; POP PSW ; Restore status word (out of stack) pop ACC; Recover accumulator setb ET0; Open t0 interrupt reti; Interrupt return;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Flash timing program;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; T1 interrupt service program, when used as time adjustment, the adjustment unit flashes to indicate intt1: push ACC; Interrupt the on-site protection push PSW; MOV TL1, #0B0H ; Install timer T1, timing initial value mov Th1, #3ch; DJNZ R2,INTT1OUT ; Exit interrupt (50ms interrupt 6 times) mov R2 before 0.3s, #06h; The initial value CPL 02h is used for 0.3 second timing reassembly; When 0.3 seconds is fixed, reverse JB 02h and flash1 for the flashing flag; When the 02h bit is 1, the display unit "" goes out "" mov 72h, 76h; When 02h bit is 0, mov 73h and 77h are displayed normally; MOV 74H,78H ; MOV 75H,79H ; INTT1OUT: POP PSW ; Restore site pop ACC; RETI ; Interrupt exit flash1: JB 01h, flash2; When 01h is 1, turn off the control mov 72h, 7Ah; When the 01h bit is 0, the "off" character "data is put into the sub mov 73h, 7Ah; The display unit (72h-73h) will not display the partial data MOV, 74h, 78h; MOV 75H,79H ; AJMP INTT1OUT ; Transfer interrupt exit flash2: mov 72h, 76h; When the 01h bit is 1, the "off" character "data is put into the hour mov 73h, 77h; Display unit (74h-75h), the hourly data will not display mov 74h, 7Ah; MOV 75H,7AH ; AJMP INTT1OUT ; Transfer interrupt exit;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Add 1 subroutine;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ADD1: MOV A,@R0 ; Take the current timing unit data to Adec R0; Point to the previous address swap a; The upper four bits and the lower four bits of data in a exchange ORL a, @ R0; The data in the previous address is put into the low and middle four bits of add a, #01h; A plus 1 operation Da a; Decimal adjustment mov R3, a; Move into R3 register anl a, #0fh; High four position transformer 0mov @ R0, a; Put back the previous address unit mov a, R3; Retrieve the temporary data Inc R0 in R3; Point to the current address unit swap a; The upper four bits and the lower four bits of data in a exchange anl a, #0fh; High four position transformer 0mov @ R0, a; Put the data into the current address unit ret; Subroutine return;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Clearing procedure;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Clock adjustment program;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; When the time adjustment key is pressed, enter this program setmm: CLR ET0; Close timer T0 and interrupt CLR tr0; Close timer t0lcall dl1s; Call the 1s delay program JB P3.7, closedis; Press the key for less than 1 second, and turn off the display (power saving) mov R2, #06h; Enter the time adjustment state and assign the initial value of flashing timing setb ET1; Allow T1 to interrupt setb Tr1; Start timer t1set2: JNB P3.7, Set1; P3.7 port is 0 (key not released), wait for setb 00h; Key release, sub adjustment, flashing flag set 1set4: JB P3.7, set3; Press the wait key lcall dl05s; Press the key, delay 0.5 s, JNB P3.7, Seth; Press for more than 0.5 seconds to adjust the hourly state mov R0, #77h; Press for less than 0.5 seconds plus 1 minute to operate lcall ADD1; Call the plus 1 subroutine mov a, R3; Get the adjustment unit data CLR C; Clear carry flag cjne a, #60h, HHH; Compare the adjustment unit data with 60 HHH: JC SET4; The adjustment unit data is less than 60 rpm SET4 cycle lcall clr0; Clear 0clr C when the adjustment unit data is greater than or equal to 60; Clear carry flag ajmp SET4; Jump to SET4 cycle closedis: setb ET0; Power saving (LED does not display) status. Turn on t0 and interrupt setb tr0; Open t0 timer (open clock) close: JB P3.7, close; No key pressed, wait. LCALL DISPLAY ; Press the key to adjust the display subroutine delay chattering JB P3.7, close; Yes, the interference returns to close and waits for wait: JNB P3.7, wait; Wait for the key to release LJMP start1; Return to the main program (LED data display is on) Seth: CLR 00h; Clear the sub flashing flag (enter the hour adjustment state) sethh1: JNB P3.7, set5; Wait for the key to release setb 01h; Hour adjustment flag 1set6: JB P3.7, Set7; Wait for the key to press lcall dl05s; Press the key with a delay of 0.5 s, JNB P3.7, setout; Press for more than 0.5 seconds and exit time to adjust mov R0, #79h; Press for less than 0.5 seconds plus 1 hour to operate lcall ADD1; Add 1 subroutine mov a, R3; CLR C ; CJNE A,#24H,HOUU ; Comparison of timing unit data with 24 houu: JC set6; Less than 24 rpm set6 cycle lcall clr0; When it is greater than or equal to 24, clear 0 operation ajmp set6; Jump to set6 cycle setout: JNB P3.7, setout1; Time adjustment exit program. Wait for the key to release lcall display; Delayed chattering JNB P3.7, setout; Is jitter, return to setout and wait for CLR 01h; Cleaning hour sign CLR 00h; Clearance and separation mark CLR 02h; Clear flashing flag CLR Tr1; Close timer t1clr ET1; Close timer T1 and interrupt setb tr0; Start timer t0setb ET0; Start timer T0 interrupt (timing start) LJMP start1; Jump back to the main program Set1: lcall display; Call the display program (point adjustment) ajmp se when waiting for key release
Our other product: