The basic framework of PIC microcontroller programming

In order to quickly grasp the basic structure of the PIC microcontroller source program, a typical program structure framework is given here. When creating the source program, first use the pseudo instruction TITLE to provide the title of the program, then give the general description of the whole program, and use the list directive LIST to specify the type of the microcontroller used and the file output format, and then use the INCLUDE directive to read the definition file provided in MPASM. For example, "P16F84INC", then define the common resources on the chip, and then give the basic structure of the general program. The examples are as follows.

TITLE "This is......"; program title; program description
LIST P=16F84, F=1NHX8M
;
Include
-config_RC_Qsc &_WDT_0FF...
; resource definitions and variable definitions
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; starting from 0005H
Call Initports ; port initialization
Call InitTimers; timer initialization...
INTSRV ... ; interrupt service program area
SVBRTH... ; subroutine area
END; program terminator, of course, can be adjusted according to the actual situation when writing the program. Below is a list of actual programs that require data 88H to be written to the 20H unit of the PIC16F84 internal EEPROM and then read 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 ; definition bit
WR EQU 1
RP0 EQU 5
GIE EQU 7
;..............................
ORG 0
GOTO WRSTART
;.................................
ORG 10H
WRSTART ; write operation begins
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 enable enable
BCF INTCON, GIE; close all interrupts
MOVLW 0 x55
MOVWF EECON2 ;55H→EECON2
MOVLW 0 xAA
MOVWF EECON2 ; AAH→EECON2
BSF EECON1, WR; initiate write operation
BSF INTCON, GIE; resume open interrupt
RDSTART ; read operation begins
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 in W
END

Adapter Ring

Adapter Ring,Lens Adapter Ring,Camera Adapter Ring,Filter Adapter Ring

SHAOXING COLORBEE PLASTIC CO.,LTD , https://www.colorbeephoto.com