The basic structure of PIC microcontroller source program

Publisher:科技火箭Latest update time:2014-08-28 Source: cecb2b Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    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

Reference address:The basic structure of PIC microcontroller source program

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

Keil's method of generating lib from source code,
The program files we generally come into contact with the most are files with .c and .h suffixes. I don’t know if you have ever seen files with the .lib suffix, which are encrypted source code files. We can use the keil development tool to encrypt our .c file into this kind of .lib file. This can achieve the following
[Microcontroller]
OnePlus 10 Pro kernel source code now released
      OnePlus recently released the OnePlus 10 Pro mobile phone worldwide and announced the kernel source code of the phone to facilitate modifications by private experts.   Since the Linux kernel is licensed under the GNU General Public License version 2, all smartphone manufacturers that release Android devices are
[Mobile phone portable]
Analysis and arrangement of Zhilin STM32 program source code 02
1. Analysis of STM32 clock configuration program 1、RCC      RCC stands for Reset and Clock Control. The main registers include control, configuration, interrupt, peripheral reset, peripheral clock enable, and reset status registers.      The core's working clock is SysClk, which has three sources: external clock H
[Microcontroller]
Android 12 source code leak: Google Pixel Fold folding screen equipped with self-developed Tensor chip
Foreign media Android Central reported that according to the source code found in the Android 12 beta version, a device codenamed "Passport" was revealed. This code name may be the rumored Pixel Fold folding screen, which Google may be preparing to release before the end of the year.     In the tweet from cstark27,
[Mobile phone portable]
Android 12 source code leak: Google Pixel Fold folding screen equipped with self-developed Tensor chip
Section 6: The process of compiling .c source code into .hex machine code
Ten years of experience in the industry, teaching you how to get started with microcontrollers Lecture 6: Step 1: Open an existing project. Double-click the "keil uVision4" icon on the desktop to start the keil software. If you find that this software opens a previously existing project by default, please click the "P
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号