;Dynamic digital clock display experiment reference program
;Use resources:
;1, TMRO timer. Determine the displayed bit and display delay.
;2, TMR1 timer. Second signal is generated.
;3, PORTA port. The bit selection signal of the six common anode digital tubes, low level is effective
;4, PORTC port. The seven segments of the digital tube are not used by RC7.
;Function Description:
;1. The six-digit digital tube dynamically scans and displays the time (format: HHMMSS, 24-hour system).
;2.The clock signal is generated by programming the internal timer hardware unit of the microcontroller.
The purpose of this practical exercise is to make everyone more familiar with the programming of timers and the programming of dynamic scanning displays of multi-digit digital tubes.
;Hardware connection:
;1. All positions of the dip switches S4 and S5 on the experimental board must be set to ON, and the others can be turned off.
;2. It is best to remove the 93C46 and 24CXX memories from the board.
;Original provider of this example: pic16 forum member leef728, thanks to leef728 for sharing this example.
;Verified, edited and annotated by Zhong Guitian (engineer) (forum username: zhongruntian) of the Technical Department of Shenzhen Qianlongsheng Electronic Technology Co., Ltd.
;Website: PIC Microcontroller Learning Network http://www.pic16.com Discussion Forum: http://pic16.com/bbs/
;All rights reserved. Please indicate the source when reprinting. The description text in the file cannot be removed or changed.
;Program file name “TIME.ASM"
;The program list is as follows:
;************************************
LIST P=16F877A
INCLUDE "P16F877A.INC"
ERRORLEVEL -302
;******************************************
__CONFIG _DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_ON&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC;
;***************File register definition**************
CBLOCK 0X20
WAW
YW
BAW
QUR
GEW
SHW
TEMP
COUNTER
S3
DAA
STATUS_TMP
W_TMP
ENDC
;********************Program starts****************
ORG 0000H
NOP ; Reset address
GOTO MAIN
ORG 0004H
;********************Interrupt handler***********
MOVWF W_TMP
SWAPF STATUS,W
CLRF STATUS
MOVWF STATUS_TMP; The above 4 instructions are interrupt scene protection
BCF INTCON,2 ; Clear TMRO interrupt flag
MOVF TEMP,W ; Address of time storage unit
MOVWF FSR
MOVF INDF,W ; Get the time value of a certain bit
CALL BMA ; Display code of the time obtained by looking up the table
MOVWF PORTC ; send digital tube display
COMF DAA,W ; Bit code inversion
MOVWF PORTA ; Light up the corresponding digital tube
RLF DAA,F ; ready to light up the next one
INCF TEMP,F ; Next time storage unit address
BTFSS DAA,6 ; Whether to display all six digits
GOTO RT
MOVLW 01H ;Yes, restart a new round of display
MOVWF DAA
MOVLW 20H ; Re-acquire the address of the time unit
MOVWF TEMP
RT
SWAPF STATUS_TMP,W ; interrupt scene recovery
MOVWF STATUS
SWAPF W_TMP,F
SWAPF W_TMP,W
MOVLW 0XE0 ; assign initial value to timer
MOVWF TMR0
RETFIE
;*******************Main program starts****************
MAIN
BANKSEL TRISA ;Selector 1
MOVLW 00H
MOVWF TRISA; PORTA is set to output
MOVWF TRISC; PORTC is set to output
MOVLW 06H
MOVWF ADCON1; Set port A to a normal digital port
BANKSEL INTCON
MOVLW 00H
MOVWF YIW
MOVWF WAW
MOVWF QIW
MOVWF BAW
MOVWF SHW
MOVWF GEW ; The above 7 instructions clear the time
MOVWF DAA
MOVLW 20H
MOVWF TEMP ; time storage unit address
BSF STATUS,RP0
MOVLW 0X05
MOVWF OPTION_REG ; The divider is used for timing TMR0, and the division ratio is 1:4
BCF STATUS,RP0
BSF INTCON,7 ; Enable interrupt enable bit GIE
BSF INTCON,5 ; Enable TMRO interrupt enable bit
BCF INTCON,2 ; Clear TMRO interrupt flag
MOVLW 0XE0 ; assign initial value to TMRO
MOVWF TMR0
CLRF DAA
INCF DAA,F ;Display bit setting
;****************************************************** *************
KS
CALL DELAY; call 200ms timer program
CALL DELAY
CALL DELAY
CALL DELAY
CALL DELAY ; Call 5 times, exactly 1s
INCF GEW,F
MOVF GEW,W ; Check if the unit digit of the second is 10
XORLW .10
BTFSS STATUS,Z
GOTO KS ; Yes, the ones digit of the second is cleared to 0, and the tens digit of the second is increased by 1
INCF SHW,F
CLRF GEW
CLRF STATUS
MOVF SHW,W
XORLW .6 ; Check if the tens digit of the second is 6 (1 minute and 60 seconds)
BTFSS STATUS,Z
GOTO KS
INCF BAW,F ; Yes, the tens digit of seconds is cleared to 0, and the ones digit of minutes is increased by 1
CLRF SHW
CLRF STATUS
MOVF BAW,W
XORLW .10 ; Check if the points are equal to 10
BTFSS STATUS,Z
GOTO KS
INCF QIW,F ; Yes, the ones place of the minute is cleared to 0, and the tens place of the minute is increased by 1
CLRF BAW
CLRF STATUS
MOVF QIW,W
XORLW .6 ; Check if the tens digit of the minute is 6 (1 hour and 60 minutes)
BTFSS STATUS,Z
GOTO KS
INCF WAW,F ; Yes, clear the tens digit of the minute to 0, and add 1 to the ones digit of the hour
CLRF QIW
CLRF STATUS
MOVF WAW,W
XORLW .4 ; Check if the unit digit is 4 (24-hour system)
BTFSS STATUS,Z
GOTO KS
INCF YIW,F ; Yes, the ones digit of the hour is cleared to 0, and the tens digit of the hour is increased by 1
CLRF WAW
CLRF STATUS
MOVF YIW,W
XORLW .2 ; Check whether the tens digit is 2 or not
BTFSS STATUS,Z
GOTO KS
CLRF GEW ; Yes, set the time back to 00-00-00
CLRF SHW
CLRF BAW
CLRF QIW
CLRF WAW
CLRF YIW
GOTO KS ; Cycle display
;**************************200ms delay program************************
DELAY
NOP
BANKSEL PIE1
BCF PIE1,0 ; Disable TMR1 interrupt
BANKSEL T1CON
MOVLW 24H ;TMR1 frequency division 1:4
MOVWF T1CON
BCF PIR1,0
MOVLW 0X3C
MOVWF TMR1H
MOVLW 0XB0
MOVWF TMR1L ; Initialize TMR1 to 0X3CB0
BSF T1CON,0
LOP
BTFSS PIR1,0 ; Check whether the timing time is up
GOTO LOP
RETURN
;****************************************************** *********
BMA
ADDWF PCL,F ;Investigate the offset
RETLW 0XC0 ;"0" encoding
RETLW 0XF9 ;"1" encoding
RETLW 0XA4 ;"2" encoding
RETLW 0XB0 ;"3" encoding
RETLW 0X99 ;"4" encoding
RETLW 0X92 ;"5" encoding
RETLW 0X82 ;"6" encoding
RETLW 0XF8 ;"7" encoding
RETLW 0X80 ;"8" encoding
RETLW 0X98 ;"9" encoding
RETLW 0XFF
;****************************************************** *********
END ; source program ends
;****************************************************** **********
; The process flow for entering this practical exercise is as follows:
; 1. Create source files and edit source files; Here we introduce a method of creating source files that is different from the previous method. Use the "Notepad" in Windows Accessories to create source files.
; This is a well-known and easy-to-use file editor, and it can easily add Chinese comments. However, there are two points to note. First, the comment before
; The semicolon ”” must be entered in half-width Western characters; secondly, it must be stored in a pre-created dedicated subdirectory with a ”.asm” extension.
; 2. Open MPLAB integrated development environment: First, in the WINDOWS environment, select Start>Programs>Microchip MPLAB>MPLAB command to start MPLAB
; and enter the MPLAB desktop.
; 3. Create a project: Select the menu File>New or Project>New Project, create a new project in a special subdirectory created in advance, and
; Source files created with Notepad are added to the project.
; 4. Build the target files in the project: Select the menu Project > Build All (project > build all files), MPLAB will automatically call MPASM to build the project
; Assemble the source file (.asm) under file management into a hexadecimal target file (.hex).
Previous article:Design of a real-time temperature and humidity measurement and control device based on PIC16F73 single chip
Next article:Temperature measurement program based on 16F877A and DS18B20
Recommended ReadingLatest update time:2024-11-16 13:29
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- WPG Live Broadcast Registration | Thundercomm, Lianda, Qualcomm IOT Platform Solutions and Success Stories
- The rain is a surprise in spring, the valley is clear, the summer is full of grains, and the summer heat is connected
- [Anxinke NB-IoT Development Board EC-01F-Kit] 4. Serial port MQTT networking and information sending and receiving test
- Microchip Live FAQ|ADAS Platform Root of Trust
- Current sampling
- "Non-textbook" analysis of transistors, forget about forward bias and reverse bias!
- Scaling of DSP data
- sampling
- 【Goodbye 2021, Hello 2022】+ Review of my 2021
- How to determine the values of inductance and capacitance in LC filter circuit?