How To Program A Microcontroller 8051 In C

06.02.2020

Contents.About 8051 The Intel 8051 is an 8-bit microcontroller which means that most available operations are limited to 8 bits. There are 3 basic 'sizes' of the 8051: Short, Standard, and Extended. The Short and Standard chips are often available in DIP (dual in-line package) form, but the Extended 8051 models often have a different form factor, and are not 'drop-in compatible'. Pin diagram of the 8051 DIP Basic Pins PIN 9:PIN 9 is the reset pin which is used to reset the microcontroller’s internal registers and ports upon starting up. (Pin should be held high for 2 machine cycles.)PINS 18 & 19:The 8051 has a built-in oscillator amplifier hence we need to only connect a crystal at these pins to provide clock pulses to the circuit.PIN 40 and 20:Pins 40 and 20 are VCC and ground respectively. The 8051 chip needs +5V 500mA to function properly, although there are lower powered versions like the Atmel 2051 which is a scaled down version of the 8051 which runs on +3V.PINS 29, 30 & 31:As described in the features of the 8051, this chip contains a built-in flash memory.

8051

In order to program this we need to supply a voltage of +12V at pin 31. If external memory is connected then PIN 31, also called EA/VPP, should be connected to ground to indicate the presence of external memory.PIN 30 is called ALE (address latch enable), which is used when multiple memory chips are connected to the controller and only one of them needs to be selected.We will deal with this in depth in the later chapters.PIN 29 is called PSEN.

This is 'program store enable'. In order to use the external memory it is required to provide the low voltage (0) on both PSEN and EA pins.Pin 29:If we use an external ROM then it should have a logic 0 which indicates Micro controller to read data from memory.Pin 30:This Pin is used for ALE that is Address Latch Enable. If we use multiple memory chips then this pin is used to distinguish between them.It is activated periodically with a constant rate of 1/6th of oscillator frequency.This Pin also gives program pulse input during programming of EPROM.Pin 31:If we have to use multiple memories then by applying logic 1 to this pin instructs Micro controller to read data from both memories first internal and afterwards external.Ports There are 4 8-bit ports: P0, P1, P2 and P3.PORT P1 (Pins 1 to 8):The port P1 is a general purpose input/output port which can be used for a variety of interfacing tasks. Internal schematics of the 8051. Data and Program Memory The 8051 Microcontroller can be programmed in PL/M, 8051 Assembly, C and a number of other high-level languages. Some compilers even have support for compiling C for an 8051.Program memory in the 8051 is read-only, while the data memory is considered to be read/write accessible.

When stored on EEPROM or Flash, the program memory can be rewritten when the microcontroller is in the special programmer circuit or, if not using a 8031, through a preinstalled bootloader.Program Start Address The 8051 starts executing program instructions from address 0000 in the program memory.Special Function Register The Special Function Register (SFR) is the upper area of addressable memory, from address 0x80 to 0xFF. A, B, PSW, DPTR are called SFR.This area of memory cannot be used for data or program storage, but is instead a series of memory-mapped ports and registers.

All port input and output can therefore be performed by memory mov operations on specified addresses in the SFR. Also, different status registers are mapped into the SFR, for use in checking the status of the 8051, and changing some operational parameters of the 8051.General Purpose Registers The 8051 has 4 selectable banks of 8 addressable 8-bit registers, R0 to R7. This means that there are essentially 32 available general purpose registers, although only 8 (one bank) can be directly accessed at a time. To access the other banks, we need to change the current bank number in the flag register.A and B Registers The A register is located in the SFR memory location 0xE0.

The A register works in a similar fashion to the AX register of x86 processors. The A register is called the accumulator, and by default it receives the result of all arithmetic operations. The B register is used in a similar manner, except that it can receive the extended answers from the multiply and divide operations. When not being used for multiplication and Division, the B register is available as an extra general-purpose register. The A and B registers can store up to 8-bits of data each.

This post is about how to install keil to program 8051 Microcontroller. As we know to do anything with microcontrollers, we must have to program them first.

How To Program A Microcontroller 8051 In C

8051 Embedded C Programming Examples Pdf

So It’s very important to understand how to load software or program into the microcontroller while developing any Embedded Application. This process often called as ‘Loading a firmware’. So before loading any program into the microcontroller we must have to write a code or program either in assembly, C or C.

And then compile that program using compiler to generate hex file which we’ll burn/load into microcontroller.There are several software’s available to compile program and also to load HEX file into 8051. Here we’ll use Keil MicroVision an Integrated Development Environment (IDE), which integrate a text editor to write programs, a compiler which convert your source code to hex file. Later on we’ll use Flash Magic utility to load HEX file onto 8051 Microcontroller. Guide: Install Keil to Program 8051 MicrocontrollerIn some simple stepsSTEP 1Go to – Download – Product Downloads – Hit on C51 Setup.

Enter your contact information with valid address, phone number and email. Fill in all fields of form. Download is free for evaluation version. Find Keil Setup 8051STEP 2Then click on C51V954A.EXE and Download it on your computer.

Download Setup Keil 8051STEP 3Next step is to run setup file C51V954A.EXE and then we’ll get pop-up box, hit on Next and Proceed Installation. Proceed Installation Keil 8051STEP 4Read license agreement, check I agree to all the terms., and click Next. Accept Terms and ConditionsSTEP 5Select Destination folder where you want to install Keil or default destination is already there. And hit on Next. Choose Installation DirectorySTEP 6Fill up required fields with all relevant information and click on Next.

Proceed with Registered CredentialsSTEP 7Wait for installation completes and hit on Next. Wait until Installation finishesSTEP 8Tick on show release notes, deselect remaining (as per your choice) and click on Finish.

Click Finish And Installation DoneNow we’re done, install Keil to Program 8051 Microcontroller under windows. We hope you will find this tutorial educational. If you have any question then please feel free to leave a comment. Thanks and see you in next tutorial where we’ll create fresh new Keil uVision project for 8051 Microcontroller.