Recently, I have a project that requires me to use a PIC microcontroller for development (I have never used it before). I encountered many problems that I don't understand. Here I summarize the problems I encountered and the corresponding solutions. I hope there will be guidance from experts, and I also hope to help friends like me.
1. Introduction to PIC microcontrollers
I have played with 51 and STM32 microcontrollers before. I was confused when I first started. I didn’t know where to start when I got the data sheet. I searched for information online and saw “Guo Tianxiang teaches you to play with PIC microcontrollers in ten days”. Of course, the microcontroller used in the video is not the model of the microcontroller I use, but watching the video can provide a direction. It is not necessary to watch the entire video. You can read the data sheet and write the code if you have an idea. The following is a link to the relevant video (including relevant code, thanks to the enthusiastic netizens for sharing!). (PS: Thank you again, Mr. Guo Tianxiang, from 51, DXP, etc., I learned from watching your videos!)
(Video with code)
Link: https://pan.baidu.com/s/1tJRE3OJ8s9DC-90nlxmfLQ
Extraction code: a0ge
Link: https://pan.baidu.com/s/18SGLYs5Dcv5YSyY_MGjJuA
Extraction code: g0f0
2. The first configuration problem encountered
Since I am using MPLAB X V5.0 IDE and XC8 (V2.0) compiler, I encountered a problem during configuration. The video uses __CONFIG(X);--[pic16F series] to configure (PIC16F&PIC18F use different methods), and an error message appears during compilation: Unexpected tag
I can't find the reason at the moment (I hope someone who knows can give me some guidance), so I searched online for information and found that the software can be configured by itself. The operation is as follows:
If you have multiple projects open, be sure to set the project you want to operate as the main project, as follows:
Open the configuration interface as follows
The configuration interface is as follows:
After configuring according to the data sheet and actual conditions, the motor "outputs and generates source code" will generate the corresponding source code based on your configuration:
Just copy the code into your source file.
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
The above configuration can be realized. If I want to configure other projects, I must set this project as the main project, because the MCU model of each project may be different, and the configuration may also be different
This is the configuration of another test project of mine.
------------------------------------------------------------------------------------------------------------------------------------------------------
3. Regarding the writing of interrupt functions.
It is also different from the video. The video uses the form of void interrupt tim0(), but when I use the compiler XC8 (V2.0), it cannot be compiled.
hint:
main.c:81:6: error: variable has incomplete type 'void'
void interrupt isr_deal(void)
main.c:81:15: error: expected ';' after top level declarator
I don't know the reason, but it can be compiled when using XC8 (V1.45). (Please give me some advice!)
Refer to the XC8 (V2.0) compilation manual, and write it in other forms to compile. The manual is opened as follows:
1. Click "Compiler Help" as shown in the picture.
2. Go to the corresponding local help website
Click to open the corresponding document to view the relevant instructions.
If you cannot open the website, you can find it in the compiler installation directory, such as mine:
Find the corresponding document in.
---------The above, there will be updates later.
Previous article:PIC microcontroller serial port transmission and key press
Next article:PIC Microcontroller Getting Started Tutorial (IV) - The First Project
Recommended ReadingLatest update time:2024-11-16 14:59
- Popular Resources
- Popular amplifiers
- Siemens S7-1200-PLC Programming and Application Tutorial (3rd Edition) (Edited by Shi Shouyong)
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Learning PLC is easy - PLC ladder diagram and statement table with pictures (Li Changjun, Zhou Hua)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- TE's latest trend report | "How does temperature monitoring affect the generator market"
- 【NXP Rapid IoT Review】+7. Understand what each icon means
- EEWORLD University Hall ---- Deep Learning Theory (National Taiwan University Li Hongyi, Chinese)
- MicroPython makes some objects const
- Monthly fixed dry goods, ADI March Chinese information
- GPIO Operation of TMS320C6748
- [nRF52840 DK Review] Playing with micropython
- Support the e-sports competition and get gifts for grabbing the building~~
- 【MicroPython】ESP32 starts to support hardware I2C method
- How to choose the power chip for DSP?