Introduction: The basic framework of C language programming for PIC microcontrollers
The basic method of writing PIC microcontroller programs based on the PICC compilation environment is similar to that of standard C programs. The program generally consists of the following main parts:
1. Use the #include preprocessing directive at the beginning of the program to reference the included header file, which must include a "pic.h" file provided by the compiler to declare special registers and other special symbols in the microcontroller;
2. Use the "_CONFIG" preprocessor directive to define the chip's configuration bits;
3. Declare the types of all functions called in this module. PICC will perform strict type matching checks on the called functions.
4. Define global variables or symbol replacement;
5. Implement the function (subroutine), paying special attention that the main function must be an infinite loop with no return.
The following is an example of a C program for your reference.
#include //Includes the predefined internal resources of the MCU
#include "pc68.h" //Include custom header file
//Define the configuration bits when the chip is working
__CONFIG(HS&PROTECT&PWRTEN&BOREN&WDTDIS);
//Declare the function type called in this module
voidSetSFR(void);
voidClock(void);
voidKeyScan(void);
voidMeasure(void);
voidLCD_Test(void);
voidLCD_Disp(unsignedchar);
//Define variables
unsignedcharsecond,minute,hour;
bitflag1,flag2;
// Functions and subroutines
voidmain(void)
{
SetSFR();
PORTC=0x00;
TMR1H+=TMR1H_CONST;
LED1=LED_OFF;
LCD_Test();
//Main loop of program work
while(1){
asm("clrwdt"); // clear watchdog
Clock(); //Update the clock
KeyScan(); //Scan the keyboard
Measure(); //Data measurement
SetSFR(); //Refresh special function registers
}
}
Previous article:Design of intelligent cleaning and nursing machine using PIC microcontroller
Next article:PIC C language programming_Variable definition in PICC
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Sigma-Delta ADC Digital Filter Types
- Remote upgrade of HuaDa MCU HC32L110
- Explanation of the stack pointer register SP of msp430
- Qorvo at CES 2020: Innovative Solutions for 5G, IoT, Wi-Fi 6 and V2X
- dsp28335 Ecap Summary
- AD automatically adds test points
- iTOP-3399 development board Linux system modify boot LOGO
- [GD32E231 DIY Contest] 4. Simulate IIC to operate OLED
- Pingtouge RVB2601 board-IIC bus test
- EEWORLD University ---- Deep Learning Course (NYU, Spring 2020) Yann Lecun