PIC Knowledge Points Summary

Publisher:HaifeengLatest update time:2020-08-27 Source: eefocusKeywords:PIC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:PIC Reference address:PIC Knowledge Points Summary

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

Proteus simulation and source program of laser communication based on PPM modulation of PIC16F877A microcontroller
Software: MPLAB X IDE v4.15 compiled proteus 8.6 simulation. 1. Simulation circuit diagram; 2. Send and receive source program with comments. Please see the comments. Principle: 1) ADC reads and displays the ADC reading with LED, and outputs it through usart. 2) Transmits to another microcontroller through the PPM pri
[Microcontroller]
Proteus simulation and source program of laser communication based on PPM modulation of PIC16F877A microcontroller
Realization of a new motor speed control system based on PIC16C63 single-chip microcomputer and fuzzy controller
  传统PID控制的电机调速系统技术成熟,结构简单,较稳定可靠,应用较为广泛,但也存在一些缺点,例如无法有效地克服传动对象和负载参数的大范围变化以及非线性因素对系统造成的影响,因而不能满足高性能和高的要求。随着模糊控制技术的成熟,应用越来越广泛,人们也开始将它应用于电机调速中。使用模糊控制技术后,能充分利用其非线性结构自寻优等各种功能,从而显著提高系统的鲁棒性(robustness)。此外,由于不需要建立被控对象的数学模型,系统的设计也变得较为简便。本文研究的这种新型电机调速系统,用模糊控制器替代传统的PID调节器,能明显改善系统的稳态和动态性能,有较好的控制效果。   System hardware structure   
[Microcontroller]
Realization of a new motor speed control system based on PIC16C63 single-chip microcomputer and fuzzy controller
Interfacing the MAX1169 ADC to a PIC Microcontroller
This application note describes how to interface the MAX1169 analog-to-digital converter (ADC) to a PIC microcontroller. Example circuits and software for the PIC18F442 are provided. The software contains function calls to interface the ADC to the PIC microcontroller at 400kHz using the internal MSSP I2C* port.
[Industrial Control]
Interfacing the MAX1169 ADC to a PIC Microcontroller
PIC microcontroller infrared remote control coding and recognition
    Infrared remote control is widely used, and encoding and recognition are often the most headaches for microcontroller beginners. In fact, infrared encoding and recognition are not difficult. The key is to master the methods of infrared encoding and recognition. First, let us understand infrared encoding.     1.
[Microcontroller]
Introduction to PIC microcontroller C language programming (4)
11.9 Mixed C and Assembly Programming There are two reasons why it is necessary to use assembly statements when developing microcontroller applications using C  language: Some special instructions of the microcontroller do not have a direct corresponding description in the standard C language syntax, such
[Microcontroller]
PIC microcontroller CCS C language (#USE FIXED_IO usage)
#USE FIXED_IO 语法:#use fixed_io(port_outputs=pin.pin?) port is A~G. pin is one of the pins defined in the device.h file. Purpose: Affects how the compiler generates input and output code, as described below. This instruction is valid until the next #use xxxx_io appears. Executing the method to set I/O will cause
[Microcontroller]
Wulin teaches you how to use PIC32 (I) - I/0 operation of the water lamp
First, let's introduce the registers. There are 6 registers in total: 1. TRIS register: Sets whether the digital pin is input or output; set to 1 to configure input (default); clear to 0 to configure output, which is the opposite of 51.  2. LAT register: write port value   3. PORT register: read port value 4. CLR regi
[Microcontroller]
Some experiences and skills in the development process of PIC microcontroller
The PIC series of microcontrollers produced by Microchip Corporation of the United States have been widely used in industrial control, instruments, meters, communications, home appliances, toys and other fields due to their ultra-small size, low power consumption, low cost and variety. This article summarizes some of t
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号