PIC8-bit microcontroller source program assembly and curing under Windows (I)

Publisher:huanhuiLatest update time:2011-02-22 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The microcontroller itself does not have the ability to develop programming, so to turn the microcontroller into an application product, it is necessary to use two tools: hardware development and software development. When developing software, first use the relevant editing software to create the source program (mnemonic program) of the PIC microcontroller in the corresponding format, and then assemble the source program. After completing the assembly, the user can use the simulation debugging software (low price) or the hardware online emulator (high price) to run and debug its target program (machine code) to find its errors and modify them. After debugging, modification, and reassembly, the modified target program can be burned into the user's PIC chip with a hardware (tool) programmer. Finally, the burned (i.e. solidified) chip is inserted into the user board (experimental board) for offline operation. If there are still problems (usually under the condition of multiple programs), check the design of the hardware circuit and software, find out the errors, modify, reassemble, and debug until the offline operation is normal.
While launching the PIC series of single-chip microcomputer products, Microchip also launched corresponding software development and hardware development tools, such as PIC online emulator, MPLAB integrated development software, MPSIM software emulator, MPASM macro assembler and PIC universal programmer. In addition, the development of PIC series single-chip microcomputers in China is also very rapid. Many companies or research institutes have also launched corresponding development devices, including both low-priced software emulators and programmers suitable for beginners and high-end development application devices suitable for product development. Some high-end developers can also support C compilers (such as MP-C) and fuzzy logic development systems. These development devices can run independently or online with a PC. In short, the tools for developing PIC single-chip microcomputers are not only very mature but also diverse.
When assembling the source program of the PIC single-chip microcomputer on a PC, it can be done under DOS conditions or under Windows conditions. The following will introduce the methods and steps of assembling the source program under Windows.
1. MPLAB, the PIC integrated development software under Windows
MPLAB is the integrated development software for PC Windows provided by Microchip for PIC single-chip microcomputer development products. MPLAB has developed into many versions from the early days to the present: such as MPLAB V3.01, V3.02, V4.0, V4.99 and V5.0. Each version is backward compatible, so even though there are so many types of PIC microcontrollers, users only need to choose the corresponding version of MPLAB integrated development software to achieve their development goals.
(1) Features and installation of MPLAB
MPLAB is an easy-to-learn and easy-to-use integrated development tool software for PIC microcontroller products. The software consists of tool software such as MPLAB editor, MPLAB project manager, MPASM assembler (Windows version) and MPLAB-SIM simulation debugger. MPLAB can help you debug source code, observe program flow, debug and optimize firmware production design of PIC microcontroller applications. The functions and usage of the above-mentioned various software will be introduced through examples in the next few issues of this newspaper.
MPLAB integrated development software has the following hardware and software configuration requirements for the computer system: Microsoft Windows 3.X, 95 and 98 versions are all acceptable; standard keyboard and mouse; 4MB (preferably 16MB or more) of memory and a VGA or higher monitor. MPLAB is easy to install. Anyone familiar with PCs can use the MPLAB SETUP.EXE file and related prompts in the disk or CD-ROM to install it. If you are a beginner, you can ask a computer expert to install it. When installing MPLAB software, it is best to paste the Microchip/MPLAB shortcut icon on the display screen for easy operation.
(2) MPLAB desktop system
The biggest difference between the Windows operating system and the DOS operating system is the extensive use of graphical operating interfaces. Therefore, dialog boxes are the most common thing users come into contact with during Windows operation. All MPLAB functions can be operated through the menu commands in the MPLAB desktop (dialog box).
After MPLAB integrated development software is installed on your PC, turn on the PC and click the shortcut icon Microchip on the monitor with your mouse to see the MPLAB desktop on the monitor, as shown in the attached figure (V4.99 version). The desktop is a resizable window. The characters on the left of the top of the MPLAB desktop are the title bar (MPLAB); below the title bar is the menu bar (MENU), below the menu bar is the toolbar, and at the bottom is the status bar. The menu bar in the desktop window is a drop-down type.
MPLAB has a total of multiple menu options (9 for V322 and V499, and 8 for V301). All MPLAB functions can be accessed through a drop-down menu. The underlined characters in the menu represent accelerators (Key Accelerators). When the menu is pulled down, click the character key with the mouse to immediately execute the function.
The functions of the various menus of MPLAB will be explained in detail by the author through specific program assembly application examples. 

Chengdu Ding Jinyuan

Knowledge contest question:
26. Send the number 0x08 to the working register W of the PIC16C54 microcontroller. Please write the corresponding source program listing.

2. Create PIC microcontroller source program in MPLAB
The author will take the source program PIC count.ASM of the PIC16C55 microcontroller pulse counting test circuit (when counting, port RA1 is decimal code input and port RB is binary code output) as an example to introduce the method of editing (creating) PIC microcontroller source program in MPLAB integrated development environment. The operation steps are as follows.
(1) Open the MPLAB desktop (window) and blank editing window. Turn on the PC and start running Windows. Under the Windows management program, click the icon Microchip (shortcut) on the display screen with the mouse to start running MPLAB integrated development software. At this time, the MPLAB desktop will be displayed on the screen (see the attached picture in the article "Assembly and Solidification of Source Programs (I)" in the 25th issue of this year). From the MPLAB desktop (window), click the leftmost File in the MPLAB menu bar to open the File drop-down menu. Then click the command New Source in the drop-down menu to open a blank editing window. In this window, type the PIC 16C55 COUNT.ASM source program on the keyboard and edit it (take MPLAB V3.01 as an example):
LIST P=16C55
#INCLUDE P16C5X.INC
COUNT EQU 1EH
ORG 0
START
MOVLW 0
MOVWF PORTB; Set port B to output
TRIS PORTB
CLRF COUNT; Set counter COUNT to zero
LOOP
BTFSS PORTA, 1; Determine whether switch K is pressed?
GOTO INCOUNT; Press switch K to jump to IN-
; COUNT
ENDLOOP
GOTO LOOP; If the switch is not pressed, continue the loop
; Determine
whether INCOUNT
INCFG COUNT, 1; counter COUNT + 1
MOVF COUNT, W
MOVWF PORTB; output count value from port B
DEBOUNCE
BTFSS PORTA, 1; determine whether switch K is released?
GOTO DEBOUNCE; if not released, continue to determine
GOTO LOOP; switch K is released and restart
ORG 0x1FF; reset vector
GOTO START
END
Description: When creating a source program under the MPLAB integrated development environment, the pseudo-instruction List (list selection instruction) indicator should be used at the beginning of the source program file to specify the type (object) of processing. Therefore, the beginning of the above source program is List P = 16C55. The "P=" is the processing type, which means setting the microcontroller to 16C55 (chip). Then the pseudo-instruction #include P16C5XINC is used, which means that MPLAB should read all the set files of the microcontroller F16C55 to be processed (type) into the source program here when needed. This pseudo instruction greatly simplifies the code setting in the source program. For example, PORTB, TRIS and other special function registers are no longer assigned values ​​using the EQU pseudo instruction.
The pseudo instruction immediately following the above in the source program is ORG, which represents the starting address of the program. Therefore, in a source program, the ORG pseudo instruction can be used multiple times as needed to locate. In the above source program, ORG is used twice. It is worth noting that in the PIC series of microcontrollers, the reset vector for the primary product PIC16C54/55 is 1FFH; PIC16C56 is 3FFH; PIC16C57/58 is 7FF; and the reset vectors for intermediate and advanced products are 000H and 0000H. It can be seen that when establishing the source program of the PIC microcontroller, it is very necessary to use some pseudo instructions, which can be used to complete some specific functions for establishing the source program, greatly simplifying the compiled source program. The functions of each instruction after the source program have been explained in the comments and will not be repeated here. 3 The source program file in MPLAB is saved to the specified directory and loaded
On the PC screen, after typing and editing the source program (COUNTASM) with the keyboard, use the mouse button to open the File pull-down menu, select the Save command, and click Save with the mouse button to open the window in Figure 1 (the directory path is C:PROGRA~1MPLAB). In the File Name column of this window (title - Save File As), select the path, enter the file name PIC COUNTASM (user-defined name) with the keyboard, and then click OK with the mouse button to save the source program file with the specified file name PIC COUNTASM to the specified directory. This process is usually called saving the PIC microcontroller (microcontroller) source program (COUNTASM).
In the MPLAB integrated development environment, on the MPLAB desktop, click the File drop-down menu with the mouse button. In the menu, select the Open Source command, and then click OPEN SOURCE with the mouse button to open the dialog box (window) of Figure 2. Select the directory path in this dialog box (same as before). In the "List File Types" column of the window, select Source File, and then use the mouse button to click the arrow button on the scroll groove on the right side of the file name window several times (you can also drag the scroll block on the groove) to transfer the established source program PIC COUNTASM to the file name window. Then use the mouse button to click the source program name PIC COUNTASM, and you can click the file name into the file name column. At this point, the source program is loaded. Click OK with the mouse button, and you can see the source program file appear again in the title bar of the selected path and file name (C:PROGRA~1MPLABPIC COUNT.ASM) on the MPLAB desktop of the PC display as shown in Figure 3. The programmer can confirm that the source program has been saved and loaded.
From the software operation process of establishing, editing, saving and loading the source program COUNTASM in the MPLAB integrated development software introduced above, it can be seen that in order to assemble the source program COUNTASM in MPLAB, it is necessary to perform multiple operations on the PC to achieve the purpose of assembling the source program (the loading step can be omitted).
In order to enable PIC microcontroller beginners to quickly master the source program assembly method, the author recommends that beginners should do more hands-on operations on the PIC microcontroller and repeatedly practice the early assembly operation process of establishing, editing, saving and loading the PIC microcontroller source program, so as to make as few mistakes as possible when learning the assembly method to be introduced, and enhance the confidence in learning the PIC microcontroller source program assembly. For this reason, the author recommends the following simplest PIC microcontroller test source program so that beginners can practice repeatedly.
LIST P=PIC16C84
#INCLUDE P16C84INC
ORG 0
START
MOVLW 0x04
GOTO START
END

Ding Jinyuan, Chengdu

Knowledge contest question:
28. In the above text, in the end instruction MOVLW, what is the value range (0x?) of the number sent to W?

Reference address:PIC8-bit microcontroller source program assembly and curing under Windows (I)

Previous article:How to select PIC microcontroller memory bank 0 or 1
Next article:PIC 8-bit microcontroller source program assembly and curing under Windows (Part 2)

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号