Embedded C Basic
Embedded C Basic
It has hardware.
It has application software.
It has Real Time Operating system (RTOS) that supervises the application software and provide
mechanism to let the
processor run a process as per scheduling by following a plan to control the latencies.
• RTOS defines the way the system works.
• It sets the rules during the execution of application program.
• A small scale embedded system may not have RTOS.
Why C:
Compilers produce hex files that are downloaded into ROM of microcontroller. The assembly language
produces a hex file that is much smaller than C. Assembly language programming is tedious and time
consuming. C is less time consuming and much easier to write.
Advantages of C programming:
a. Easier and less time consuming to write in C than assembly programming.
b. C is easier to modify and update
c. You can use code available in function libraries
d. C code is portable to other microcontroller with little or no modification
Assembly language:-
● User can control exact instruction and its sequence
● Size of generated hex file is compact
● Tedious and time consuming
● Function library does not exists
● Program modification is complicated
● ASP code is not portable
i. Unsigned char
i. Unsigned char:
Since 8051 is an 8-bit microcontroller, the character data type is the most natural
choice for many applications and most widely used data types for 8051. It is an 8-bit
data type that takes a value in the range of 0 – 255(00H – FFH). It occupies one byte
location in internal RAM. In setting a counter value, to store string of ASCII characters,
where there is no need for signed data, unsigned char should be used instead of
signed char. Default is signed char. „unsigned‟ keyword is used to declare unsigned
char.
bdata: The variable chosen for the program will be stored in bit addressable memory of the
microcontroller.
unsigned char bdata v;
code: Its used to store a constant variable like string or large integer numbers in code memory.
xdata: The variable used in the program will be stored in the RAM memory of the controller.
pdata: This will store the variable in the program in the paged data memory.
sfr P1 = 0x40;
Pointers in Keil C
Generic and Memory-specific pointers are commonly used as pointers in Keil C.
Generic Pointers
● char *a;
Memory-Specific Pointers
● The memory type and the pointer variable is indicated in the program statement.
Functions
Function Declaration
{
while (1) //repeat forever
{ P1=0x55;
MSDelay(250); p1=0xAA;
MSDelay(250);
Solution:
for (;;)
{ P1=0x55; P1=0xAA;
Write an 8051 C program to monitor bit P1.5. If it is high, send 55H to P0;
otherwise, send AAH to P2.
Solution:
if (mybit==1) P0=0x55;
else P2=0xAA;
Format: data >> number of bits to be shifted right data << number of bits to be shifted left.
These operators are widely used in software engineering for embedded systems and control.