Composition of PIC series 8-bit microcontroller source program

Publisher:TranquilWhisperLatest update time:2011-02-22 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The source program of the PIC series microcontroller refers to the program written by the mnemonic instructions of the PIC (assembly language program). Here we will briefly introduce the format requirements of the PIC source program and the establishment or writing of the source program.
Generally speaking, there is no unified writing format for the source program format of the PIC microcontroller. Users can write according to their habits. Of course, some assembly specifications should be followed when writing. The following uses the assembly program example of the PIC16F84 chip to light up a light-emitting diode to introduce a method (format) of source program writing for reference in practical applications.
Source program listing
1File TURNON.ASM
2Assembly code for PIC16F84 microcontroller
3Turns on an LED connected to B0
4Uses RC oscillator,about 100kHz
5CPU configuration
6(it's a 16F84,RC oscillator
7watchdog timer off, power-up timer on)
8processor 16F84
9include
10_config_RC_OSC&_WDT_OFF&_PWRTE_ON
11Program
12org 0; start at address 0
13At startup, all ports are inputs
14Set Port B to all outputs
15m ovlw B'00000000'; w=binary 00000000
16tris Portb; copy w to port B control reg
17. Put a 1 in the lowest bit of port B.
18. movlw B'00000001'; w = binary 00000001
19. movwf portb; copy w to port B itself
20. Stop by going into an endless loop
21. fin: goto fin
22. end; program ends here
Now we will explain the source program line by line.
The first line is the file name, which is named TURNON. ASM. TURNON means a turn-on (i.e., turn on LED) program. ASM is the extension of the source program.
The second line shows that it is a source program written in assembly code suitable for PIC16F84 microcontroller.
The third line shows that the purpose of the program is to turn on the B0 bit LED of PIC16F84 PORTB.
The fourth line shows that the clock is provided by the RC oscillator with a frequency of about 100kHz.
Lines 5, 6, and 7 explain the structural settings of the 16F84 CPU (using an RC oscillator, the watchdog timer is off, and the power-up timer is on. The structural settings of the 16F84 will be discussed in detail later).
Lines 8, 9, and 10 are pseudo instructions. This is used to provide the assembler with control command information on how to complete the assembly. It is both a control instruction for the assembly process and an operating instruction for the assembler. Here, lines 8, 9, and 10 also explain to the assembler that the microcontroller is a 16F84, using an RC oscillator, and the watchdog timer is turned off and not used, but the power-up timer is turned on and used. Comparing lines 5 and 6, it can be seen that the two have the same content, but one is a comment specifically for the user, and the other is a pseudo instruction, which provides command information for the PC assembler.
Line 11 is another comment, indicating that the main body of the program starts here.
Line 12 indicates that the program is stored in the program memory of the 16F84 microcontroller starting from address 0, which is also a pseudo instruction.
Lines 13 and 14 are comments, explaining the role of the following instructions (two sentences), that is, at startup, all ports are input, and then port B is set to full output (that is, all bits are output).
Line 15 is the first instruction written in assembly language, that is, the binary (B) number "00000000" is stored in the working register W.
Line 16 transfers the content of the W register (that is, 00000000) to the control register of port B, making port B an output port. Lines 15 and 16 are both commented. Line 17 is a comment, explaining that the following two instructions are to make the lowest bit of port B 1.
The instruction in line 18 sends the binary number 00000001 to the working register W, and the instruction in line 19 copies the content of the W register to port B, then the lowest bit B0 of port B is high, and the rest of the bits are low, making the LED connected to bit B0 light up.
Line 20 is another comment. It means that the following instructions will make bit B0 continue to be high.
The instruction in line 21 is an infinite loop statement, which keeps the output of port B1 high.
Line 22 is the pseudo instruction END, indicating that the program ends here.
After assembling the programs listed in the list on a PC using an assembly software called MPASM, if there are no errors, you can get the corresponding machine code file with the extension name HEX. With the help of a programmer, burn the corresponding content of the file into the program memory of the PIC16F84 microcontroller, insert the programmed chip into the aforementioned circuit board, and add power to light up the LED at position B0 of the 16F84.
Reference address:Composition of PIC series 8-bit microcontroller source program

Previous article:The basic format of PIC microcontroller programming
Next article:Assembly language for PIC 8-bit microcontrollers

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号