When creating a source program, first use the pseudo-instruction TITLE to provide the program title, 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 as follows.
TITLE "This is..."; program title
;Procedure Description
LIST P="16F84",F=1NHX8M
;
include
-config_RC_Qsc&_WDT_0FF…
; Resource definition and variable definition
STATE OF THE HORSE 03
FSR EQU 04
PORTA EQUIPMENT 05
PORTB EQU 06
J EQU 01F
K EQU 01E
;…………………
ORG 0000 ;
goto MAIN ; skip the interrupt vector
ORG 0004
goto INTSRV; subroutine entry address
;……………………………………
MAIN
; Start putting the main program from 0005H
call Initports; port initialization
call InitTimers; timer initialization
…
INTSRV ... ;Interrupt service routine area
SVBRTH… ; Subroutine area
END ; program end character
Of course, you can adjust it 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 the PIC16F84, and then reading it out from the 20H unit.
LIST P="16F84",F=INHX8M
;……………………………
STATUSEQU 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 ; write operation starts
CLRW; Clear W, make W=0
BCF STATUS, RP0; select BANK0
MOVLW 20H
MOVWF EEADR ; address → EEADR
MOVLW 88H
MOVWF EEDATA; write data →
; AUNT
BSF STATUS,RP0 ;选BANK1
BSF EECON1, 2; Write operation enable
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 ; EEPROM
; Data read into W
END
Previous article:PIC microcontroller development issues
Next article:Motor control based on Microchip PIC32MM development board
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