6-digit electronic clock made with AT89C2051

Publisher:AlisallllLatest update time:2011-12-06 Keywords:AT89C2051 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The principle of the 6-bit electronic clock using AT89C2051 is shown in the figure below. As long as the hardware connection is correct, success is guaranteed. In addition, the SET button in the figure is used to calibrate the time. Press and hold for more than 2 seconds to enter the calibration time state and shift and exit. Quick touch is used to adjust the time value. The triode can be 9015. It is best to use a red common anode LED digital tube for a higher brightness. Because it is a scanning display mode, the abcdefg pins of each digital tube are connected in parallel by bus. Changing the 510 ohm resistor can change the display brightness.



Electronic clock source program

MCS51 MCU assembly program

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; AT89C2051 clock program; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; The overflow period of timers T0 and T1 is 50MS, T0 is used for counting seconds, T1 is used for flashing when adjusting, ; P3.7 is the adjustment button, P1 port is the character output port, and a common anode display tube is used. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ORG 0000H ;Program execution start address LJMP START ;Jump to label START and execute ORG 0003H ;External interrupt 0 interrupt program entry RETI ;External interrupt 0 interrupt return ORG 000BH ;Timer T0 interrupt program entry LJMP INTT0 ;Jump to INTTO and execute ORG 0013H ;External interrupt 1 interrupt program entry RETI ;External interrupt 1 interrupt return ORG 001BH ;Timer T1 interrupt program entry LJMP INTT1 ;Jump 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, a total of 11 memory units MOV R7,#0BHCLEARDISP:MOV @R0,#00HINC R0DJNZ R7,CLEARDISPMOV 20H,#00H ;Clear 20H (for flag) MOV 7AH,#0AH ;Put in "extinguisher" data MOV TMOD,#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 ;50MS timing initial value (for T1 flashing timing) MOV TH1,#3CH ;50MS timing initial value SETB EA ;General interrupt open

[page]

SETB ET0 ; Enable T0 interrupt

SETB TR0 ; Start T0 timer

MOV R4,#14H; Initial value for 1 second timing (50MS×20)

START1: LCALL DISPLAY ;Call display subroutine

JNB P3.7,SETMM1; When P3.7 is 0, switch to time adjustment program

SJMP START1; jump back to START1 when P3.7 is 1

SETMM1: LJMP SETMM ; Go to time adjustment program SETMM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; 1 second timing program;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;T0 interrupt service routine

INTT0: PUSH ACC; Accumulator stack protection

PUSH PSW; status word stack protection

CLR ET0 ; turn off T0 interrupt enable

CLR TR0 ; turn off timer T0

MOV A,#0B7H ;Interrupt response time synchronization correction

ADD A,TL0; lower 8-bit initial value correction

MOV TL0,A ; Reload initial value (lower 8 bits correction value)

MOV A,#3CH ; High 8-bit initial value correction

ADDC A, TH0

MOV TH0,A ; Reload initial value (high 8-bit correction value)

SETB TR0 ; Start timer T0

DJNZ R4, OUTT0; 20 interrupts have not been received and the interrupt exit

ADDSS: MOV R4,#14H; 20 interrupts to (1 second) re-initialize

MOV R0,#71H ; point to the second timing unit (71H-72H)

ACALL ADD1; Call the add 1 program (add 1 second operation)

MOV A,R3; put the second data into A (R3 is a 2-digit decimal combination)

CLR C ; Clear carry flag

CJNE A,#60H,ADDMM

ADDMM: JC OUTT0; Interrupt and exit when less than 60 seconds

ACALL CLR0 ; Clear the second timer unit to 0 when it is greater than or equal to 60 seconds

MOV R0,#77H ; point to the sub-timing unit (76H-77H)

ACALL ADD1; add 1 minute to the timer unit

MOV A,R3; put the data into A

CLR C ; Clear carry flag

CJNE A,#60H,ADDHH

ADDHH: JC OUTT0; Interrupt and exit when less than 60 minutes

ACALL CLR0 ; Clear the timer unit to 0 if it is greater than or equal to 60 minutes

MOV

[page]

R0,#79H; points to the hour timing unit (78H-79H)

ACALL ADD1; hour timer unit plus 1 hour

MOV A,R3; when data is put into A

CLR C ; Clear carry flag

CJNE A,#24H,HOUR

HOUR: JC OUTT0; less than 24 hours interrupt exit

ACALL CLR0 ; greater than or equal to 24 hours hour timer unit cleared to 0

OUTT0: MOV 72H,76H; when the interrupt exits, move the minute and hour timing unit data to

MOV 73H,77H; enter the corresponding display unit

MOV 74H, 78H

MOV 75H,79H

POP PSW ; Restore status word (pop the stack)

POP ACC ; restore accumulator

SETB ET0 ; open T0 interrupt

RETI ;Interrupt return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Flashing timing program;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;T1 interrupt service routine, used as a flashing indication for the adjustment unit when adjusting the time

INTT1: PUSH ACC; interrupt context protection

PUSH PSW

MOV TL1, #0B0H; install the initial value of timer T1

MOV TH1, #3CH

DJNZ R2, INTT1OUT; Exit interrupt if 0.3 seconds have not passed (50MS interrupt 6 times)

MOV R2,#06H ; Reinstall the initial value of 0.3 second timing

CPL 02H ;0.3 seconds timing to reverse the flashing mark

JB 02H,FLASH1; When 02H is 1, the display unit is "off"

MOV 72H,76H; Normal display when 02H is 0

MOV 73H,77H

MOV 74H, 78H

MOV 75H,79H

INTT1OUT:

POP PSW ;Recovery site

POP ACC

RETI ;Interrupt exit

FLASH1: JB 01H, FLASH2; When 01H is 1, the control will be turned off in the hour

MOV 72H,7AH; When 01H is 0, the "extinguishing character" data is put into the sub

MOV 73H,7AH; Display unit (72H-73H), will not display sub-data

MOV 74H, 78H

MOV 75H,79H

AJMP INTT1OUT ;Transfer to interrupt exit

FLASH2: MOV 72H,76H; When the 01H bit is 1, the "extinguishing symbol" data is placed in the hour register.

MOV 73H,77H; Display unit (74H-75H), hour data will not be displayed

MOV 74H,7AH

MOV 75H,7AH

AJMP INTT1OUT ;Transfer to interrupt exit

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Add 1 subroutine;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[page]

A,@R0; Get the current timing unit data to A

DEC R0 ; point to the previous address

SWAP A; the high four bits and low four bits of data in A are exchanged

ORL A,@R0; the data in the previous address is placed in the lower four bits of A

ADD A,#01H; A plus 1 operation

DA A ;Decimal Adjustment

MOV R3,A ; move to register R3

ANL A,#0FH ; high four bits become 0

MOV @R0,A ; put back to the previous address unit

MOV A,R3; retrieve the temporary data in R3

INC R0 ; points to the current address unit

SWAP A; the high four bits and low four bits of data in A are exchanged

ANL A,#0FH ; high four bits become 0

MOV @R0,A ; data is placed in the current address unit

RET ; Subroutine return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Clearing procedure;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Reset the timing unit

CLR0: CLR A; Clear accumulator

MOV @R0,A ; Clear current address unit

DEC R0 ; point to the previous address

MOV @R0,A ; clear the previous address unit to 0

RET ; Subroutine return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Clock adjustment procedure;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;When the time adjustment button is pressed, enter this program

SETMM: CLR ET0 ; turn off timer T0 interrupt

CLR TR0 ; turn off timer T0

LCALL DL1S ;Call 1 second delay program

JB P3.7, CLOSEDIS; If the key is pressed for less than 1 second, the display will be turned off (power saving)

MOV R2,#06H; Enter the timing state and assign the initial value of the flashing timing

SETB ET1 ; Enable T1 interrupt

SETB TR1 ; Start timer T1

SET2: JNB P3.7, SET1; P3.7 port is 0 (key not released), wait

SETB 00H ;Key release, minute adjustment flashing flag set to 1

SET4: JB P3.7, SET3; Wait for the key to be pressed

LCALL DL05S ;When a key is pressed, the delay is 0.5 seconds

JNB P3.7,SETHH

[page]

; Press for more than 0.5 seconds to switch to hour status

MOV R0,#77H ; Press for less than 0.5 seconds plus 1 minute of operation

LCALL ADD1 ; call the add 1 subroutine

MOV A,R3; Get adjustment unit data

CLR C ; Clear carry flag

CJNE A,#60H,HHH ; Adjust unit data to compare with 60

HHH: JC SET4; adjust the unit data to less than 60 turns SET4 cycle

LCALL CLR0 ; Clear to 0 when the adjustment unit data is greater than or equal to 60

CLR C ; Clear carry flag

AJMP SET4 ; Jump to SET4 loop

CLOSEDIS:

SETB ET0 ; Power saving (LED not displayed) state. Open T0 interrupt

SETB TR0; Start T0 timer (turn on clock)

CLOSE: JB P3.7,CLOSE; No button is pressed, wait.

LCALL DISPLAY ;When a key is pressed, the display subroutine is called to delay and reduce jitter

JB P3.7, CLOSE; Interference return CLOSE wait

WAITH: JNB P3.7, WAITH; Wait for key release

LJMP START1 ; Return to the main program (LED data display is bright)

SETHH: CLR 00H; Clear the minute flashing mark (enter the hour adjustment state)

SETHH1: JNB P3.7,SET5 ; Wait for key release

SETB 01H ; Hour adjustment flag set to 1

SET6: JB P3.7, SET7; Wait for the button to be pressed

LCALL DL05S; 0.5 second delay when a key is pressed

JNB P3.7, SETOUT; Press for more than 0.5 seconds to exit time adjustment

MOV R0,#79H ; Press time less than 0.5 seconds plus 1 hour operation

LCALL ADD1 ; add 1 subroutine

MOV A,R3

CLR C

CJNE A,#24H,HOUU ; Timing unit data compared with 24

HOUU: JC SET6; less than 24 turns SET6 cycle

LCALL CLR0 ; Clear to 0 when greater than or equal to 24

AJMP SET6 ; Jump to SET6 loop

SETOUT: JNB P3.7, SETOUT1; Exit the program after adjusting the time. Wait for the key to be released

LCALL DISPLAY; delay and jitter reduction

JNB P3.7, SETOUT; if it is jitter, return to SETOUT and wait

CLR 01H ; Clear hour mark

CLR 00H ; Clearing and adjustment mark

[page]

CLR 02H ; Clear flashing flag

CLR TR1 ; Close timer T1

CLR ET1 ; turn off timer T1 interrupt

SETB TR0 ; Start timer T0

SETB ET0; Open timer T0 interrupt (timing starts)

LJMP START1 ; Jump back to the main program

SET1: LCALL DISPLAY; Call the display program (adjustment) when the key is released

AJMP SET2 ; Prevent no clock display when key is pressed

SET3: LCALL DISPLAY ; Clock display while waiting for the adjustment button

AJMP SET4

SET5: LCALL DISPLAY; Call the display program (adjust hours) when the key is released and waiting

AJMP SETHH1 ; Prevent no clock display when key is pressed

SET7: LCALL DISPLAY; Clock display when waiting for the hour adjustment button

AJMP-SET6

SETOUT1:LCALL DISPLAY ; Wait for key release when exiting clock adjustment

AJMP SETOUT ; Prevent no clock display when key is pressed

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Show program;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Display data in 70H-75H unit, using six-digit LED common anode digital tube display, P1 port output segment code data, P3 port as

; Scan control, each LED digital tube lights up for 1MS and then cycles bit by bit.

DISPLAY:MOV R1,#70H ; point to the display data first address

MOV R5,#0FEH ; Scan control word initial value

PLAY: MOV A,R5 ; scan word and put it into A

MOV P3,A ; output from P3 port

MOV A,@R1; Get display data to A

MOV DPTR,#TAB ; Get the segment code table address

MOVC A,@A+DPTR; check the corresponding segment code of the displayed data

MOV P1,A; put the segment code into P1 port

LCALL DL1MS ;Display 1MS

INC R1 ; point to the next address

MOV A,R5; scan control word into A

JNB ACC.5,ENDOUT ;When ACC.5=0, the display ends once

RL A; data in A is circularly shifted to the left

MOV R5,A ; put back into R5

AJMP PLAY ; Jump back to the PLAY loop

ENDOUT: SETB P3.5; one display ends, P3 port reset

MOV

[page]

P1,#0FFH; P1 port reset

RET ; Subroutine return

TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0FFH

;共阳段码表 "0""1""2" "3""4""5""6""7" "8""9""不亮"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Delay program;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;1MS delay program, LED display program

DL1MS: MOV R6,#14H

DL1: MOV R7,#19H

DL2: DJNZ R7,DL2

DJNZ R6,DL1

RIGHT

;20MS delay program, using the display subroutine to improve the LED display flickering phenomenon

DS20MS: ACALL DISPLAY

ACALL DISPLAY

ACALL DISPLAY

RIGHT

; Delay program, used to judge the length of time the key is pressed

DL1S: LCALL DL05S

LCALL DL05S

RIGHT

DL05S: MOV R3,#20H; 8 milliseconds*32=0.196 seconds

DL05S1: LCALL DISPLAY

DJNZ R3,DL05S1

RIGHT

END

Keywords:AT89C2051 Reference address:6-digit electronic clock made with AT89C2051

Previous article:Environmental Noise Measuring Instrument Based on 89C51 Single Chip Microcomputer
Next article:A brief analysis of the design method and application of rehabilitation equipment based on single chip microcomputer

Recommended ReadingLatest update time:2024-11-16 15:37

Electronic clock (DS1302+AT89C2051 infrared remote control clock)
;Data code of each button of the remote control, the corresponding key code can be modified according to different remote controls muteM EQU 10h ;Mute key alarm on/off timerT EQU 0Ch ;Menu key enter/exit setting state leftL EQU 46h ;Left shift key  rightR EQU 47h ;Right shift key upU EQU 19h ;Increase key downD EQU 1d
[Microcontroller]
Design of remote current data acquisition system based on power line carrier technology
Introduction: This paper introduces a remote current data acquisition system using semiconductor magnetoresistive current sensor (MRCS) and LM1893 chip. The system hardware mainly consists of AT89C2051 single-chip microcomputer main control circuit, serial ADC0832 analog/digital conversion circuit, LM1893 power line c
[Microcontroller]
Design of remote current data acquisition system based on power line carrier technology
Kitchen timer based on AT89C2051 microcontroller
The device uses 5 minutes as a timing unit and can last up to 1 hour. It uses a 3V battery as the power source and has a buzzer alarm. The power consumption is about 6mA when working (using AT89C2051). It can use a 3V button battery and has an automatic shutdown function. The power consumption is negligible when not
[Industrial Control]
Kitchen timer based on AT89C2051 microcontroller
How to make a countdown timer using AT89C2051 microcontroller
The countdown timer is very useful in daily life. It is made by using a microcontroller. Not only the circuit is simple, but the functions can be designed according to the needs. There are many countdown timers designed by 74 series and 40 series small-scale digital chips, but they have shortcomings such as unintuitiv
[Microcontroller]
How to make a countdown timer using AT89C2051 microcontroller
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号