Two mistakes that beginners often make when using PICC

Publisher:哈哈哈33Latest update time:2019-11-28 Source: eefocusKeywords:PICC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This is my first time using a PIC microcontroller. I don't know the programming specifications for PICC, and I always have problems when compiling programs. Now I will introduce two of the most common problems to you to see if you have encountered the same problems as me.


Error 1: The order of variable definition and assignment is very important

The development environment is MPLAB IDE V7.43 + PICC. Which of the following two code writing methods will compile incorrectly after completion? (flag_sendKeyByte is a global bit variable, which has been defined)

A:

flag_sendKeyByte = 0; 
 unsigned char mbit = 0;

B: 
 unsigned char mbit = 0; 
 flag_sendKeyByte = 0;

From the perspective of normal C language habits, it seems that there is no problem, they are all assignments, just the order is different. However, in the compilation environment of PIC microcontroller, A is wrong and B is correct.


When this compilation error occurred, I searched for a long time. Since it was my first time to use PIC and I didn't know much about it, I took a lot of detours. Finally, I deleted the code line by line and modified it line by line, and finally found that the order was wrong.


The compilation environment of PIC microcontrollers requires that variable assignment must be after variable definition. It does not allow defining another variable and assigning a value after assigning a value to a variable. It seems that the compilation environment processes all variable definitions before assigning a value. If a variable assignment statement is detected, the definition of the function or subroutine will not be checked, resulting in some variables being undefined during the final compilation.


(Note: The above analysis is my own thinking, and may be wrong. Please correct me if I am wrong.)

The funny thing is that the compilation error message is a mess, instead of saying that there are undefined variables. The following prompts are what I prompted when compiling. For a beginner, can you find the source of the error based on these prompts?

Error[000] D:documentsPICtestkeyboardps2.c 390 : missing basic type: int assumed Error 
[000] D:documentsPICtestkeyboardps2.c 390 : type  redeclared
Error[000] D:documentsPICtestkeyboardps2.c 390 : identifier redefined: calc_parity (from line 64) Error[000] D:documentsPICtestkeyboardps2.c 390 : constant expression required 
Warning[000] D:documentsPICtestkeyboardps2.c 390 : missing basic type: int assumed 
Error[000] D:documentsPICtestkeyboardps2.c 390 : type redeclared 
Error[000] D:documentsPICtestkeyboardps2.c 390 : identifier redefined: calc_parity (from line 64) 
Error[000] D:documentsPICtestkeyboardps2.c 390 : constant expression required

....

There are many more to come, and the program will prompt an error at the end. Replace the writing in A with that in B, and the compilation will succeed.


I feel that this compilation environment is too difficult to use. I have used the development tools of the C8051F series before, which are much easier to use. I raise this question to remind beginners not to make the same mistake as me.


Error 2, could not find file 'c018i.o'

When using MPIDE +MCC18 to compile, the following prompt often appears: "could not find file 'c018i.o'"

Solution: Because the default path of the library is not specified. Click project->build option->project. In the Directories tab, click the drop-down menu on the right of show directories for:, find the library search path item, select new, and specify the path as c:mcc18lib in the newly created project. Click OK. Compile again and it will be successful.

 

————————————————————————————————

In C language, variable declarations must be at the beginning of a block. 
A block refers to the part enclosed by a pair of {} braces. 
The variable declaration must follow "{" immediately, and no other code can be included in between.

For example, for(char i=0; i< 20 ; i++){ do something...}, which works in some compilers but not in others. 
This way of writing is also incorrect and will report a syntax error, an error of undeclared variable. 
If you want to use it but don’t want to declare the temporary variable i at the beginning of the block, you can do it like this: 
{ //Note the curly braces 
    char i; 
    for(i=0; i< 20 ; i++){ /*do something...*/} 
} //Note the curly braces. 
This ensures that the declaration is at the beginning of the block and that the local variable can be used without declaring it at the beginning

Keywords:PICC Reference address:Two mistakes that beginners often make when using PICC

Previous article:MOS tube makes PIC microcontroller unable to operate normally
Next article:PIC16F877A Watchdog Timer (WDT)

Recommended ReadingLatest update time:2024-11-23 08:18

PIC16F + PICC9.50 Study Notes (Part 2)
The difference between LP/XT/HS in the configuration word: 1. The excitation power provided to the crystal in these three modes is different. Generally, LP can be selected for crystals 200KHZ, XT can be selected for crystals 100KHZ~4MHZ, and HS can be selected for crystals over 2M. 2. Please note that there is some
[Microcontroller]
Write PIC microcontroller programs based on PICC compilation environment
At present, the PIC series of microcontrollers produced by Microchip have rapidly occupied the domestic market with its advantages of low cost, low power consumption, high performance, fast development speed and one-time user programmability, becoming the best-selling microcontroller in China. However, there are rel
[Microcontroller]
Write PIC microcontroller programs based on PICC compilation environment
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号