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
pravin_35 Avatar
Posted By pravin_35
Tue Jul 22 2014, 01:05 PM
hi... i have done with a simple blinky program wi...
pravin_35 Avatar
Posted By pravin_35
Tue Jul 22 2014, 07:23 AM
Autoscale does not know what settings you keep on ...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Jul 22 2014, 02:19 AM
[Topic moved to PIC Microcontroller Discussion For...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Jul 22 2014, 02:18 AM
[Topic moved to electronics discussion forum]
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Jul 22 2014, 02:17 AM
This type of problem comes in gcc based softwares....
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Jul 22 2014, 01:54 AM
are you sure your read is working properly? I mean...
ajay_bhargav Avatar
Posted By ajay_bhargav
Tue Jul 22 2014, 01:46 AM
Autoscale does not know what settings you keep on ...
pravin_35 Avatar
Posted By pravin_35
Tue Jul 22 2014, 01:06 AM
hi guys, please kindly suggest me a good PV charge...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jul 21 2014, 04:15 PM
but when I executed the program something went ba...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jul 21 2014, 04:06 PM
That MCP3901 is a very complicated chip.I have no ...

Conversation

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
ExperimenterUK
Tue Jul 08 2014, 03:25 PM
Post questions in the forum.. this area is for chat
Tue Jul 08 2014, 08:15 AM
P.Panchanyam
Sir i want some new ideas for my final year projects ,which would help for our soceity in future
Tue Jul 08 2014, 01:39 AM
jasvinder
Dear Sir Ref. to the discussion held with under sign, the detail is as under--- We are in weighing scale field since 1986. We are assembling the scales by purchasing the material from out source ( From India and other countries). Now we decide to make our own Card in our decided shape. So we want to develop a universal card , which we can make all types of scales of up 100000 counts with 7 segment LED Display . Also with other features like Printing, Counting, RS232 Etc. And Three Pass words at different levels. And we can edit the Softwear. What else you can provide in this field, also mention. We will pay you the development , softwear and testing charges. And up-gradation charges at time to time. Our web site is modern-scales.com Kindly revert.
Mon Jul 07 2014, 09:20 AM
tadashige matuda
Please tell me about pic instruction ADDWF fileName,f ; fileName=fileName+W. Why twice memory access (1)fileName+W,(2)fileName=fileName+W, be able in one instruction cycle. For MOVWF fileName ; memory access once in an one instruction cycle.
Mon Jul 07 2014, 09:08 AM
tadashige matuda
pic instruction
vshal
Thu Jul 03 2014, 11:09 AM
Can somebody tell me, RLP434A 418MHz RF receiver module , this module Where get in pune ?

Downloads

Comments

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
salemalqahtani
Sun Jul 20 2014, 12:55 AM
nagarajan.electro
Sat Jul 19 2014, 12:49 AM
praru
Sat Jul 12 2014, 07:51 AM
nmcleod1993
Thu Jul 10 2014, 09:02 AM
abdulmannan39
Thu Jul 10 2014, 05:50 AM

Online

Guests: 67, Members: 0 ...

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

Members: 37479
Newest member: vinosentinal