100% found this document useful (2 votes)
3K views3 pages

8051 Data Types: Data Types Size in Bits Data Range/Usage

There are several data types in C for the 8051 microcontroller including unsigned char, signed char, unsigned int, signed int, sbit, bit, and sfr. Unsigned char and signed char are 8-bit data types that can hold values from 0-255 and -128 to 127 respectively. Unsigned int and signed int are 16-bit data types that can hold values from 0-65535 and -32768 to 32767 respectively. Sbit is used for single bit addresses and sfr accesses 8-bit special function registers.

Uploaded by

Girish Chaple
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
3K views3 pages

8051 Data Types: Data Types Size in Bits Data Range/Usage

There are several data types in C for the 8051 microcontroller including unsigned char, signed char, unsigned int, signed int, sbit, bit, and sfr. Unsigned char and signed char are 8-bit data types that can hold values from 0-255 and -128 to 127 respectively. Unsigned int and signed int are 16-bit data types that can hold values from 0-65535 and -32768 to 32767 respectively. Sbit is used for single bit addresses and sfr accesses 8-bit special function registers.

Uploaded by

Girish Chaple
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

8051 DATA TYPES

There are various type of data types in C :

• unsigned char
• signed char
• unsigned int
• signed int
• sbit (single bit)
• bit and sfr

Data Types Size in bits Data Range/Usage


unsigned char 8 bit 0 to 225
signed char 8 bit -128 to +127
unsigned int 16 bit 0 to 65535
signed int 16 bit -32768 to +32767
sbit 1 bit SFR bit addressable only
bit 1 bit RAM bit addressable only
sfr 8 bit RAM addresses 80 – FFH only

unsigned char:

The character data type is the most common choice. 8051 is an 8-bit microcontroller and
unsigned char is also an 8-bit data type in the range of 0 – 255 (00 – FFH). C compilers use the
signed char as the default data types if we do not put the keyword unsigned char.

Example:

#include <reg51.h> // Header file of 8051

void main(void)

unsigned char i;

for (i=0;i<=255;i++)

P1=i;

}
Signed char :

The signed char is an 8-bit data type. signed char use the MSB D7 to represent – or +. signed
char give us values from –128 to +127.

We always use unsigned char in program until and unless we don’t need to represent signed
numbers for example Temperature.

Example :

//Singed numbers

#include <reg51.h> // Header file of 8051

void main(void)

{
char anynum[ ]={+1,-1,+2,-2,+3,-3,+4,-4};

unsigned char z;

for (z=0;z<=8;z++)

P1=anynum[z];
}

Unsigned int :

• The unsigned int is a 16-bit data type.


• Takes a value in the range of 0 to 65535 (0000 – FFFFH)
• Define 16-bit variables such as memory addresses
• Set counter values of more than 256
• Since registers and memory accesses are in 8-bit chunks, the misuse of int variables will
result in a larger hex file.

Example :

#include <reg51.h>

sbit MY_BIT=P1^0;

void main(void)

{ unsigned int z;

for (z=0;z<=50000;z++)

{ MY_BIT=0;

MY_BIT=1;
}
}
Signed int:

• Signed int is a 16-bit data type.


• use the MSB D15 to represent – or +.
• We have 15 bits for the magnitude of the number from –32768 to +32767.

Example :

#include <reg51.h> // Header file of 8051

void main(void)

char mynum[ ]={+1,-1,+2,-2,+3,-3,+4,-4};

signed int z;

for (z=0;z<=8;z++)

P1=mynum[z];

Bit and SFR :

The bit data type allows access to single bits of bit-addressable memory spaces 20 –2FH

To access the byte-size SFR registers, we use the sfr data type.

Example:

// sbit and sfr data type

#include<reg51.h> //Header file for 8051

sbit test=P1^0;

sfr PORT=0x80;

void main(void)

{
unsigned char i;

for (i=0;i<=255;i++)

{
PORT=i;

test=~test;
}
}

You might also like