Here we introduce a timing program to illustrate the application of loop programs on PIC microcontrollers. The author still takes the PIC16F84 microcontroller as an example to establish its timing source program list. The timer source program only needs to change the constant setting of one instruction to make the timing time change continuously from minutes to 3.8 hours (4MHz crystal oscillator condition). For the hardware circuit of the PIC16F84 microcontroller, please see the experimental programmer 1.01 experimental board circuit in the 32nd issue of this newspaper. On this experimental board circuit, if the reader changes the frequency of the crystal oscillator (2MHz, 1MHz, 500kHz), it is easy to see that the timing time increases proportionally, which is very intuitive and interesting for understanding the performance of the PIC microcontroller. If one more loop is set on this source program, the timing time can be extended to more than 1 month.
The PIC16F84 microcontroller timing source program can be directly assembled under the MPLAB integrated development environment software. The HEX file generated after assembly can be used to solidify the source program on the experimental programmer 1.01 and the experimental results can be directly observed on the corresponding experimental board. The source program list for PIC16F84 microcontroller is as follows (each file can be customized):
LIST P=PIC16F84
#INCLUDE P16F84INC
COUNT1 EQU 0x1F
COUNT2 EQU 0x1E
COUNT3 EQU 0x1D
COUNT4 EQU 0x1C
ORG 0
START CLRW ; equivalent to MOVLW 0
BSF STATUS, 5; select body 1
MOVWF TRISB ; set port B to output
BCF STATUS, 5; reset STATUS to current body 0
CLRF PORTB ; timing start function M1 BTFSS PORTA, 1 ; judge the D1 bit of port A, jump when D1=1 , and execute sequentially
when D1=0 GOTO M2 GOTO M1 M2 MOVLW 0xAA ; select the timing bit of port B, LED lights up and starts timing MOVWF PORTB ; Port B outputs DELY CLRW at 0x10101010 ; Equivalent to MOVLW 0 MOVLW 0xFF MVOWF COUNT1 MVOWF COUNT2 MVOWF COUNT3 MOVLW 0 ; Equivalent to CLRW instruction MOVLW 0x02 ; 0x02 sends W (maximum timing is 0xFF) MOVWF COUNT4 ; Timing value control (fine adjustment) LOOP DECFSZ COUNT1, 1 ; CPUNT decreases by 1, jumps to GOTO LOOP DECFSZ COUNT2, 1 ; Same as above, here d=1, GOTO LOOP DECFSZ COUNT3, 1 ; Same as above GOTO LOOP DECFSZ COUNT4, 1 ; Same as above, but the value in COUNT4 can be freely selected GOTO LOOP CLRW ; Same as MOVLW 0 MOVLW 0x02; Timer ends and displays MOVWF PORTB M3 GOTO M3 END; Program ends Description: The constant settings in this source program can be changed by the reader at will, and any time setting can be achieved after the change.
Reference address:PIC microcontroller loop program application example
The PIC16F84 microcontroller timing source program can be directly assembled under the MPLAB integrated development environment software. The HEX file generated after assembly can be used to solidify the source program on the experimental programmer 1.01 and the experimental results can be directly observed on the corresponding experimental board. The source program list for PIC16F84 microcontroller is as follows (each file can be customized):
LIST P=PIC16F84
#INCLUDE P16F84INC
COUNT1 EQU 0x1F
COUNT2 EQU 0x1E
COUNT3 EQU 0x1D
COUNT4 EQU 0x1C
ORG 0
START CLRW ; equivalent to MOVLW 0
BSF STATUS, 5; select body 1
MOVWF TRISB ; set port B to output
BCF STATUS, 5; reset STATUS to current body 0
CLRF PORTB ; timing start function M1 BTFSS PORTA, 1 ; judge the D1 bit of port A, jump when D1=1 , and execute sequentially
when D1=0 GOTO M2 GOTO M1 M2 MOVLW 0xAA ; select the timing bit of port B, LED lights up and starts timing MOVWF PORTB ; Port B outputs DELY CLRW at 0x10101010 ; Equivalent to MOVLW 0 MOVLW 0xFF MVOWF COUNT1 MVOWF COUNT2 MVOWF COUNT3 MOVLW 0 ; Equivalent to CLRW instruction MOVLW 0x02 ; 0x02 sends W (maximum timing is 0xFF) MOVWF COUNT4 ; Timing value control (fine adjustment) LOOP DECFSZ COUNT1, 1 ; CPUNT decreases by 1, jumps to GOTO LOOP DECFSZ COUNT2, 1 ; Same as above, here d=1, GOTO LOOP DECFSZ COUNT3, 1 ; Same as above GOTO LOOP DECFSZ COUNT4, 1 ; Same as above, but the value in COUNT4 can be freely selected GOTO LOOP CLRW ; Same as MOVLW 0 MOVLW 0x02; Timer ends and displays MOVWF PORTB M3 GOTO M3 END; Program ends Description: The constant settings in this source program can be changed by the reader at will, and any time setting can be achieved after the change.
Previous article:Features of PIC8-bit 8-pin microcontrollers 12C5×× and 12CE5×× series
Next article:Application of PIC16F877 Microcontroller--A/D Converter
- Popular Resources
- Popular amplifiers
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- SparkRoad Review (7) - FPGA Serial Port Test
- Disable AD auto-start JLink
- Seeking guidance - stc microcontroller remote upgrade program
- Problems with creating sheet symbols for multi-page schematics
- Zigbee Z-Stack 3.0.1 Modify channels using broadcasting
- SHT31 Review + My Review Summary
- Using AT89S series microcontroller
- 【McQueen Trial】Use IPAD to program McQueen's car
- The STM32 FFT library calculates the amplitude normally, but the phase is different each time. Has anyone encountered this problem?
- EEWORLD University----UCD3138 Analog Front End (AFE) Module