6. Programming in C
6.1. Data Types
Declaration of the types of memory
In the variable declaration can indicate what kind of memory is stored.
The following table shows the type of memory that can be specified.
- program code memory (64 KBytes). With access by using the MOVC @ A + DPTR.
- Address data directly to the internal data memory. For quick access to variables (128 bytes).
- idata Indirect addressing the internal data memory. With access to all internal memory (256 bytes).
- BDATA internal data memory address bit by bit. Allows access to the area bit by bit and address byte (16 bytes).
- xdata external data memory (64 KBytes). Accessed through the MOVX @ DPTR instruction.
- pdata Paging (256 bytes) external data memory. Access by instruction MOVX @ Rn.
Normally when working in C, it is not necessary to specify the type of memory in which to store the contents of variables, it is assumed that this is the work RAM. But in this type of microcontrollers by having various memory areas with different behavior, you must specify whether the variable is to give one or the other memory as needed. By default, if nothing is indicated the variable is assigned a data memory.
Examples:
data char Var1;
char code text [] = "Enter temperature:";
unsigned long xdata MyArray [100];
float idata x, y, z;
unsigned int pdata Dimension;
unsigned char xdata vector [10] [4] [4];
char BDATA Indicator;
Data Types
A data type defines the range of values that can have a variable throughout the execution of the program and the number of bytes of memory allocated to hold information.
Datatype | Bits | Bytes | Range |
bit * | 1 | | 0 to 1 |
signed char | 8 | 1 | -128 To +127 |
unsigned char | 8 | 1 | 0 to 255 |
enum | 8 / 16 | 1 or 2 | -128 To +127 or -32768 to +32767 |
signed short | 16 | 2 | -32768 To +32767 |
unsigned short | 16 | 2 | 0 to 65535 |
signed int | 16 | 2 | -32768 To +32767 |
unsigned int | 16 | 2 | 0 to 65535 |
signed long | 32 | 4 | -2147483648 To 2147483647 |
unsigned long | 32 | 4 | 0 to 4294967295 |
float | 32 | 4 | ± 1.175494E-38 to ± 3.402823E +38 |
SBIT * | 1 | | 0 to 1 |
sfr * | 8 | 1 | 0 to 255 |
sfr16 * | 16 | 2 | 0 to 65535 |