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 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 given below.
TITLE "This is..."; program title
;Procedure 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 the interrupt vector
ORG 0004
goto INTSRV; subroutine entry address
;……
MAIN; start 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
;……
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 ; 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→
;EEDATA
BSF STATUS, RP0; select 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:Software and hardware design of embedded CAN intelligent node
Next article:Detailed explanation of the relevant knowledge of the microcontroller controlling the I/O port of the device
Recommended ReadingLatest update time:2024-11-15 15:27
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- Detailed explanation of the structure, principle, and considerations of SAW and BAW filters
- From ERM to X-axis LRA, TI provides you with a comprehensive Haptics Solution
- Single-cell Li-ion battery fuel gauge and low cutoff current charging IC
- I'm a newbie and need help. How to declare lcd_wdat? Please help me.
- 【TI mmWave Radar Evaluation】+Configuration File Test (Part 2)
- [AT-START-F425 Review] + Get MCU 96-bit unique ID, FLASH size
- Looking for a car charger IC with dual port output power of 40W or more C+A port
- Why does the ripple of a switching power supply increase as the output voltage decreases?
- TI Live: Overview and application introduction of 60G millimeter wave sensors, "packaged antenna" makes building and factory detection solutions simpler
- MaixSense R329 Development Board Unboxing