0% found this document useful (0 votes)
67 views13 pages

Embedded C Programming With 8051

The document discusses embedded C programming for the 8051 microcontroller architecture. It covers memory areas, data types, bit addressing, special function registers, pointers, and memory models when programming for the 8051 in C. Key topics include declaring variables in different memory types like data, code, and xdata, using bit and sbit data types, accessing special function registers, and generic versus memory-specific pointers.

Uploaded by

V Prakash Singh
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
0% found this document useful (0 votes)
67 views13 pages

Embedded C Programming With 8051

The document discusses embedded C programming for the 8051 microcontroller architecture. It covers memory areas, data types, bit addressing, special function registers, pointers, and memory models when programming for the 8051 in C. Key topics include declaring variables in different memory types like data, code, and xdata, using bit and sbit data types, accessing special function registers, and generic versus memory-specific pointers.

Uploaded by

V Prakash Singh
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/ 13

Embedded C Programming with 8051

Feb,01 2021
Programming Lamguage for Embedded System
Development

Assembly language is a low-level programming language which is


specific for a processor architecture.

In contrast, high level language programs are easily portable across


different architectures.
Embedded processors e.g. 8051 have limited processing power and
memory: the programs must be efficcient.

An assembly program provides complete and precise control of the


available hardware resources.

Embedded C Programming with 8051


Programming Lamguage for Embedded System
Development
The 8051 architecture supports several physically separate memory
areas for program and data.

Figure: Explicitly declared memory types

Embedded C Programming with 8051


Embedded C Programming

The 8051 architecture supports several physically separate memory


areas for program and data.

Figure: Explicitly declared memory types

Embedded C Programming with 8051


Memory Areas

The 8051 architecture supports several physically separate memory


areas for program and data.

Figure: Explicitly declared memory types

Embedded C Programming with 8051


Memory Areas

Yoy may specify where variables are stored by including a memory


type specifier in the variable declaration. For example

char data var1;

char code text[ ] = ”HELLO WORLD”;

float idata x,y,z;

char bdata flags;

unsigned char xdata vector [10][4][2];

Embedded C Programming with 8051


Memory Models

The memory model determines the default memory type to use for
function arguments, automatic variables and declarations with no
expliit memory type specifier.

In compact model, all variables by default reside in one page of


external data memory. Maximum of 256 bytes of variable. Indirect
addressing through R0 and R1.

In Large model, all variables by default reside in external data


memory. Maximum of 64 Kbytes of variable. Indirect addressing
through DPTR.

In small model, all variables by default reside in the internal data


memory. All objects as well as stack must fit into the internal RAM.

Embedded C Programming with 8051


Data Types
The 8051 architecture supports several physically separate memory
areas for program and data.

Figure: Data Types in C51 Compiler

Embedded C Programming with 8051


Bit Data Type

You may use the bit data types for variable declarations, argument
lists and function return values. E.g. static bit doneflag = 0;

All bit variables are stored in a bit segment in the 16 bytes of


internal memory area of 8051. A maximum of 128 bit variables.

Memory types of data or idata only may be included in the


declaration.

An array of type bit is invalid. A bit cannot be declared as a pointer.

Functions that disable interrupts and functions that are declared


using an explicit register bank can not return bit data type.

Embedded C Programming with 8051


Bit Addressable Objects

Bit-addressable objects are objects that can be addressed as words


or as bits. Only data objects that occupy the bit-addressable area of
the 8051 internal memory fall in this category.

You may declare these variables as


int bdata ibase; ( bit addressable integer)
char bdata bary[4]; (bit addressable array)

You may use the sbit keyword to declare new variables that access
the bits of variables declared using bdata. For example:
sbit mybit = ibaseˆ7; (bit 15 of variable ibase))
ary07 = bary[0]ˆ7; (bit 7 of bary[0])

Embedded C Programming with 8051


Bit Addressable Objects

Declarations involving the sbit type require that the base object be
declared with the memory type bdata or it may be a special function
register.

You may declare these variables as external for the sbit type to
access these types in other modules.
extern bit mybit0; (bit 0 of ibase)
extern bit ary07; (bit 7 of bary[0])

You may not specify bit variables for the bit positions of a float.

The sbit data type uses the specified variable as a base address and
adds the bit position to obtain a physical address.

Embedded C Programming with 8051


Special Function Registers

SFRs are used in programs to control timers, counters, serial I/O,


port I/O and other peripherals. Declarations for SFRs are provided
in the include files for particular 8051 derivatives.

SFRs reside from address 0x80 to 0xFF and can be accessed as bits,
bytes and words.

C51 compiler provides access to SFRs with the sfr, sfr16 and sbit
data types.
sfr P0 = 0x80; (Port 0 address 80h)
sfr16 T2 = 0xCC; (Timer 2, T2L address 0CCh and T2H 0CDh)
sbit EA = 0xAF; (SFR bit at address AFh)
sbit OV = PSWˆ2; (PSW Registers 2nd bit)
sbit OV = 0XD0ˆ2; (PSW Registers 2nd bit)
sbit OV = 0XD2 ;(PSW Registers 2nd bit)

Embedded C Programming with 8051


Pointers

The C51 compiler supports the declarartion of variable pointers


using the ∗ character.

C51 pointers can be used to perform all operations available in


standard C.

C51 compiler provides two different types of pointers: generic


pointers and memory-specific pointers.
Generic pointer are similar to standard C pointers. e.g. char *s;
(string pointer). These pointers may be used to access any variable
regardless of its location in 8051 memory space.
Memory specific pointers always include a memory type specification
in the pointer declaration and always refer to a specific memory area.
e.g. char data *str; (pointer to string in data)

Embedded C Programming with 8051

You might also like