Types and definitions of PICC variables
PICC variables and definitions
1. When the variable is multi-byte data, PICC stores the variable according to the principle of storing the low byte at the low address and the high byte at the high address, and uses the address of the lowest byte as the address of the variable. For example, the value of int variable i is 0X1234, the low byte 0x34 is stored at 0X30, the high byte 0x12 is stored at 0X31, and 0x30 is used as the address of variable i.
2. The signed integers of the microcontroller are stored in the complement format. For binary numbers, the result of subtracting one and then negating it is the same as the result of negating it and then adding 1.
3. There is no bit variable in standard C. Bit variables are unique to PICC C language. With bit variables, you can easily perform bit operations and set whether a pin is high or low.
4. The general expression for forced type conversion is (type specifier) (expression) Function: Force the result of the expression to be converted into the type expressed by the type specifier
For example: (float) x; // Force X to be converted to a real type, regardless of the type of variable X
PICC variable modification keywords
1. extern variable declaration
If a C program file is to use some variables defined in other files or reference variables defined by the embedded assembler, then these variables must be declared as "extern" in this program file.
2. Volatile variable declaration
The volatile keyword is not in standard C. It tells PICC that these variables are random and do not perform random processing on the variables.
In the relevant header files, the relevant registers are defined as volatile type.
3. const (constant) variable declaration
If you put the keyword "const" before a variable definition, the variable will become a constant and cannot be modified while the program is running.
The constants of the microcontroller actually exist in the program memory and return values in the form of a lookup table. Usually the program memory of the microcontroller is relatively large and can store more constants.
A program memory unit (word) can only store an 8-bit byte constant, although the program memory is 14 bits.
4. Persistent (uninitialized) constant declaration
Declare that such variables do not need to be automatically cleared to zero on reset, and these variables are still retained when exiting certain functions.
5. static constant declaration
The default variables are all automatic variables. Automatic variables refer to local variables that are no longer retained after the calling function returns, that is, they do not exist. If static variable modifiers are added to the declaration, these variables will still be retained after exiting the function.
6. Bank selection statement
Since the RAM data memory of the PIC16 series microcontrollers is divided into four banks, you must specify which bank it is when defining a variable. The default is bank 0. Use bank1 to bank3 to specify that the variable is stored in the corresponding bank.
Designers should know how much data memory is occupied by the programs they write.
In the variable definition of PICC, the address can also be specified for global variables. For example: char AA @0X30
The structures and communities supported by PICC are no different from those in standard C.
PICC pointer:
1. Pointer to RAM
When PICC compiles the C source program, the pointer operation pointing to RAM is finally implemented with FSR to achieve indirect addressing. Therefore, when defining a pointer, the addressing range applicable to the pointer and the range where the pointer variable exists must be clearly specified. For example, bank3 char *bank1 zz2 defines a pointer pointing to bank2/3, and the pointer itself exists in bank1.
When using pointers to RAM, pay attention to the location matching of the body.
2. Pointer to FLASHROM constant
The constants defined by PICC are stored in the program memory, namely FALSHROM, or ROM for short.
A pointer to a constant can point to another constant without having to define it again.
Previous article:PIC16F887 SPI CAN transmission, operating MCP2515
Next article:Getting Started with MPLAB XC8 Compiler Devices Based on PIC18F45K80
Recommended ReadingLatest update time:2024-11-16 21:55
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Multimodal perception parameterized decision making for autonomous driving
- Investigation of occupancy perception in autonomous driving: An information fusion perspective
- Power Integrated Circuit Technology Theory and Design (Wen Jincai, Chen Keming, Hong Hui, Han Yan)
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
- [TI recommended course] #Optimizing system-level design through industrial Ethernet#
- C64x+ Memory Organization
- Low voltage MOS tube body diode reverse breakdown voltage
- Prize live broadcast: TI takes you to learn mobile robots. This Friday at 10 am, make an appointment to watch and there will be a surprise~
- Altium Designer AD special-shaped plate layout skills
- Download Win Gift | Artesyn PMBus Interface Non-Isolated Digital DC-DC Converter
- TO92S enclosed 3-pin direct plug-in components have a pin spacing of only 0.45mm, and occasionally a short circuit will occur between the two pins after soldering
- [Erha Image Recognition Artificial Intelligence Vision Sensor] 3: Erha Image Recognition Vision Sensor and STM32 Communication to Realize Color Recognition Experiment
- The actual circuit does not match the simulation circuit. I don't know why. Please tell me. Thank you. The actual op amp is OP297.
- ADI or TI blood glucose meter solution