The basic format of PIC microcontroller programming

Publisher:DelightWish123Latest update time:2013-03-05 Source: EDNKeywords:PIC 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 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

Keywords:PIC Reference address:The basic format of PIC microcontroller programming

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

Detailed explanation of PIC mid-range microcontroller assembly instructions (1)
NOP No Operation Instruction Syntax: NOP Operands: None Execution time: one instruction cycle Execution process: In addition to consuming one instruction cycle, there is no other impact, so it is usually used as a delay Status flags affected: None Note: The instruction operation does not involve any operands
[Microcontroller]
PIC microcontroller instruction cycle calculation
Every four clock cycles of the PIC microcontroller is an internal instruction cycle. For example: for an 8MHz crystal oscillator, the internal instruction cycle is 1/(8/4) = 0.5 uS Example 1: 35us, 8MHz crystal, 8-bit timer, division ratio 1/2, initial value E4 Example 2: 156.25us, 32768Hz crystal, 8-bit timer,
[Microcontroller]
pic 16 f690 pic 16 f1947 eeprom examples and differences
void WriteEE(unsigned char adds,unsigned char data)         { while(WR==1); //Is the last write operation completed? EEADR=adds; //EEPROM address EEDAT=data; //Prepare to write data into EEPROM EEPGD=0; //point to EEPROM data storage CFGS=0; //point to EEPROM data storage WREN=1; //Enable write operation         GIE=0
[Microcontroller]
PIC microcontroller programming method and basic format
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 pse
[Microcontroller]
Introduction and significance of each pin of PIC16F684
1, VCC: C=circuit means circuit, that is, the voltage connected to the circuit; VDD: D=device means device, that is, the internal working voltage of the device; VSS: S=series means common connection, usually refers to the voltage of the common ground terminal of the circuit; VEE: E=electron usually refers to negative
[Microcontroller]
Introduction and significance of each pin of PIC16F684
PIC10F200 LED running light program
include p IC .h   __CONFIG(0x0ffb);   //Watchdog off, reset pin for reset, no encryption //---------------------------------- //Delay function void delay() {  int i; //Define loop variable  for(i=5000;i 0;i--); //empty instruction, consumes one instruction cycle } //--------------------------------- //Initializati
[Microcontroller]
DS18B20 and PIC microcontroller communication source program
     ORG     PIC54      GOTO    MAIN      ORG     0 ;---------------------- ;---------------------------- DELAY22                     MOVLW   D'200'               ; DELAY 2*250=500mS         MOVWF    COUNT1 DE32    MOVLW   D'250'                ; 8*250=2mS     MOVWF    COUNT2 DE42    NOP                          ; 1+2
[Microcontroller]
LCD routine for PIC microcontroller 1
; LCD_F84.ASM ; LCD_RESET - provides a means for the user to manually reset the LCD ; - brings RA.0 (serial lead) low for 2.5 secs. During this ; time, the user should manually reset the LCD. ; - routine then clears the LCD and ouptuts ten dots. ; - LCD is then cleared again. ; - W and STATUS are saved. ;
[Microcontroller]
Latest Power Management 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号