In order to quickly grasp the basic structure of the PIC microcontroller source program, a typical program structure framework is given here. When creating a source program, first use the pseudo-instruction TITLE to provide the title of the program, then give a general description of the entire program, and use the list pseudo-instruction LIST to specify the microcontroller model and file output format used, and then use the INCLUDE pseudo-instruction to read the definition file provided in MPASM, such as "P16F84 INC", and then define the commonly used resources in the chip, and then give the basic structure framework of the general program. An example is given below.
TITLE "This is..."; Program title
; Program description
LIST P="16F84", F=1NHX8M
;
include
-config_RC_Qsc & _WDT_0FF…
;Resource definition and variable definition
STATUS EQU 03
FSR EQU 04
PORTA EQU 05
PORTB EQU 06
J EQU 01F
K EQU 01E
;……………………
ORG 0000 ;
goto MAIN ;Skip interrupt vector
ORG 0004
goto INTSRV ;Subroutine entry address
;……………………………………
MAIN
; Start from 0005H and put the main program
call Initports ; Port initialization
call InitTimers ; Timer initialization
...
INTSRV ... ; Interrupt service program area
SVBRTH... ; Subroutine area
END ; Program end mark
Of course, it can be adjusted according to the actual situation when writing the program. The following is an actual program list, which requires writing data 88H into the 20H unit of the internal EEPROM of PIC16F84, and then reading it out from the 20H unit.
LIST P="16F84", F=INHX8M
;………………………………
STATUS EQU 03 ;Define register
EEDATA EQU 08
EEADR EQU 09
INTCON EQU 0BH
EECON1 EQU 88H
EECON2 EQU 89H
;…………………………
RD EQU 0 ;Define bit
WR EQU 1
RP0 EQU 5
GIE EQU 7
;…………………………
ORG 0
GOTO WRSTART
;………………………………
ORG 10H
WRSTART ;Start writing operation
CLRW ;Clear W, make W=0
BCF STATUS,RP0 ;Select BANK0
MOVLW 20H
MOVWF EEADR ;Address→EEADR
MOVLW 88H
MOVWF EEDATA ;Write data→
;EEDATA
BSF STATUS,RP0 ;Select BANK1
BSF EECON1,2 ;Enable write operation
BCF INTCON, GIE ;Turn off all interrupts
MOVLW 0X55
MOVWF EECON2 ;55H→EECON2
MOVLW 0XAA
MOVWF EECON2 ;AAH→EECON2
BSF EECON1, WR ;Start write operation
BSF INTCON, GIE ;Restore interrupt
RDSTART ;Read operation starts
BCF STATUS, RP0
MOVLW 20H
MOVWF EEADR ;Address→EEADR
BSF STATUS, RP0
BSF EECON1, RD ;Start read operation
BCF STATUS, RP0
MOVF EEDATA, W ;
Read EEPROM data into W
END
Previous article:The difference between ADC delay and settling time
Next article:How to choose and use a power supply
Recommended ReadingLatest update time:2024-11-16 22:47
- Popular Resources
- Popular amplifiers
- MathWorks and NXP Collaborate to Launch Model-Based Design Toolbox for Battery Management Systems
- STMicroelectronics' advanced galvanically isolated gate driver STGAP3S provides flexible protection for IGBTs and SiC MOSFETs
- New diaphragm-free solid-state lithium battery technology is launched: the distance between the positive and negative electrodes is less than 0.000001 meters
- [“Source” Observe the Autumn Series] Application and testing of the next generation of semiconductor gallium oxide device photodetectors
- 采用自主设计封装,绝缘电阻显著提高!ROHM开发出更高电压xEV系统的SiC肖特基势垒二极管
- Will GaN replace SiC? PI's disruptive 1700V InnoMux2 is here to demonstrate
- From Isolation to the Third and a Half Generation: Understanding Naxinwei's Gate Driver IC in One Article
- The appeal of 48 V technology: importance, benefits and key factors in system-level applications
- Important breakthrough in recycling of used lithium-ion batteries
- 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
- WPI Group sincerely invites you to gather in Chongqing to attend the "Ansemester and NXP - Automotive Electronics Innovation Products and Technology Seminar"
- RVB2601 Evaluation Board Trial 5: Remote Audio Acquisition System
- God, please help me find where I am wrong.
- Comparison of three basic triode amplifier circuits
- SinlinxA33 lvds screen configuration
- PCB size measurement, VX9000 optical scanning imaging measuring machine VS imager measurement
- DC Gain of Nanopower Op Amps
- What model can replace the EPM570T144C5 model? Need PIN2PIN compatible
- How does the SPI bus work?
- Xiaomi Mi Band 3 Disassembly