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). Setting one more loop on the source program can make the timing time last for 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 P16F84?INC
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
Note: 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:PIC Microcontrollers: Read-Modify-Write Problems and Solutions
Next article:Design of Inclination Sensor Based on PIC Microcontroller
- Popular Resources
- Popular amplifiers
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
- Discussion: How many spacings should be used to drill a GND via in RF high-speed PCB design? [Repost]
- Selection of current resistance of switching power supply MOS
- Qorvo frequently promotes 5G and releases chips to make headlines?
- 5G's new Ultra-high Bands
- Switching Power Supply Study Group
- Is the Tsinghua virtual student singing a real person AI face replacement? The R&D team responds again!
- Sand built on gold - Qorvo announces acquisition of Cavendish Kinetics
- Can multiple ADCs simultaneously acquiring a signal improve system performance?
- Study of TMS320F28335 ADC module
- C8051F340 delay issue