Single chip electronic clock (assembly)

Publisher:532829319hmkLatest update time:2016-09-13 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I am very happy today. I wrote this electronic clock in one go (this is the microcontroller experiment tonight. I remember that when I was self-studying microcontrollers last year, I really couldn’t write this. However, this clock is only static and cannot be modified manually. This is still not perfect. If I have time in the future, I will rewrite it, haha)
 
Electronic clock (compilation) - gududesiling - suixin

count equ 9217 ; define 1s count value, for 11.0592 crystal oscillator, delay 10ms

second equ 30h ; define temporary variable area

second_ge equal 31h

second_shi equal 32h

minute equ 33h

minute_ge equal 34h

minute_time 35h

hour equal 36h

hour_ge equal 37h

hour_shi equal 38h

 

       org 0000h

       sjmp main ; enter the main program

       org 0003h

       reti

       org 000bh ;time0 (timer/counter T0 entry address)

       ljmp int_time0 ; jump to interrupt 0 service routine

       org001bh

       reti

       org 0023h

       reti

 

main:     

       mov r0,#0 ; Initialize the program (the initial value of this program is set to 13:33:22)

       mov second,#22

       mov second_ge,#0

       mov second_shi,#0

       mov minute,#33

       mov minute_ge,#0

       mov minute_shi,#0

       mov hour,#13

       mov hour_ge,#0

       mov hour_shi,#0

 

       mov tmod,#00000001b

       mov th0,#high(65536-count); get the high eight bits of data

       mov tl0,#low(65536-count); get the bottom five bits

       clr tf0

       setbea

       setb et0

       setb tr0 ; start timing

loop:      

       lcall digitor_display ;Call the digital tube scanning display program

       sjmp loop ; The program loops here  

 

;Timer 0 interrupt

int_time0:

       push acc

       push psw

 

       clr tf0

       mov th0,#high(65536-count); get the high eight bits of data

       mov tl0,#low(65536-count); get the bottom five bits

       inc r0

       cjne r0,#100,ret_loop ;The second value increases by one

       sjmp second_add

 

second_add: ; Second value processing

       mov r0,#0

       inc second

       mov a,second

       cjne a,#60, ret_loop

       sjmp minute_add

 

minute_add: ; minute value processing

       mov second,#0

       inc minute

       move a,minute

       cjne a,#60, ret_loop

       sjmp hour_add

 

hour_add: ; Hour processing

       mov minute,#0

       inc hour

       move a,hour

       cjne a,#24,ret_loop

       sjmp hour_reset

 

hour_reset:

       mov hour,#0

 

ret_loop:

       pop psw

       pop acc

       reti ;Interrupt return

 

digitor_display: ;digital tube scanning

       push acc

       push psw

       mov a,second

       mov b,#10

       div ab

       mov second_shi,a

       mov second_ge,b

 

       move a,minute

       mov b,#10

       div ab

       mov minute_shi,a 

       mov minute_ge,b

 

       move a,hour

       mov b,#10

       div ab

       mov hour_shi,a

       mov hour_ge,b

 

       mov p1,#11011111b ; Display the units of seconds

       mov a,second_ge

       mov dptr,#table

       movc a,@a+dptr

       mov p2,a

       lcall delay

 

       mov p1,#11101111b ; Display the tens digit of seconds

       mov a,second_shi

       mov dptr,#table

       movc a,@a+dptr

       mov p2,a

       lcall delay

 

       mov p1,#11110111b ; Display the units of minutes

       mov a,minute_ge

       mov dptr,#table

       movc a,@a+dptr

       mov p2,a

       lcall delay

 

       mov p1,#11111011b ; Display the tens digit of minutes

       mov a,minute_shi

       mov dptr,#table

       movc a,@a+dptr

       mov p2,a

       lcall delay

 

       mov p1,#11111101b ; Display the unit digit of the hour

       mov a,hour_ge

       mov dptr,#table

       movc a,@a+dptr

       mov p2,a

       lcall delay

 

       mov p1,#11111110b ; Display the tens place of the hour

       mov a,hour_shi

       mov dptr,#table

       movc a,@a+dptr

       mov p2,a

       lcall delay

       pop psw

       pop acc

 

       ret ; Scanning program returns

 

table: ; Common cathode digital tube scanning code

       DB 3FH ;0

    DB 06H ;1

    DB 5BH ;2

    DB 4FH ;3

    DB 66H ;4

    DB 6DH ;5

    DB 7DH ;6

     DB 27H ;7

    DB 7FH ;8

    DB 6FH ;9

     

delay: mov r4,#5 ; delay function (delay is about 5*255*2=25ms)

l1: mov r5,#0ffh

l2: djnz r5,$

       djnz r4,l1

       ret  

 

       end        

Keywords:MCU Reference address:Single chip electronic clock (assembly)

Previous article:Implementation of ASM51 calling C51 function
Next article:Assembly bubble sort (51) (need debugger to pay initial value)

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号