Programmer EN
Programmer EN
Programmer EN
MS Micro Controller
MS Designed By Origin-gd Tech
Page 2
1. How to determine the version of the emulator and upgrade the software and firmware? ................................. .................. 1
2. Can I download HEX to the chip with an emulator? ..................................... ............ ........................... 1
3. During simulation, can PA0 and PA1 continue to be used as ordinary IO ports? ............................ 1
4. How to use the emulator for debugging? ........................................ ......... ......................................... ...... 1
5. How to deal with the download failure during simulation? ...................................... ........... ........................... 2
6. How to perform external power supply simulation through the simulator? ..................................... ............ ........................... 2
Chapter 2 Frequently Asked Questions of the Writer and the Software of the Writer... ................................. ............. 3
1. How to power the writer and what is the power supply voltage? ................................... .............. ........................... 3
2. How to see if the writer is connected to the computer? .................................... ............. ................................... 3
3. Where can I view the burner software version and the burner firmware version, and how to update? ............................. 3
4. How to import HEX and EEPROM.BIN into the writer software? ................................... ............... ................. 3
5. Do I need to set the configuration bit before importing the compiled HEX to the writer? ............................... .......... 3
6. How to set the programming voltage of the writer? ...................................... ........... ....................................... .... 4
7. What are the functions of the Auto Program button of the writer software and other buttons such as Erase and Blank Check? .......... 4
8. There is no MS84Fxx04 series model in the writer software? ..................................... ............ ....................... 4
9. How to prompt if the programming is successful or failed? ..................................... ............ ...................................... ..... 4
10. HEX has been encrypted, there is information that can be read by the burner? ................................ ................. .. 4
Origin-gd Tech
11. How to read back the check code of the chip through the writer? .................................. ............... ..................... 4
12. How to connect the burner to the automatic burner to burn? .................................... ............. ......................... 5
13. How to realize the function of only checking Checksum and not burning through the burner? ................................ ............. 5
14. Can the programmer only connect to four wires VCC, GND, CLK, and DAT for programming? ............................. .......... 5
15. The writer succeeded in programming the chip for the first time, but what was the reason for the failure in the second time? ....................... ............5
16. How to use the writer to burn the chip on the board? ................................... .............. .................................... . 6
17. Support jumper cap jumper, how to use the model of programming holder? ........................ ............... ............. 6
18. How to use a burner to burn in rolling code? ..................................... ............ ............................... 1 1
1. Can the two platforms of MPLAB IDE or MPLAB X IDE be used to develop MS microcontrollers? ................. 12
2. I am not used to editing code on ORIGINIDE platform, can I edit it with other code editing software? ........ 12
www.origin-gd.com
Page 3
4. Prompt "File not exist" or "No such fileor diretory", how to deal with the included header file? ......... 12
5. How to add custom header files to the project? ...................................... ........... ......................... 1 3
6. When using the new ORIGINIDE to compile the old project, the pop-up compile option is gray, how to deal with it? ........ 13
7. When the emulator is emulating, can the PA0 and PA1 of the chip continue to be used as ordinary IO ports? ..................... 13
8. Does the watchdog have any effect when using ORIGINIDE emulation? ..................................... ............ .......... 1 3
9. The same project can be compiled and passed on other computers, but not on some computers? ............... 13
11. Can only HEX files be burned by ORIGINIDE? ....................................... .......... ........... 1 4
1. How to call the header file? ......................................... ........ .......................................... ....... ....... 1 5
2. When using assembly programming, how to protect the interrupt on site? ................................... .............. ................. 1 5
3. After the chip is initialized, why does it not work to operate the common IO register PORTA/PORTC? ....................... 16
4. Why is the IO pin not high when the chip IO is pulled up internally? ................................ ........16
5. How can the lowest standby current be achieved when the chip sleeps? ................................... .............. ................. 1 6
6. What is the function of the pseudo instruction BANKSEL? ...................................... ........... ................................. 1 6
Origin-gd Tech
2. About EEPROM initialization............................................ .................................................. ....... 1 7
8. Regarding the operation of special registers and RAM, bank switching........................... . .......................... 1 8
12. Regarding bit data types and variables... ....................................... .......... ..... 2 1
www.origin-gd.com
Page 4
Chapter 6 Frequently Asked Questions about Using MS8xF ... ....................................... .......... .... 2 4
1. Is the internal circuit of the chip the same for models of the same series? ................................ ................. ............. 2 4
3. How many points should be paid attention to in low-power applications? .................................. ............... ................................... .. 2 4
4. The IO of MS81F still cannot input or output normally after TRIS (such as TRISA) register is set? ....... twenty four
5. The IO of MS83F still cannot input or output normally after setting TRIS and CMCON0 registers? ............ 25
6. After setting TRIS, CMCON0 and ANSEL on the IO of MS84F, it still cannot input or output normally? ......... 25
7. What are the clock cycle and instruction cycle of MS microcontroller? .................................... ............. ....... 2 5
8. How to clear the interrupt with IO level change interrupt (IOCA)? ........................ ............... ............. 2 5
9. Precautions for internal fixed reference voltage of MS83F and MS84F...................................... .................... 2 5
10. When using ADC, the converted AD value is inaccurate... ................................... ..... 2 6
11. Why do LCALL and LJUMP with more than 2K space in the assembler go wrong......................... .... 2 6
Origin-gd Tech
www.origin-gd.com
Page 5
1. How to determine the version of the emulator and upgrade the software and firmware?
Not possible. If you want to download the program with the chip, you can only click build all and download the program after the compilation is passed
To the chip. That is to say, it is necessary to have source code that can be effectively compiled successfully, before the HEX program corresponding to the source code
Download to the chip. At the same time, the configuration bit of the program downloaded through build all is consistent with the configuration bit set by the user.
For example, CPD has selected Enable, and the downloaded chip is already code protected.
3. During simulation, can PA0 and PA1 continue to be used as ordinary IO ports?
Not possible. During simulation, LINK will occupy PA0 and PA1 to communicate with the chip internally, so it can't be used as normal during simulation.
Origin-gd Tech
IO port use. After the download is complete, disconnect from LINK, and re-power on, PA0 and PA1 can achieve normal
IO port function.
1. After connecting the emulator LINK to the computer with USB, select the LINK with the 3 voltage options in the upper right corner.
Power supply mode for the chip-the emulator supplies power to the chip and the external power supply supplies power to the chip.
a. There are 3 voltage options for the emulator to power the chip: 3.3V, 3.7V, 5V
b. To supply power to the chip from an external power supply, jump the jumper to the External, and connect the external power supply VCC to the P1 terminal of the emulator
Connect the external power supply GND terminal to the GND of the P1 port of the emulator, and the external power supply voltage cannot exceed
5.5V;
Note: When using the power supply voltage of the emulator, external power supply to the target board is prohibited. Loading two power supplies at the same time has a great risk of damage
Bad Link
2. Connect the four pins VCC, GND, CLK, and DATA on the right side of the LINK to the VCC, GND, PA0, and
PA1;
3. After opening the project, click the Build All button and the compilation options will pop up. After the compilation options are selected, ORIGINIDE is
www.origin-gd.com Page:1
Page 6
The download failure is generally divided into two cases, one is to use Link to connect the chip alone to download the failure, and the other is to use on-board debugging
The download failed at the time.
In view of the first case, the analysis is divided into the following steps:
1. Check whether multiple projects are opened at the same time;
2. Check whether the firmware version of ORIGINIDE and Link is the latest;
3. Check if the connection between Link and chip is correct and stable. Note that PA0 of the chip is the clock pin, connected to the CLK of Link,
The PA1 of the chip is the data pin, which is connected to the DATA of Link. The opposite of this PIC (the RA0 of the PIC is the data pin
ICSPDAT, RA1 is the clock pin ICSPCLK);
4. Check whether the voltage of LVR in the code option is higher than the output voltage of Link. If the chip has been successfully burned
The LVR setting is higher than the output voltage of Link. Before entering the programming mode, the chip is already low due to LVR.
Press reset, so the programming will fail. The chip must be erased separately ("Debug"->"Erase" in the menu bar),
Burn again
5. Check if WDTEN is selected as Enable in the compilation options, it should be Disable. If the core has been burned successfully
The timeout time of the WDTCON register of the chip is set to a lower value, which will cause the program to be programmed again before the program is successfully programmed.
WDT timeout reset. Also need to erase the chip separately (menu bar "Debug" -> "Erase"), and then
Burn
6. Check if the chip model is mixed, replace the chip for test.
7. Check whether the Link is normal, and replace the Link test;
For the second case, analyze it in the following steps:
Origin-gd Tech
1. Use Link to connect the chip separately, and check according to the first situation. If it can be downloaded, proceed to the next step;
2. Check if there is a large capacitance between VCC and GND of the board chip, if so, please remove it;
3. Check whether there are capacitive devices or other components on the CLK and DAT pins of the chip that affect the download communication level;
4. Check whether the reset pin function of the chip is turned on. Set MCLRE in the compile option to PA3/PA5;
1. Change the voltage selection jump of the emulator from 3.3V/3.7V/5.0V to External;
2. Connect the external power supply VCC terminal to the VCC of the P1 port of the emulator;
3. Connect the GND terminal of the external power supply to the GND of the P1 port of the emulator;
www.origin-gd.com Page:2
Page 7
1. How to power the writer and what is the power supply voltage?
Power supply .
First connect the burner to the computer via a USB cable. After the driver is installed (the driver comes with the burner), open the burning software
Pieces. If the version number of the burner appears under the Guangdong origin LOGO on the upper right of the burning software, such as: DRV Ver:
02.00.00.09 means that it has successfully connected to the computer.
3. Where can I view the burner software version and the burner firmware version, and how to update?
The software version number of the writer is displayed in the upper left corner of the software, such as OriginWriter V3.4.
The burner firmware version number is displayed after DRV Ver under the icon at the top right of the burner software, such as V2.1.4.
The firmware can be upgraded or downgraded by clicking the small icon above DRV Ver:. After clicking the icon, a confirmation box will pop up,
After confirming, wait for about 2 minutes, the writer will automatically complete the update.
After the firmware update is complete, you need to re-plug the USB and reconnect. After the re-connection is successful, the current DRV Ver will be displayed.
Previous firmware version number.
Origin-gd Tech
a. After selecting the chip model, the writer software will automatically pop up the burn file directory option box;
b. If you need to burn HEX files, select HEX files. If you do not need to burn the HEX file, select Cancel.
After the selection is completed, the burner will automatically pop up the directory option box, select the EEPROM file;
c. If you need to burn EEPROM, select BIN file. If you do not need to burn the BIN file, select Cancel;
Select the HEX file separately, the writer will only burn the corresponding program area and will not affect the original EEPROM number of the chip
according to;
d. Select the EEPROM file separately, the writer will only burn the corresponding EEPROM area, and will not affect the original chip
Program data;
e. If neither HEX nor EEPROM is selected, the data of the chip on the writer can only be read through the programming software.
5. Do I need to set the configuration bit before importing the compiled HEX to the writer?
No need. The HEX compiled in ORIGINIDE already contains the configuration bits configured before compilation. So, guide
When importing HEX to the writer, there is no need to set configuration bits.
www.origin-gd.com Page:3
Page 8
There is a jumper in the upper right corner of the writer, which can be adjusted to 3V or 5V. The default is to jump at 3V.
7. burner software Auto Program buttons and other Erase , Blank the Check and other press
After clicking the Device/Load button, a dialog box for selecting the chip model will pop up. If there is no serial number of the current chip,
Need to check:
1. Whether the writer is online normally. (Does the DRV Ver display the burner firmware number?)
Origin-gd Tech
9. How to prompt if the programming is successful or failed?
When the red burning button is pressed, the green light and red light will go out together. If the programming is successful, the green light will be on; if
If the programming fails, the red light will be on and the buzzer will alarm.
10. HEX has been encrypted, there is information that can be read by the burner?
11. How to read back the check code of the chip through the writer?
Place the chip on the writer according to the programming pins or effectively connect it to the writer through a wire, click on the writer
KEY_MODE button, the writer will beep once and display “IC's checksum: “XXXX” on the display,
If this result does not appear, you need to check whether the connection is correct or whether the program is configured in external crystal mode.
www.origin-gd.com Page:4
Page 9
PROGRAM, BUSY, OK, FAIL, GND and GND silkscreen on the back of the 20-pin horn holder of the V2.0 writer
The unmarked pins (+3V) below are connected to the START, BUSY, OK, NG,
GND, VCC. Set the start level, BUSY level, OK level, NG level in the setting options of the writer
Set it to L and use the default settings for other times.
13. How to realize the function of only checking Checksum but not burning through the burner ?
Download the program that needs to be verified into the writer, and press and hold the KKEY_MODE button until the screen shows on the writer
The working mode of the writer is “Write Flash”. At this time, press the red button to switch the writer mode to “Check
checksum num".
There are the following modes under the Write function (the writer will automatically select the mode when downloading the program, it is not recommended to switch manually):
a.Write Flash: Programming chip HEX
b.Write Flash EEPROM: Programming chip HEX and EEPROM.BIN
c.Write Fla EEP Rcode: Programming chip program HEX and EEPROM.BIN programming rolling code
d.Write Fla EEP Rd FOSC: Burn chip program HEX and EEPROM.BIN to burn rolling code and calibrate frequency
e.Write Flash Rcode: Programming chip HEX, burning rolling code
f.Write Fla Rd FOSC: Burn the chip program HEX, burn the rolling code and calibrate the frequency
g.Write Fla FOSC: burn chip program HEX and calibrate frequency
h.Write Fla EEP FOSC: burn chip program HEX and EEPROM.BIN and calibrate frequency
i.Write EEPROM: Write EEPROM.BIN
j.Write EEPROM R_code: Write EEPROM.BIN and rolling code
There are three modes under the Check function:
a.Check FOSC: Check the chip frequency (checking the chip frequency will erase the internal data of the chip, you need to re-check after checking
Burn)
b.Check Flash: Check the program (only applicable when the code is not encrypted CPB=Disable)
c.Check checksum num: Checksum of the check chip (can be connected to the machine to automatically detect)
Origin-gd Tech
14. Can the programmer only connect to four wires VCC , GND , CLK , and DAT for programming?
Can be connected. After the writer software has imported the program into the writer, it will burn the Calibration in the lower left corner of the software
Uncheck Frequency and Test Frequency, and you can burn through four wires.
15. The writer succeeded in programming the chip the first time, but what was the reason for the failure in the second time?
1. Check the programming voltage selection jump on the left side of the burner display. If the program LVR voltage selection exceeds 3V and the programming
When the programming voltage of the recorder is 3V, the first programming succeeds and the second programming fails. will
The voltage can be solved by choosing 5V. Because the 3V LVR that was burned for the first time was already created during the second burn process
If the programming voltage is still 3V, the chip will be reset directly at this time and cannot enter the programming mode. therefore
Need to jump the programming voltage setting to 5V programming.
2. Check whether the watchdog of the program programmed for the first time is turned on. If it is turned on, check the WDTCON register
Whether the frequency division ratio configured in WDTPS[3:0] is too low, causing the watchdog to overshoot before the chip is successfully programmed during programming
Time reset. If this is the case, you need to erase the chip separately and then burn.
www.origin-gd.com Page:5
Page 10
16. How to use the writer to burn the chip on the board?
Connect the jumper of the writer P1 to the corresponding pin of the MCU as shown in the figure below. Online programming circuit specification: CLK
And whether there are capacitive devices or other components on the DAT pin that affect the download communication level; there should be no between VCC and GND
Large capacitance, so as not to affect the power-on again.
Origin-gd Tech
17. Support jumper cap jumper, how to use the model of programming holder?
MS80F0801 3 3 2 2 4
MS81F0802 3 2 1 2 4
MS81F1402 3 6 3 2 1
MS81F1602 2 7 4 3 2
MS81F1802 4 4 2 1 3
www.origin-gd.com Page:6
Page 11
MS82F0802A 1 5 3 4 2
MS82F0802B 1 5 3 4 2
MS82F1402A 1 5 3 4 2
MS83F0802A 1 5 3 4 2
MS83F0802B 1 5 3 4 2
MS83F1402A 1 5 3 4 2
MS83F1602 1 5 3 4 2
2 , MS81F1402 :
Origin-gd Tech
www.origin-gd.com Page:7
Page 12
4 , MS81F1802 :
Origin-gd Tech
www.origin-gd.com Page:8
Page 13
Origin-gd Tech
Please note: to burn these 4 types of chips, only 4 wires can be used . That is, jump the jumper cap and import the program to the burning
After installing, uncheck the Calibration Frequency and Test Frequency options in the lower left corner of the burning software .
www.origin-gd.com Page:9
Page 14
Please note: To burn these 2 types of chips, only 4- wire programming can be used . That is, jump the jumper cap and import the program to the burning
After installing, uncheck the Calibration Frequency and Test Frequency options in the lower left corner of the burning software .
Origin-gd Tech
www.origin-gd.com Page:10
Page 15
After importing the program, click the "Rolling Code" of the burning software, and the burning rolling code configuration information table will pop up. caution:
The rolling code value can only be rolled in the EEPROM area. It can't be in FLASH area or EEPROM like PIC
Rolling code. Therefore, to use the rolling code of the MS single-chip microcomputer, the EEPROM read command must be used in the program to read the stored
Rolling code value in EEPROM area. In addition, the rolling code only has an auto-increment mode and no pseudo-random mode.
Origin-gd Tech
www.origin-gd.com Page:11
Page 16
Machine?
No, you can only use the ORIGINIDE platform to develop. Because MPLAB IDE and MPLAB X IDE do not
There are corresponding models for MS.
2. If you are not used to editing code on ORIGINIDE platform, you can use other code editing software to edit
Edit?
Yes, for example, use source insight. But it should be noted that the project must be built before editing the c code of the project. because
Use ORIGINIDE to build a project, it will automatically generate ac file with the same name as the project, and this c file is invalid
Code. If there is already ac file with the same name as the project and the code has been edited before building the project,
Such a project will replace the already written file.
Exists"?
Generally, it is caused by the C compiler not installed or the path of calling the C compiler execution program (pic.exe) is wrong. in
After opening a project in the ORIGINIDE directory, "Menu bar->Project->Select Language Toolsuite..."
In the pop-up box, click Browse... to select the compiler executable (pic.exe) in the installation directory of the C compiler.
can.
Origin-gd Tech
Note: If you use this C compiler to develop PIC devices, please copy the files after the C compiler is successfully installed
The copy is on another drive letter. For example, when the C compiler is installed on the C drive at the beginning, copy the C compiler file
One is in another drive letter other than the C drive. Then the device development using PIC is to use the C compiler of the C disk, and the device of MS
For software development, use another C compiler with a drive letter.
4. It will prompt "File not exist" or "No such fileor diretory" when compiling, including the header
a. When using assembly programming, the header file needs to include the header file at the very beginning: #include <header file.inc> or #include
"Header file.inc". Their differences are:
• #include <header file.inc> means to directly search for this file in the IDE software path when compiling. Such as
If yes, load directly; if not, report an error (File not exist);
• #include "Header file.inc" means first search for this file in your current project folder when compiling. in case
Yes, load this file first. If not, it will look for this file in the IDE software path.
If there is, load directly; if not, report an error (File not exist);
www.origin-gd.com Page:12
Page 17
At present, you can only add a custom header file by including.inc or .h in the file. After the compilation is passed, you can
It is displayed in the Include File directory of File View. It is not currently supported to manually add directly in the Include File.
6. When using the new ORIGINIDE to compile the old project, the pop-up compilation options are grayed out, why?
deal with?
This situation is usually caused by changes in the chip model of the project. Now ORIGINIDE is in accordance with the specifications
The device name is used for processing, so the device name is not the same, causing the compilation options to be blank.
Solution: Right-click on Device:xx in the File View display area, and select in the pop-up menu bar
"Project Options..." select the correct device name Device:xxxx in the pop-up option box, and click OK to correct
Often compiled.
7. When the emulator is emulating, can the PA0 and PA1 of the chip continue to be used as ordinary IO ports?
Not possible. During simulation, LINK will occupy PA0 and PA1 to communicate with the chip internally, so it can't be used as normal during simulation.
IO port use. After the download is complete, disconnect from LINK, and re-power on, PA0 and PA1 can achieve normal
IO port function.
8. Does the watchdog have any effect when using ORIGINIDE emulation?
Origin-gd Tech
During simulation, if the watchdog is enabled, pay attention to the watchdog, otherwise it will generate a reset when the watchdog overflows, so that the IDE cannot
Method to obtain the correct PC value, which results in a simulation error. It is recommended to close the watchdog during simulation and open it during normal testing
Watchdog.
9. The same project can be compiled and passed on other computers, but not on some computers.
Ever?
1. The problem of header files. In the new version of the IDE, use the C language to include syscfg.h, and the assembly language includes the chip system
Just list the header file, such as MS80Fxx01.inc.
2. The installation directory of the C compiler is wrong. Because of user authority management, some operating systems will prohibit IDE from repairing
Change the file in the C compiler under the system disk. Install the C compiler on a non-system disk, or run it with administrator privileges
ORIGINIDE can solve this problem.
www.origin-gd.com Page:13
Page 18
1. Open a project, IDE menu bar Project->Export EEPROM Data will generate a .bin type
File, save this file.
2. Since the IDE does not support online editing of EEPROM files, it is recommended to use third-party text editing software to
EEPROM file to edit, take UltraEdit as an example, use UltraEdit to open the file, click Edit->Hexadecimal
Function->Hexadecimal Edit, you can edit 256 bytes of EEPROM data.
At present, only ORIGINIDE's Build All can be used to compile and download the project. A single HEX file can only
Burn the chip through the burner.
Origin-gd Tech
www.origin-gd.com Page:14
Page 19
The interrupt vector address of the chip is 04H. When an interrupt event occurs while the program is running, the current PC value of the program will be pushed into the heap
Stack, and then execute from 04H address until RETI is encountered and the stack PC is returned. Interruption protection site and recovery
The field program needs to ensure that the W value and STATUS value remain unchanged before and after the interrupt event occurs. If rewritten in interrupt
If PCLATH is added, then a variable needs to be added to protect PCLATH. If it is not rewritten in the interrupt
PCLATH value can not be protected. The recommended procedures for on-site protection and restoration are as follows:
W_TMP EQU 0x70
S_TMP EQU 0x71
ORG 0004H
STR W_TMP
SWAPR STATUS,W
STR S_TMP
;BANKSEL PORTA
; Interrupt handler
; Interrupt handler
INT_RET:
SWAPR S_TMP,W
Origin-gd Tech
STR STATUS
SWAPR W_TMP,F
SWAPR W_TMP,W
RETI
W_TMP and S_TMP need to be defined in the address range 0x70-0x7F, which is shared by all BANKs, to prevent other
When entering the interrupt in the BANK, the interrupt information will be lost.
After interrupting to protect the scene, you need to set the BANK in the interrupt.
If the register in BANK0 is to be processed in the interrupt handler, then BANK needs to be set in BANK0.
If the register in BANK1 is to be processed in the interrupt handler, then BANK needs to be set in BANK1.
If it is not set, when the program enters the interrupt during BANK1, an error will occur when the register in BANK0 is operated.
Similarly, when entering an interrupt at BANK0, operations to the register in BANK1 will also cause an error.
Programming in C language does not need to pay attention to these matters, the compiler will automatically set it.
www.origin-gd.com Page:15
Page 20
4. Why is the IO pin not high when the chip IO is pulled up internally ?
To set IO as a normal IO port, you also need to set WPUAX/WPUCX, and set OPTION. 7 to 0 to enable the internal upload
Pull the main switch.
5. How can the lowest standby current be achieved when the chip is sleeping?
1. Check the status of the IO, and don't let the IO be in a floating state;
2. Check whether the ANSEL function and the comparator function are turned on;
3. Check whether the LVR function is turned on during sleep, if so, please turn it off;
4. Check whether Fosc is set to INTOSC in the compilation options, if so, please select INTOSCIO;
5. Check the reset pin setting. If the reset pin is not used or there is no reset pin, set the code option MCLRE to MCLR;
6. Check whether the watchdog is open, open or close as needed;
The pseudo-instruction BANKSEL is a command used to set the register BANK, switch to the register behind BANKSEL
In the BANK.
Such as MS80Fxx01 and MS81Fxx02:
BANKSEL PORTA, because PORTA is in BANK0, this instruction is equivalent to BCR STATUS,5
Origin-gd Tech
BANKSEL TRISA, because TRISA is in BANK1, this instruction is equivalent to BSR STATUS,5
In MS83Fxx02, because the register page is divided into BANK0, BANK1, and BANK2. By STATUS
BIT5 and BIT6 are set, so BANKSEL PORTA is equivalent to two commands
BCR STATUS,5
BCR STATUS,6
The same BANKSEL TRISA is also equivalent to two instructions
BSR STATUS,5
BCR STATUS,6
This requires special attention when accurately calculating the number of instructions.
LJUMP, LCALL, RET, RETI, RETW instructions that need to jump are double instruction cycles, and other instructions are
Single instruction cycle.
BTSS, BTSC, INCRSZ, DECRSZ these instructions are double instruction cycles when the jump conditions are met, and they are not satisfied
The sufficient jump condition is a single instruction cycle.
www.origin-gd.com Page:16
Page 21
Use #include at the top of the program to reference the include header file, which must include the "syscfg.h" file provided by the compiler,
Realize the declaration of special registers and other special symbols in the microcontroller. All series of MS microcontrollers rely on this header file.
There is no need to separately include the header file of the chip model, ORIGINIDE will automatically call it.
Please note: the old version calls pic.h , pic16f684.h and pic16f685.h , now you don't need to call these 3 header files.
Call syscfg.h uniformly
PIC microcontroller uses __EEPROM() instruction to initialize EEPROM, while MS microcontroller needs to call initialization
EEPROM binary file (bin) to initialize EEPROM. When using MS single chip microcomputer, there must be no
__EEPROM() This instruction prevents programming failures and program running errors. About MS single chip EEPROM
For details of initialization, please refer to the EEPROM description of the routine library.
The PIC microcontroller uses the __CONFIG() instruction to configure the configuration bits, while the MS microcontroller is clicking the build button
After that, the configuration bit information table pops up, select each item in turn, and finally click OK. The configuration bit information is set in HEX
bingo. When using MS single chip microcomputer, the __CONFIG() instruction cannot be in the program to prevent programming failure and program
Operation error.
Origin-gd Tech
The MS MCU interrupt vector entry is at 0x0004, and there is only one entry. Therefore, the C compiler specifies the interrupt function
The name is: void interrupt ISR(void).
The C compiler will automatically generate codes for interrupting the scene protection and restoring scenes, without the need for users to write the scene protection codes themselves. Yes
It is necessary to write the site protection and recovery site code by yourself when using assembly.
Because there is only one interrupt vector entry, the priority of all interrupts is defined by the user. In the interrupt service letter
In the numbers, which interrupt is judged first, the priority of that interrupt is higher.
The corresponding interrupt source is not enabled. Once the interrupt condition is reached, the flag bit will also be set to 1, but it will not trigger the interrupt function entry
www.origin-gd.com Page:17
Page 22
The C compiler will automatically switch the BANK according to the address allocated by the operating register, and the user does not need to switch by themselves.
_XTAL_FREQ is defined to tell the C compiler to run the oscillator frequency of the current code. So you can call the delayed macro.
For example: #define _XTAL_FREQ 4000000. This tells the C compiler that the current code is running on the oscillator as
In a 4MHz environment. If you need to delay one millisecond, you can write: __delay_ms(1); if you want to delay ten
In microseconds, you can write: __delay_us(10);.
At the same time, it should be noted that the C compiler runs at 4T instruction cycle by default, so when we configure the bit configuration
When the instruction cycle is 2T, the defined frequency must be multiplied by two. For example, if the oscillator is 4HMz, it must
Must be defined as 8MHz. In this way, the delay time with the delay macro is accurate.
The C compiler supports integer data types of 1, 2, 3, and 4 bytes, as well as single-bit types. bit and short long
Types are non-standard types provided in this implementation. The long long type is the C99 standard type. All integer values use
It is expressed in little-endian format with the least significant bit (LSb) at the lower address. If no symbol is specified in the type, divide char
Types other than type (always unsigned) are all signed. bit type is always unsigned, the concept of sign bit
Meaningless. The signed value is stored as a twos complement integer value. The following table lists the data types and their corresponding
Length and arithmetic type:
Types of Length (bit) Arithmetic type
bit 1 Unsigned integer
Origin-gd Tech
signed char 8 Signed integer
unsigned char 8 Unsigned integer
signed short 16 Signed integer
unsigned short 16 Unsigned integer
signed int 16 Signed integer
unsigned int 16 Unsigned integer
signed short long twenty four Signed integer
unsigned short long twenty four Unsigned integer
signed long 32 Signed integer
unsigned long 32 Unsigned integer
signed long long 32 Signed integer
unsigned long long 32 Unsigned integer
www.origin-gd.com Page:18
Page 23
Constants are used to represent immediate data in source code, in contrast to variables that can store the same value. For example, 123 is a
Constants. Like all values, constants must have C type. In addition to the types of constants, there are several
One of the formats to specify the actual value.
1. Integer constant
The format of an integer constant specifies its base. The C compiler supports ANSI standard radix specifiers and is used in the C generation
Specifier that specifies a binary constant in the code.
The following table lists the format used to specify the base. Same as the letters used to specify hexadecimal numbers, used to specify binary
The letters in the system or hexadecimal base are also case-sensitive.
Base format Example
Binary 0b number or 0B number 0b10101010
Octal 0 number 0257
Decimal digital 129
Hexadecimal 0x number or 0X number 0xF7
The integer constant will have type int, long int or long long int so that the type can overflow without
Store its value under. For constants specified in octal or hexadecimal, if their corresponding signed constants are too small and
Unable to store its value, you can also allocate unsigned int, unsigned long int, or unsigned long long int
Types of.
You can change the default type of a constant by adding a suffix after the number; for example, 23U, where U is the suffix.
The following table lists the possible combinations of suffixes and types that are considered when assigning types. For example, if the suffix l is specified, and
And the value is a decimal constant, and if the long int type can store the constant, the compiler will assign the class
Type; otherwise, it will allocate a long long int type. If the constant is specified as an octal or hexadecimal constant
Quantity, unsigned types will also be considered.
suffix Decimal Octal or hexadecimal
u or U unsigned int unsigned int
unsigned long int unsigned long int
unsigned long long int unsigned long long int
Origin-gd Tech
l or L long int long int
long long int unsigned long int
long long int
unsigned long long int
u or U, and l or L unsigned long int unsigned long int
unsigned long long int unsigned long long int
ll or LL long long int long long int
unsigned long long int
u or U, and ll or LL unsigned long long int unsigned long long int
The following is an example of code that may fail because the default type assigned to the constant is inappropriate:
unsigned long int result;
unsigned char shifter;
void main(void)
{
shifter = 20;
result = 1 << shifter;
www.origin-gd.com Page:19
Page 24
Origin-gd Tech
const char * cp = "hello world\n";
Defining and initializing arrays with strings (that is, not pointers) is an exception. Eg:
char ca[]= "hello world\n";
Actually copy the string characters to the RAM array instead of assigning the address of the character as in the previous example
Give pointers. The string literal value remains read-only, but the array is readable and writable.
For strings with the same character sequence, the C compiler will use the same storage unit and label (used to initialize
Except for strings that reside in arrays in data space). For example, in the following code snippet
if(strncmp(scp, "hello", 6) == 0)
fred = 0;
if(strcmp(scp, "world") == 0)
fred--;
if(strcmp(scp, "hello world") == 0)
fred++;
The last 6 characters in the string "world" and the string "hello world" (the last character is the nul terminator)
Will be represented by the same character in the memory. The string "hello" will not be the same character in the string "hello world"
Overlap, because the position of the nul character in the two is different.
www.origin-gd.com Page:20
Page 25
The C compiler supports the bit integer type, which can store the value 0 or 1. A single bit variable can be declared with the keyword bit, for example:
bit init_flag;
These variables cannot be automatic variables or function parameters, but they can be defined by static so that they can be localized in the function
Define them. Eg:
int func(void)
{
static bit flame_on;
// ...
}
By using the bit keyword in the function prototype in the usual way, the function can return a bit object. Value 1 or 0 will return
To the carry flag in the STATUS register.
The behavior of bit variables is similar to regular unsigned char variables in most respects, but they can only contain the values 0 and 1.
Therefore, a convenient and efficient way to store the logo is provided. 8 bit objects are packed into each byte of memory,
So they will not consume a lot of internal RAM.
Whenever possible, operations on bit objects are performed using single bit instructions (bsf and bcf), thus generating code access
Bit objects are extremely efficient.
It is not possible to declare a pointer to a bit type or assign the address of a bit object to any pointer. Statically
Initialize bit variables, so they must be given any non-zero starting value (ie 1) in the code itself. Unless used
Persistent is limited, otherwise the bit object will be cleared at startup.
When a longer integer type is assigned to a bit variable, only the LSb will be used. For example, if the bit variable bitvar is assigned as follows:
int data = 0x54;
bit bitvar;
Origin-gd Tech
bitvar = data;
Assignment will clear it, because the LSb of data is zero.
Type qualifiers can provide additional information on how to use the object. The C compiler supports ANSI C qualifiers and a
Some additional special qualifiers, these special qualifiers are very useful for embedded applications, and make full use of the 8-bit
MS MCU architecture.
1 , CONST type qualifier
The const type qualifier is used to instruct the compiler that an object is read-only and will not be modified. If you try to modify the sound
If it is an object of type const, the compiler will issue a warning or error.
If user-defined objects are declared as const type, they will be put into a special link to the program space
psect. Objects restricted to const type can be absolute objects. @address constructs used to place objects
At the specified address in the program memory, as shown in the following example, the object tableDef is placed at address 0x100.
const int tableDef[] @ 0x100 = {0, 1, 2, 3, 4};
Normally, a const object must be initialized at the time of declaration, because it cannot be assigned at any point in runtime.
www.origin-gd.com Page:21
Page 26
The volatile type qualifier is used to instruct the compiler that there is no guarantee that an object will retain its value between two consecutive accesses.
value. This prevents the optimizer from deleting seemingly redundant references to volatile objects, as this may change the execution of the program.
Perform this quoting behavior.
All SFRs that can be modified by hardware or drive hardware are limited to volatile types, and all SFRs that may be modified by interrupt programs
This qualifier should also be used for variables. Eg:
volatile static unsigned int TACTL @ 0x160;
The volatile qualifier does not guarantee that all accesses are atomic, which is usually not the case for 8-bit PIC MCU architectures.
For all these devices, each instruction can only access 1 byte of data at most.
The code generated by the compiler for accessing volatile objects may be different from the code for accessing ordinary variables, and is used
The code for volatile objects is usually longer and slower, so use this qualifier only when necessary. However, in need
Failure to use this qualifier when necessary may cause the code to fail.
Another use of the volatile keyword is to prevent variables that are not used in the C source code from being deleted. If a non
Volatile variable is never used, or its use has no effect on the function of the program, then it may be edited
The translator was deleted before generating the code.
If a C statement contains only the name of a volatile variable, a storage unit for reading the variable will be generated and the result will be discarded.
The code of the fruit. For example, the following entire statement:
PORTB;
Will generate assembly code that reads PORTB but does not perform any operations on the value. For some need to be replied by reading
Origin-gd Tech
This is very useful for bit interrupt flag status peripheral registers. Normally, this kind of sentence will not be encoded because
It has no effect.
The optimization in the C compiler can be roughly divided into C code-level optimization (the source code is converted to assembly code before
Execution) and assembly-level optimization (execute the assembly code generated by the compiler).
C code-level optimization is performed early in the code generation phase, so it has a process advantage: it is possible to perform an optimization
Means that another item can be applied later.
Since these optimizations are applied before the debugging information is generated, there is usually almost no source-level debugging of the program
influences.
Some of these optimizations are an integral part of the code generation process, so they cannot be disabled through options. The following sections
Suggestions on how to abolish some specific optimizations are given.
In the standard mode, especially in the free mode, some of these optimizations will be prohibited. Even if they are enabled, only
They are only applied when very specific conditions are met. Therefore, you may find that some lines of code are optimized,
www.origin-gd.com Page:22
Page 27
Origin-gd Tech
www.origin-gd.com Page:23
Page 28
1. Is the internal circuit of the chip the same for models of the same series?
it's the same. For example, the internal circuits of MS80F0601 and MS80F0801 are the same.
MS80F0601 just doesn't package PA3/MCLRB and PA5. Other series (MS81F, MS82F,
MS83F and MS84F) are also the same.
For IO ports that are not encapsulated, if they have MCLR (reset) function, set it to MCLR in the configuration bit table,
Not as an IO port. For other IOs that are not encapsulated, if the IO port has an internal pull-up, then set it to
Digital input and enable internal pull-up. If the IO port has no internal pull-up, then set it as a digital output (digital
Both word output high and digital output low are possible).
The reason for this setting is that in low-power applications, if there are floating input pins (not packaged
The pin is considered as a floating pin), the level of the floating input pin is not fixed, and it will consume a certain amount of power in a floating state.
For example: the PA3/MCLRB and PA5 pins of MS80F0601 are not encapsulated, so PA3/MCLRB should be
The configuration bit table is set to MCLR, PA5 is set as an input pin and the internal pull-up is enabled.
1. When normal IO is in sleep, it should be set according to application requirements. If it is a normal output port, it should be set to save power
Output. If it is a normal input port, the input port should be kept at a fixed level and cannot be in a floating state
(Please pay attention to the previous point 2-" How to initialize the unpackaged IO port?") .;
2. Turn off peripherals that are not used by the chip as much as possible. Special attention: use MS83F and MS84F with ADC modules
The model of the block, if the ADON bit of the ADCON0 register is set to 1, it must be set to 0 before sleep;
Origin-gd Tech
3. After the LVR module is started, there will be a current of about 15uA, so you can choose whether to
To turn on LVR. Note: LVR can be turned on and off by software, so some application environments can do this
The same setting-when waking up, start LVR; when sleeping, turn off LVR.
4. After the IO of MS81F is set with TRIS (such as TRISA ) register, it still cannot input normally
Or output?
This situation mostly occurs in the MS81Fxx02 series. The CMCON0 register should be set to
0x07. Because this series has a comparator, and when the MCU is power-on reset, CMCOM0 is equal to 0 (compare
The comparator is turned off, and the corresponding input pin of the comparator is analog input pin). So the CMCON0 register must be set to 0x07,
Then the comparator is closed, and the corresponding analog input pin is set as a normal digital input pin.
www.origin-gd.com Page:24
Page 29
Output?
Because some IOs multiplex the comparator function and ADC function, and when power-on reset, the corresponding pins are all analog
To be input pin. Must be set to: CMCON0=0x07 and ANSELx=0.
6. After setting the TRIS , CMCON0 and ANSEL registers , the IO of MS84F still cannot
Check whether the USFRSEL option in the compilation options is DisUSFR, modify it to ENUSFR and change CMCON4
The CMPON[3-0] is set to 0000.
1. Clock cycle:
The clock period is the oscillation period, which is the reciprocal of the clock pulse, that is, the reciprocal of the system oscillator frequency. Eg system clock
Set the internal RC oscillator to 4MHz, then the clock cycle=(1/4MHz)=0.25us.
2. Instruction cycle:
The instruction cycle refers to the time required to execute a single-cycle instruction, which consists of 4 or 2 clock cycles. Eg:
The MS80F0801 instruction cycle consists of 4 machine cycles. If the system clock is set to the internal RC oscillator
4MHz, then the instruction cycle=(1/4MHz)*4T=1us. And MS81F, MS82F, MS83F and MS84F can
To select 2T instruction cycle.
The overflow time of Timer can be calculated according to the instruction cycle. For example, the prescaler ratio of Timer0 is 1:4, and the initial value is 6, which means
Let the period be 1us. Then overflow time=(256-6)*1us*4=1000us.
Origin-gd Tech
8. With IO level change interrupt (IOCA) , how to clear the interrupt?
Each PORTA pin can be individually configured as an interrupt-on-change pin. The control bit IOCx enables or disables each
Interrupt function of each pin. PAIE enables or disables interrupt-on-change, PAIF is the interrupt-on-change flag.
For pins that have enabled interrupt-on-change, the value on the changed pin is the same as the value latched when PORTA was read last time.
Line comparison. The output of the last “mismatch” is combined with a logical OR operation, so that the value in the INTCON register
The PAIF interrupt-on-change flag bit is 1.
After the interruption occurs, the user clears the interruption in the interrupt service routine in the following ways:
1. Perform a read operation on PORTA. This will end the pin level mismatch condition;
2. Clear the flag bit PAIF.
If the ADC uses the internal reference voltage of 2V, the VCC supply voltage must be higher than 2.5V
If the ADC uses an internal reference voltage of 3V, the VCC supply voltage must be higher than 3.5V
www.origin-gd.com Page:25
Page 30
1. Check whether the voltage of the reference source is stable. If it is an internal fixed reference, check whether it meets the requirements of point 9;
2. Check the setting of the ADCON1 register conversion clock, which must conform to the dark part of the ADC clock cycle (Tad) table;
3. Check the ADC program, after setting ADON to 1, is there a delay of about 20us, then set GO/DONE to 1;
ADC clock period (Tad) System clock frequency (Fsys)
11. assembler in more than 2K space LCALL and LJUMP Why wrong?
The program counter (PC) is 12 bits wide. The lower 8 bits come from the PCL register that can be read and written, and the upper 4 bits (PC[11:8]) come from
Since PCLATH, it cannot be read or written directly. Whenever a reset occurs, the PC will be cleared. The figure below shows the value installed on the PC
Two situations. Note that the LCALL and LJUMP instructions on the right of the figure, because the opcode in the instruction is 11 bits, and the core
The PC of the chip is 12 bits, so only the third bit of PCLATH is used at this time, and the 11 bits of the opcode form a 12-bit ground.
site.
Origin-gd Tech
So when using assembly programming, you must set PCLATH[3:0] to directly manipulate PCL
For LCALL and LJUMP within 2K, BCR PCLATH should be set. 3
For LCALL and LJUMP other than 2K, BSR PCLATH should be set. 3
When programming in C language, there is no need to consider this problem, the compiler will handle it automatically.
www.origin-gd.com Page:26
Page 31
WEB: www.origin-gd.com
TEL: 0755-83666320
FAX: 0755-83666329
ADDRESS: Room 605 , Building E , Bantian International Center, No. 5 , Huancheng South Road , Bantian Street, Longgang District, Shenzhen, Guangdong Province
Origin-gd Tech
www.origin-gd.com Page:27