Friday 30 May 2014

8051 Programming in C

Why program 8051 in C

   Compilers produces hex file that is downloaded to ROM of the Micro-Controller. The size of the
hex file is the main concern of the Micro-Controller programmers. The reasons behind it are 
  1.  Micro-Controllers have limited on-chip ROM. 
  2. Code space for the 8051 is limited to 64K bytes. 

   Assembly language produces a file that is much smaller in size than produced by the C, but Assembly language is tedious and time consuming. C programming on the other hand is less time consuming and much easier to write but the hex file produced is much larger than  Assembly language. The reasons for writing code for Micro-Controller in C language are:
  1. It is easier and less time consuming to write in C than Assembly.
  2. C is easier to modify and update.
  3. You can use code available in function libraries.
  4. C code is portable to other MC with little or no modification.

C Data Types for 8051

   Since every 8051 programmer want small .hex file so it is worthwhile to re-examine C data types for the 8051. Here we discuss the most frequently used data types in 8051 programming.
  •  Char (Unsigned, signed)
  •  Int (Unsigned, Signed)
  •  Sbit
  •  Bit
  •  Sfr

Char data type

   The char (character) data type is the most natural choice of the programmers because 8051 is an 8-bit MC. The unsigned char is an 8-bit data type in the range of 0-255 (00-FFH). 
Signed char is an 8-bit data type uses the MSB D7 to represent - and + and gives values from -128 to +127. By default C compiler uses the signed char if there is no unsigned keyword. This data type is used widely for 8051 in setting up Counter values and ASCII characters. 

Int data type

   The unsigned int is 16-bit data type. It takes a value in the range of 0 to 65535 (00-FFFFH). It is used to define 16-bit variables such as memory addresses and setting up counter values of more than 256. The misuse of int data type may result a larger .hex file as it is 16-bit data type and registers and memory accesses are in 8-bit chunks. 
Signed int is a 16-bit data type uses the D15 to represent -and + sign. This data type ranges from -32,768 to +32767

 Sbit data type

   This keyword is widely used in 8051 C data type. It is designed specifically to access single-bit addressable registers. It allows access to the single bits of the SFR registers. It also allows access to single bit of the ports P0 to P3.

Bit data type

   The bit data type is used for the bit-addressable section of RAM space 20 - 2FH.

SFR data type

   This data type is used to access the byte-size SFR registers.


Tuesday 27 May 2014

8051 Family

The detail specifications of the 8051 are given below

8051 MC

The 8051 is the original member of the 8051 family. Which is refers to it as MCS-51. Following table shows the main features of the 8051.


Features
Quantity
RAM(bytes)
128
ROM
4K
Timers
2
Serial port
1
I/O pins
32
Interrupt sources
6
  
There are two other members of the 8051 family. Which are 8052 and 8031. 

8052 MC

The 8052 is another member of 8051 family.  The 8052 has all the standard features of the 8051 as well as some additional storage, timer and interrupt sources. Following table shows the important features of 8052.


Features
Quantity
RAM(bytes)
256
ROM
8K
Timers
3
Serial port
1
I/O pins
32
Interrupt sources
8

8031 MC

Another member of the 8051 family is 8031 which is referred to as ROM-less 8051 since it has no on-chip ROM. In order to use this MC you need to add extra ROM to it which contains the program that 8031 will fetch and execute. In the process of adding external ROM to 8031, you lose two of its Ports. This problem can be solved by adding external I/O to 8031. The external memory can ranges from 4Kbytes to 64Kbytes. The main features of the 8031 MC are given in the following table.
 

Features
Quantity
RAM(bytes)
128
ROM
0K
Timers
2
Serial port
1
I/O pins
32
Interrupt sources
6


Thursday 22 May 2014

8051 architecture

History  

In 1981, Intel Corporation introduced an 8-bit micro-controller called the 8051.
This micro-controller had 128 bytes of RAM, 4K bytes of on-chip ROM, two timers, one serial port, and four ports (each 8-bits wide) all on a single chip.
The 8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of data at a time.
Data larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU.
The 8051 has a total of four I/O ports, each 8 bits wide. 
Although the 8051 can have a maximum of 64K bytes of on-chip ROM, many manufacturers have put only 4K bytes on the chip.
The 8051 became widely popular after Intel allowed other manufacturers to make and market any flavors of the 8051 they please with the condition that they remain code-compatible with the 8051.
This has led to many versions of the 8051 with different speeds and amounts of on-chip ROM marketed by more than half a dozen manufacturers

 Inside Micro-Controller

In the following Figure you can see that all the supporting peripherals are at the single chip i.e CPU, ROM, RAM, Serial Port, TIMERS etc. 
Look at the following Diagram which explains in more details the architecture of Micro-Controller. some pins of the MC are shown in the diagram which are responsible for the functioning of the MC.