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
		
Forum Activity
NexusRevZ Avatar
Posted By NexusRevZ
Wed Jul 30 2014, 02:31 AM
Ok, I have edited the code, it's updated above wit...
NexusRevZ Avatar
Posted By NexusRevZ
Wed Jul 30 2014, 02:10 AM
Oh tahnk you so much for the reply. I will do imme...
ajay_bhargav Avatar
Posted By ajay_bhargav
Wed Jul 30 2014, 01:56 AM
You cannot move and read data from EEPROM immediat...
pravin_35 Avatar
Posted By pravin_35
Wed Jul 30 2014, 12:39 AM
Remove all power connections to the circuit at the...
NexusRevZ Avatar
Posted By NexusRevZ
Tue Jul 29 2014, 09:31 PM
This simple code is test the write and read of EEP...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jul 29 2014, 02:08 PM
Remove all power connections to the circuit at the...
pravin_35 Avatar
Posted By pravin_35
Tue Jul 29 2014, 06:00 AM
Fyiimage with connections
pravin_35 Avatar
Posted By pravin_35
Tue Jul 29 2014, 05:53 AM
another chip is also same problem... i am confused...
pravin_35 Avatar
Posted By pravin_35
Tue Jul 29 2014, 01:41 AM
hi guys i found the following link is very useful...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jul 28 2014, 11:17 PM
Link the tx and rx pins on HC06, everything you se...

Conversation

NexusRevZ
Tue Jul 29 2014, 09:32 PM
Anyone good in Asm lang?
ajay_bhargav
Mon Jul 28 2014, 12:34 AM
@ Anshu Raj sorry we do not take such requests.
Sun Jul 27 2014, 12:23 AM
Anshu Raj
sir plz send the automatic collage alram bells in 2 hrs bells ring. For microcontroller programme plz sir
ajay_bhargav
Thu Jul 24 2014, 01:06 AM
@R.ABHISHEK where? I dont see it. is it in forum?
Wed Jul 23 2014, 05:49 AM
R.ABHISHEK
sir,pls message on microcontroller 8051 assambly language new program
Wed Jul 23 2014, 05:47 AM
R.ABHISHEK
sir,pls message on 8051 microcontroller assambly language program new quastions
ajay_bhargav
Tue Jul 22 2014, 09:18 AM
@Pragya Android application is taken from google play. Only Author has its source with him. Application is only used in this project.
Tue Jul 22 2014, 04:58 AM
Pragya
plz send me 8051 code and android code for android based device controller via Bluetooth .Here in this project I am using Hc-06 Bluetooth module
Thu Jul 10 2014, 09:57 AM
Caleb
plz someone mail me the source code for that project
Thu Jul 10 2014, 09:57 AM
Caleb
http://www.8051projects.net/download-d188-control-your-pc-tv-remote.html

Downloads

Comments

NexusRevZ
Tue Jul 29 2014, 09:29 PM
kritz22
Mon Jul 28 2014, 10:33 AM
Abbasans786
Mon Jul 28 2014, 03:15 AM
Imran.pk
Fri Jul 25 2014, 07:50 PM
PavanKh
Fri Jul 25 2014, 12:56 AM
vinosentinal
Mon Jul 21 2014, 08:28 PM
niks_here
Sun Jul 20 2014, 05:38 PM
athiramsankar
Sun Jul 20 2014, 12:00 PM

Online

Guests: 35, Members: 0 ...

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

Members: 37484
Newest member: NexusRevZ