Delay Controller Program Using 89C2051 Single Chip Microcomputer

Publisher:亚瑟摩根Latest update time:2018-03-12 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;***************************************************
;* Delay controller made of single-chip microcomputer 89C2051 *
;* T0 and TT0 are combined to form a second pulse generator *
;* TSBIN is a second counter (binary, 0~60); 21H unit *
;* TMBIN is a minute counter (binary, 0~60); 22H unit *
;* THBIN is a hour counter (binary, 0~24); 23H unit *
;* KEYCODE is the keyboard value; 29H unit *
;* KEYPRE is the key mark word; PSW.5 *
;* When the countdown reaches 00H00M00S, P3.0, P3.1 terminals output *
;* inverted signals. *
;* S1----Time button; S2-Minute button; *
;* S3-Second button; S4-Exit time synchronization *  
;****************************************************

 TMSBIN EQU 20H
 TSBIN EQU 21H
 TMBIN EQU 22H
 THBIN EQU 23H
 KEYCODE EQU 29H
 TT0 EQU 2BH
 OUT EQU 2DH

 KEYPRE BIT PSW.5
 
 DPS1 DATA 11001111B ;S4
 DPM0 DATA 11010111B ;S3
 DPM1 DATA 11011111B ;S2
 DPH0 DATA 11100111B ;S1
 DPH1 DATA 11101111B
 HIDE DATA 11111111B ;Blanking word

 ORG 0000H
 AJMP MAIN

 ORG 000BH
 SJMP I_T0

 ORG 001BH
I_T1: AJMP MAIN1
 RETI

;*********** T0 interrupt service ***********
 ORG 0030H
I_T0: PUSH A CC
 PUSH PSW 
 MOV TH0,#0DCH ;0.01s time, constant factor is DC00H
 ;MOV TL0,#00H 
 CLR C
 MOV A,TMSBIN
 SUBB A,#01H
 MOV TMSBIN,A
 MOV R3,TT0  
 DJNZ R3,I_T01 ;Interrupt times <100 (0.01S per interrupt), transfer out
 CPL KEYPRE
 MOV R3,#100 ;Interrupt times = 100 times, restart the next count
 MOV TMSBIN,#100
 CLR C
 MOV A,TSBIN ;Second counter plus 1
 SUBB A,#01H
 MOV TSBIN,A
 ;SUBB A,#60 ;Second counter>59? Y, second counter = 00
 JNC I_T01
 MOV A,TMBIN
 ADD A,THBIN
 JNZ M1
 MOV OUT,#11111101B
 CLR TR0
 MOV TSBIN,#00H
 SJMP I_T01 
M1: MOV TSBIN,#59
 CLR C
 MOV A,TMBIN ;Minute counter plus 1
 SUBB A,#01H
 MOV TMBIN,A
 JNC I_T01
 MOV A,THBIN
 JZ I_T01
 MOV TMBIN,#59
 CLR C
 MOV A,THBIN ;Hour counter plus 1
 SUBB A,#01H
 MOV THBIN,A
 ;SUBB A,#24 ;Hour counter>23? Y, hour counter=00
 JNC I_T01
 MOV THBIN,#00H 
I_T01: MOV TT0,R3
 POP PSW
 POP ACC
 RETI

 ORG 00F0H
MAIN: MOV P1,#0FFH
 MOV OUT,#11111110B ;P3.0 outputs low level
 MOV P3,OUT
 MOV SP,#40H ;Initialize stack pointer  
 MOV TMOD,#11H ;T0, T1 work as 16-bit timer
 MOV TT0,#100
 MOV TH0,#0DCH ;T0 initial value
 MOV TL0,#00H
 MOV TH1,#00H ;T1 initial value
 MOV TL1,#00H
 MOV TSBIN,#59
 MOV TMBIN,#59
 MOV THBIN,#23
 CLR EX0
 CLR EX1
 CLR ES
 SETB ET0 ;Open T0, T1 interrupt
 SETB ET1
 SETB TR0
 SETB TR1
 SETB EA
MAIN1: MOV R6,#80H ;Main processing
DISP: MOV KEYCODE,#00H
 MOV TH1,#00H
 MOV TL1,#00H
 ACALL DISPLY ;Call display subroutine
 DJNZ R6,DISP
 MOV DPTR,#KEY
 MOV A,KEYCODE ;Read keyboard value
 JMP @A+DPTR ;Press key value to jump to corresponding processing program

KEY: SJMP MAIN1
 SJMP KEY1 ; In sequence: KEY value + 2, 4, 6, 8, because SJMP occupies 2 bytes
 SJMP KEY2 ; S1's KEYCODE = 02H, S2: KEYCODE = 04H
 SJMP KEY3 ; S3: KEYCODE = 06H, S4: KEYCODE = 08H
 SJMP KEY4
KEY1: CLR TR0 ; Hour counter plus 1
 MOV A, THBIN
 CLR C
 ADDC A, #01H
 MOV THBIN, A
 SUBB A, #24 ; 24D
 JC KEY11
 MOV THBIN, #00H
KEY11: SJMP MAIN1
 NOP
KEY2: CLR TR0 ; Minute counter plus 1
 MOV A, TMBIN
 CLR C
 ADDC A, #01H
 MOV TMBIN, A
 SUBB A, #60 ; 60D
 JC KEY21
 MOV TMBIN,#00H
KEY21: SJMP MAIN1
 NOP
KEY3: CLR TR0 ;Increase the second counter by 1
 MOV A,TSBIN
 CLR C
 ADDC A,#01H
 MOV TSBIN,A
 SUBB A,#60 ;60D
 JC KEY31
 MOV TSBIN,#00H
KEY31: SJMP MAIN1 
 NOP
KEY4: MOV TH0,#0DCH ;Exit the time calibration state
 MOV TL0,#00H
 SETB TR0
 SJMP MAIN1


; ********** Display subroutine **************
     ORG 0200H  
DISPLY: MOV A,TSBIN ; Transfer the second counter into A
 MOV B,#0AH
 DIV AB ; Count the second value ÷ 10 (the result is stored in A for tens and in B for ones) 
 SWAP A
 ORL A,#07H ; Display the tens digit of the second
 MOV P1,A
 MOV A,#DPS1
 ANL A,OUT
 MOV P3,A
 ACALL  DSP DEL ; Delay (when displaying) 0.5ms
 MOV C,P3.7 ; Read the status of S4 key
 MOV A,#HIDE
 ANL A,OUT
 MOV P3,A
 JC NP1
 MOV KEYCODE,#08H ; S4 is pressed, keyboard value = 8 
NP1: MOV P1,#0F7H ; Blanking
 NOP
 NOP
 NOP
 MOV A,B ; Display the ones digit of the second
 SWAP A
 ORL A,#07H
 MOV P1,A
 MOV A,#DPS0
 ANL A,OUT
 MOV P3,A
 ACALL DSPDEL
 MOV A,#HIDE
 ANL A,OUT
 MOV P3,A
 NOP
 NOP
 NOP
 MOV A,TMBIN ;
 MOV B,#0AH
 DIV AB ;
 SWAP A ;Display the tens digit of
 minutesORL A,#07H
 MOV P1,A
 MOV A,#DPM1
 ANL A,OUT
 MOV P3,A
 ACALL DSPDEL
 MOV C,P3.7 ;Check if S2 is pressedMOV
 A,#HIDE
 ANL A,OUT
 MOV P3,A
 JC NP2
 MOV KEYCODE,#04H ;S2 is pressed, keyboard value=4
 NOP
NP2: MOV P1,#0F7H ;Hide
 NOP
 NOP
 MOV A,B
 SWAP A ;Display the ones digit of
 minutesORL A,#07H
 MOV P1,A
 ;MOV C,KEYPRE
 ;MOV P1.3,C
 SETB P1.3
 MOV A,#DPM0
 ANL A,OUT
 MOV P3,A
 ACALL DSPDEL
 MOV C,P3.7 ;Judge whether S3 is pressed
 MOV A,#HIDE
 ANL A,OUT
 MOV P3,A

 JC NP3
 MOV KEYCODE,#06H ;If S3 is pressed, the keyboard value = 6
 NOP  
NP3: MOV P1,#0F7H ;Hide
 NOP
 NOP
 MOV A,THBIN ;
 MOV B,#0AH 
 DIV AB ;
 SWAP A ;Tens digit when displayed
 JNZ DISPLY1
 MOV A,#0F7H
DISPLY1:ORL A,#07H
 MOV P1,A
 MOV A,#DPH1
 ANL A,OUT
 MOV P3,A
 ACALL  DSP DEL
 MOV A,#HIDE
 ANL A,OUT
 MOV P3,A
 NOP
 MOV A,B
 SWAP A ;Ones digit when displayed
 ORL A,#07H
 ANL A,OUT
 MOV P1,A
 SETB P1.3
 MOV A,#DPH0
 ANL A,OUT
 MOV P3,A
 ACALL DSPDEL
 MOV C,P3.7 ;Judge whether S1 is pressed
 MOV A,#HIDE
 ANL A,OUT
 MOV P3,A
 JC NP4
 MOV KEYCODE,#02H ;S1 is pressed, keyboard value = 2
 NOP
NP4: MOV P1,#0F7H ;Hide
 NOP
 NOP
 NOP
 RET


;********** Delay subroutine **************8
DSPDEL: MOV R7,#0FFH ; Delay program 0.5ms
 DJNZ R7,$
 RET
 END


Keywords:MCU Reference address:Delay Controller Program Using 89C2051 Single Chip Microcomputer

Previous article:How to display 8 digits in decimal on a seven segment display?
Next article:DS18B20 assembly program and C program

Recommended ReadingLatest update time:2024-11-16 14:29

Detailed explanation of the connection between RXD and TXD of microcontroller serial communication
    I believe many people are confused about how to connect RXD and TXD when the microcontroller communicates with a computer or chip. Because in some circuit diagrams, some are straight connection methods, and some are cross connection methods, which makes people a little confused.          First of all, we need to u
[Microcontroller]
51 single chip microcomputer realizes LED water light (array mode and bit operation mode)
/*  Name: 51 single chip microcomputer realizes LED water light (array mode and bit operation mode) Note: Today I started to study 51 systematically again, and LED is the beginning.  Two points to note:  1. sfr and sbit are keywords extended from C language. sfr is used to declare special function registers, and sbi
[Microcontroller]
Serial port interrupt setting of 51 single chip microcomputer
First, you need to enable interrupts using software. That is, in C language, EA = 1; enable total interrupt ES = 1; //Enable serial port interrupt assembly SETB EA ; Enable general interrupt SETB ES ; Enable serial port interrupt When the microcontroller receives a frame of data, RI will be set to 1 and an i
[Microcontroller]
LPC1768 MCU serial port IAP upgrade example source code
LPC1768 IAP upgrade method example   Test instruction:     This experiment uses serial port 0 to upgrade the development board through IAP. This project is a boot program. Connect the USB to serial port on the development board to the computer.     Plug in the 3.2-inch color screen module, download the program to the
[Microcontroller]
Application of single chip microcomputer in embedded system design
1 Overview With the rapid development of semiconductor technology and the application of mobile communication, network technology and multimedia technology in embedded system design, the development of single-chip microcomputers from 4-bit, 8-bit, 16-bit to 32-bit has always attracted great attention from elect
[Microcontroller]
Application of single chip microcomputer in embedded system design
Some pitfalls in 8-bit microcontroller programming
Since TI 254x uses an 8-bit microcontroller and has only a pitiful 8k of memory, there are some differences from ordinary PC programming, so you must pay attention.   1. Don’t declare arrays that are too large Please always remember that there is only 8k of memory, and if you declare an array that is too large, it wil
[Microcontroller]
MCU software simulation SPI interface
SPI (Serial Peripheral Interfacer) is a synchronous serial communication interface introduced by Motorola, which is used for serial connection between microprocessor controller and peripheral expansion chip. It has now developed into an industrial standard. At present, various semiconductor companies have launched a la
[Microcontroller]
MCU software simulation SPI interface
ADC considerations in C8051F microcontroller
The F020 has a 1.2V, 15×10-6/℃ bandgap voltage reference generator and a two-times gain output buffer on the chip. The 2.4V reference voltage (VREF) can be connected to ADC0, ADC1 and DAC through external pins. VREF has an external load capacity of 200μA (it is recommended to connect a load resistor to ground when d
[Analog Electronics]
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号