Introduction

The use of C language to program microcontrollers is becoming too common. And most of the time its not easy to buld an application in assembly which instead you can make easily in C. So Its important that you know C language for microcontroller which is commonly known as Embedded C. As we are going to use Keil C51 Compiler, hence we also call it Keil C.

Keywords

Keil C51 compiler adds few more keywords to the scope C Language:

_at_ far sbit
alien idata sfr
bdata interrupt sfr16
bit large small
code pdata _task_
compact _priority_ using
data reentrant xdata
data/idata

Description: The variable will be stored in internal data memory of controller. example:

unsigned char data x;
//or
unsigned char idata y;
		
bdata

Description: The variable will be stored in bit addressable memory of controller. example:

unsigned char bdata x;
//each bit of the variable x can be accessed as follows
x ^ 1 = 1; //1st bit of variable x is set
x ^ 0 = 0; //0th bit of variable x is cleared
		
xdata

Description: The variable will be stored in external RAM memory of controller. example:

unsigned char xdata x;
		
code

Description: This keyword is used to store a constant variable in code memory. Lets say you have a big string which is not going to change anywhere in program. Wasting ram for such string will be foolish thing. So instead we will make use of the keyword "code" as shown in example below. example:

unsigned char code str="this is a constant string";
		
pdata

Description: This keyword will store the variable in paged data memory. This keyword is used occasionally. example:

unsigned char pdata x;
		
_at_

Description: This keyword is used to store a variable on a defined location in ram. example:

unsigned char idata x _at_ 0x30;
// variable x will be stored at location 0x30
// in internal data memory
		
sbit

Description: This keyword is used to define a special bit from SFR (special function register) memory. example:

sbit Port0_0 = 0x80;
// Special bit with name Port0_0 is defined at address 0x80
		
sfr

Description: sfr is used to define an 8-bit special function register from sfr memory. example:

sfr Port1 = 0x90;
// Special function register with name Port1 defined at addrress 0x90
		
sfr16

Description: This keyword is used to define a two sequential 8-bit registers in SFR memory. example:

sfr16 DPTR = 0x82;
// 16-bit special function register starting at 0x82
// DPL at 0x82, DPH at 0x83
		
using

Description: This keyword is used to define register bank for a function. User can specify register bank 0 to 3. example:

void function () using 2
{
	// code
}
// Funtion named "function" uses register bank 2 while executing its code
		
interrupt

Description: This keyword will tells the compiler that function described is an interrupt service routine. C51 compiler supports interrupt functions for 32 interrupts (0-31). Use the interrupt vector address in the following table to determine the interrupt number.

Interrupt vector
example:

void External_Int0() interrupt 0
{
	//code
}
		

Memory Models

There are three kind of memory models available for the user:

Small
All variables in internal data memory.
Compact
Variables in one page, maximum 256 variables (limited due to addressing scheme, memory accessed indirectly using r0 and r1 registers)
large
All variables in external ram. variables are accessed using DPTR.
Depending on our hardware configuration we can specify the momory models as shown below:

//For Small Memory model
#pragma small
//For Compact memory model
#pragma compact
//For large memory model
#pragma large
		

Conversation

Fri Dec 19 2014, 11:31 AM
1
-1'
Fri Dec 19 2014, 11:30 AM
1
1
ajay_bhargav
Fri Dec 12 2014, 04:38 AM
@Abdul BAsit, Post in forum please. We will help you.
Wed Dec 10 2014, 06:41 PM
Abdul BAsit
I am working on smoke detector using AT89S52 and dont know how its wors..kindly send me circuit diagram and code for its hardware & software implementation
Tue Dec 09 2014, 11:30 AM
Irinel
Please send me the content of that cd-rom (embedded c - michael j pont. Thank you.
Tue Dec 09 2014, 02:45 AM
kmyo
please give me the operation of 12v trickle charger
Sun Dec 07 2014, 07:50 AM
hidawi
we need the circuit diagrom of the remote control of iduction motor by android appliction
PsySc0rpi0n
Tue Dec 02 2014, 10:30 AM
I have no idea... I'm new to micro controllers
Tue Dec 02 2014, 08:35 AM
samarnath dev
how can usb key bord interfasing to dot matrx led moving, by asm51 ?
Tue Dec 02 2014, 08:32 AM
samarnath dev
how can usb key bord interfasing to 8051 by asm code?

Downloads

Comments

naimish324
Wed Dec 17 2014, 04:48 AM
sathish177
Tue Dec 16 2014, 06:43 PM
djnokey
Sat Dec 13 2014, 12:12 PM
sai9113
Tue Dec 09 2014, 07:23 AM
alexlomol
Fri Dec 05 2014, 12:06 AM
chandujonty
Thu Dec 04 2014, 10:11 AM
fantasy1214
Mon Dec 01 2014, 01:45 PM
vumbelino
Sat Nov 29 2014, 04:43 PM

Online

Guests: 59, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37560
Newest member: naimish324
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Dec 19 2014, 09:58 PM
For what you want,it is easier to not use interrup...
sankalp_s Avatar
Posted By sankalp_s
Fri Dec 19 2014, 06:04 PM
This version works.Edit it to use either method. ...
muhibraza Avatar
Posted By muhibraza
Fri Dec 19 2014, 08:05 AM
software_developer Avatar
Posted By software_developer
Fri Dec 19 2014, 04:54 AM
Which files i have to use?Please give me .zip fold...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Dec 19 2014, 12:21 AM
This version works.Edit it to use either method. ...
sankalp_s Avatar
Posted By sankalp_s
Thu Dec 18 2014, 08:40 PM
SIR THIS CODE IS NOT WORKING.. ORG 000H ; starting...
sankalp_s Avatar
Posted By sankalp_s
Thu Dec 18 2014, 08:36 PM
i've tried this code but faced a syntax error on l...
sankalp_s Avatar
Posted By sankalp_s
Thu Dec 18 2014, 08:32 PM
SIR THIS CODE IS NOT WORKING.. ORG 000H ; starting...
ajay_bhargav Avatar
Posted By ajay_bhargav
Thu Dec 18 2014, 04:24 AM
Code is all ok.. just change EXT0 to EX0... By mis...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Dec 17 2014, 11:21 PM
i've tried this code but faced a syntax error on l...