3832 views|0 replies

1379

Posts

0

Resources
The OP
 

Using single chip microcomputer to control and display clock status [Copy link]

This program is also a program that we find interesting when we are working on it.
In fact, the basics
are similar to the program list of electronic species.

msec equ 30h /* Set the starting address of the program segment */

sec equ 31h

min equ 32h

hour equal 33h

org 0000h

ajmp main

org 000bh

ajmp ctc

org 0030h

main:

mov sp,#60h /* set address pointer */

mov hour,#00h

mov min,#00h

mov sec,#00h

mov msec,#00h

mov tmod,#01h

mov th0,#3ch

mov tl0,#0b0h

setb ea /*ea set to 1*/

setb et0 /* et0 set to 1*/

setb tr0 /* tr0 set to 1*/

sjmp $ /* Program step */

ctc:

mov th0,#3ch /* initialize t0 */

mov tl0,#0b0h

inc msec /* point to the next byte of addend msec */

mov a,msec /* send the accumulator to register a */

cjne a,#10,exit /* Compare the first and last numbers */

mov msec,#00h /* set address pointer */

inc sec /* points to the next byte of addend sec */

mov a,sec /* send the accumulator to register a * /

cjne a,#60,exit /* Compare the first and last numbers */

mov sec,#00h /* set address pointer */

inc min /* point to the next byte of addend min */

mov a,min /* send the accumulator to register a * /

cjne a,#60,exit /* Compare the first and last numbers */

mov min,#00h /* set address pointer */

inc hour /* point to the next byte of addend hour */

mov a,hour /* send the accumulator to register a * /

cjne a,#24,exit /* Compare the first and last numbers */

mov hour,#00h /* set address pointer */

exit:

mov scon,#00h /* set address pointer */

mov r0,#31h

mov r1,#03h

loop:

mov a,@r0 /* send internal r0 to accumulator a */

mov b,#10 /* immediate data is sent to b */

div ab /* accumulator a divided by register b*/

mov r2,a /*a is sent to register r2 */

mov a,b /*b is sent to a*/

mov dptr,#tab /* send tab to data pointer */

movc a,@a+dptr /* Send the table lookup data to register a * /

mov sbuf,a / * send a to sbuf */

jnb ti,$ /* direct addressing bit 0 transfer */

clr ti /*ti clears to zero */

mov a,r2 * r2 is sent to register a*/

movc a,@a+dptr /* Send the table lookup data to register a * /

mov sbuf,a / * send a to sbuf */

jnb ti,$ /* direct addressing bit 0 transfer */

clr

inc r0 /* point to the next byte of addend r0 */

djnz r1,loop /* If the counter is decremented by one and is not zero, the loop program starting from loop will be executed */

reti /*ti clears to zero */

tab: /* Define storage area */

db 3fh,06h,5bh,4fh,66h

db 6dh,7dh,07h,7fh,6fh

end /* End of program */

Test steps:

1. Connect the wires on the microcontroller;

2. Input the program into the computer;

3. Turn on the power of the microcontroller and the display will show C_ ;

4. Run the program;

5. Observe the movement of the clock;

6. Change the initial time and continue observing;

7. Turn off the power and put the experimental device back to its original position.

Running result: The clock status is displayed on the chassis (ordinary electronic watch)

flow chart:


start

Set the stack pointer initial value

Set the clock initial time

(milliseconds) +1

points = 60 ?

Y

(milliseconds) cleared to 0

(seconds) + 1

hours =24 ?

Y

(seconds) clear to 0

(points) +1

N

milliseconds = 10 ?

Y

(division) clear 0

(hours) +1

N

Y

(Hours) Clear to 0

Use software to clear SCON to 0

Create a data pointer

Display current data

( R 1 -1) = 0 ?

return

points = 60 ?

N

N

seconds = 60 ?


Friends who are interested can come and do it.

This post is from MCU
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list