(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:8051_tutorials]]
 
[[Category:8051_tutorials]]
Seven segment displays allow you to show numbers/digits in a bright fashion. Let us look at interfacing 7 segments with 8051.
+
In this tutorial we see how to setup Keil4 for generating .hex file.<br>
=Video Tutorial=
+
Keil software can be downloaded from [https://github.com/ExploreEmbedded/Keil4_For_8051/archive/master.zip this link].<br>
 +
Download and install the Keil C51 for 8051.<br>
 +
[[FILE:01Kiel.PNG]]<br>
  
<html>
 
<iframe width="560" height="315" src="//www.youtube-nocookie.com/embed/-ECiWj32KC0?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
 
</html>
 
{{Box|type=l_green_light|text=<br />
 
=Seven Segment Display=
 
[[File:BasicSevenSegmentDisplay.png|thumbnail|fig 1: Basic 7 segment Display]]
 
[[File:7 segments Indicator.gif|framed|fig 2: Simulation]]
 
Well, the name 7 segments implies there are 7 LED segments arranged as shown in figure 1.
 
After LEDs they are the easiest interfaces to a microcontroller.
 
There is also a decimal point or dp. It is used when decimal digits like 5.1 etc are displayed.
 
==Applications==
 
Seven segment are widely used in applications where digits[0-9] are required to be displayed.Although they also display letters A to F as shown in figure(2) simulation.
 
This is a very simple and convenient way to display numbers in a bright fashion.
 
==Form Factor==
 
  
*'''Sizes''':They come in various sizes; 0.28”, 0.3”, 0.32”, 0.36”, 0.39”, 0.4”, 0.5”, 0.56”, 0.6”, 0.8”, 1.0”, 1.2”, 1.5”, 1.8”, 2.0”, 2.3”, 3.0”, 4.0”, 5.0”, 7.0”)
+
=Keil Setup Steps=
*'''Colors''': and varied colors too; Red, Green, Yellow, Orange, Blue, and White.
+
<b>Step1:</b> Open the Keil software and select the New Microvision project from Project Menu as shown below.<br>
==Working==
+
[[FILE:8051_Keil_01.png]]<br>
[[File:Common Cathode 7Segment.jpeg|thumbnail|fig 3:Common Cathode Display]]
+
[[File:Common Anode 7Segment.jpeg|thumbnail|fig 4: Common Anode 7 segment]]
+
Since these are basically LEDs arranged as a group they can either have anode in common or cathode.
+
*'''Common Cathode''': This type of 7 segments, requires a positive voltage(5v) to given to the segments '''a''' to '''g''' in order to glow. This is shown in figure(3). Providing a positive voltage with respect to common cathode makes the LED forward biased.
+
*'''Common Anode''': This type of 7 segments, requires a negativevoltage(GND) to given to the segments '''a''' to '''g''' in order to glow. This is shown in figure(4). A ground connection to cathode with respect to common anode again forward biases the LED which glows.<br />
+
}}
+
  
=Interfacing 7 segment display to 8051 =
+
<b>Step2:</b> Browse to your project folder and provide the project name and save it.<br>
==Driving the Seven Segment==
+
[[FILE:8051_Keil_02.png]]<br>
[http://exploreembedded.com/wiki/images/3/38/Schematic_8051_Interfacing_7Segment_1.pdf '''Schematic Diagram''']
+
[[File:Schematic 8051 Interfacing 7Segment.JPG|680px]]
+
==Code==
+
<syntaxhighlight enclose="div">
+
 
+
#include <reg51.h>  
+
#include "delay.h"
+
 
+
#define SegmentValue P0
+
#define SegmentSelection P2
+
#define SegOne  0x01
+
#define SegTwo  0x02
+
#define SegThree 0x04
+
#define SegFour  0x08
+
/* start the main program */
+
void main()
+
{
+
unsigned char seg_code[]={0xfc,0x60,0xda,0xf2,0x66,0xb7,0xbe, 0x30,0xfe,0xf6,0xee,0xfe,0x9c,0xfc,0x9e,0x70};
+
  unsigned char cnt=0;
+
  while(1)
+
    {  
+
      for(cnt=0x00;cnt<=0x0f;cnt++) // loop to display 0-F
+
  {
+
  SegmentSelection = SegOne; // Select segment
+
SegmentValue= seg_code[cnt]; // Send code
+
delay_sec(1);
+
          }
+
    }  
+
}
+
</syntaxhighlight>
+
 
+
=Downloads=
+
[http://exploreembedded.com/wiki/images/3/38/SevenSegment.zip Code]
+
 
+
 
+
 
+
[[File:8051_LED_Interface_Cover.png|left|thumbnail|x240px|{{Box|type=l_blue_light|text=LED Interfacing with 8051}}|link=LED_Interfacing_with_8051|'''''PREVIOUS TUTORIAL''''']]
+
[[File:SwitchesLEDs.jpg|right|thumbnail|x120px|{{Box|type=l_blue_light|text=Switches and LED Interfacing with 8051 }}|link=8051_Interfacing_swithes_leds|'''''NEXT TUTORIAL''''']]
+
  
 +
<b>Step3:</b> Once the project is saved a new pop up “Select Device for Target” opens, Select the required 8051 series controller and click on OK.<br>
 +
#Atmel->AT89s52<br>
 +
#NXP->P89V51RD2<br>
 +
#Nuvoton-> W78E052D<br>
 +
Since all the controller follow the same 8051 architecture, any of the above mentioned controller can be selected.
 +
[[FILE:8051_Keil_03.png]]<br>
  
 +
<b>Step4:</b>Select Atmel->At89s52 and click OK.<br>
 +
[[FILE:8051_Keil_04.png]]<br>
  
  
 +
<b>Step5:</b>8051 doesn't need the startup code, click on <b>NO</b> option to proceed.<br>
 +
[[FILE:8051_Keil_05.png]]<br>
  
  
 +
<b>Step6:</b> Create a new file to write the program.<br>
 +
[[FILE:8051_Keil_06.png]]<br>
  
  
 +
<b>Step7:</b> Type the code or Copy paste the below code snippet and save the file as main.c<br>
 +
[[FILE:8051_Keil_07.png]]
 +
<html>
 +
<script src="https://gist.github.com/sharanago/16048113a83ad744505631bc67fdefcc.js"></script>
 +
</html>
 +
<br>
  
  
 +
<b>Step8:</b>Save the file as main.c<br>
 +
[[FILE:8051_Keil_08.png]]<br>
  
 +
<b>Step9:</b>Add the file to the project using the option <b>Add files to Source Group</b>.<br>
 +
[[FILE:8051_Keil_09.png]]<br>
  
 +
<b>Step10:</b> Add the recently saved file to the project.<br>
 +
[[FILE:8051_Keil_10.png]]<br>
  
 +
<b>Step11:</b>Now the main.c file should appear in Project Source Group.<br>
 +
[[FILE:8051_Keil_11.png]]<br>
  
 +
<b>Step12:</b>Build the project and fix the compiler errors/warnings if any.
 +
[[FILE:8051_Keil_12.png]]<br>
  
 +
<b>Step13:</b>Code gets compiled with no errors and .hex file is still not generated.<br>
 +
[[FILE:8051_Keil_13.png]]<br>
  
 +
=Enable Hex File Generation=
 +
<b>Step14:</b>Click on <b>Target Options</b> to select the option for generating .hex file.<br>
 +
[[FILE:8051_Keil_14.png]]<br>
  
 +
<b>Step15:</b> Rebuild the target to generate the .hex file. <br>
 +
[[FILE:8051_Keil_15.png]]<br>
  
 +
<b>Step16:</b> Check teh project folder for generated .hex file.
 +
[[FILE:8051_Keil_16.png]]<br>
  
  
 +
=Uploading the Hex file=
 +
After generating the .hex file check the below tutorials for uploading it.
 +
# [[Uploading Hex File Using nuvoTon|Uploading Hex File Using nuvoTon ISP.]]
 +
# [[Uploading Hex File Using At89s52 ISP Programmer|Uploading Hex File To At89s52 using ISP Using Programmer.]]
 +
<br><br>
  
  
Would like to have your feedback and suggestions here;
+
Have a opinion, suggestion , question or feedback about the article let it out here!
 
{{DISQUS}}
 
{{DISQUS}}

Latest revision as of 17:36, 19 August 2016

In this tutorial we see how to setup Keil4 for generating .hex file.
Keil software can be downloaded from this link.
Download and install the Keil C51 for 8051.
01Kiel.PNG


Keil Setup Steps

Step1: Open the Keil software and select the New Microvision project from Project Menu as shown below.
8051 Keil 01.png

Step2: Browse to your project folder and provide the project name and save it.
8051 Keil 02.png

Step3: Once the project is saved a new pop up “Select Device for Target” opens, Select the required 8051 series controller and click on OK.

  1. Atmel->AT89s52
  2. NXP->P89V51RD2
  3. Nuvoton-> W78E052D

Since all the controller follow the same 8051 architecture, any of the above mentioned controller can be selected. 8051 Keil 03.png

Step4:Select Atmel->At89s52 and click OK.
8051 Keil 04.png


Step5:8051 doesn't need the startup code, click on NO option to proceed.
8051 Keil 05.png


Step6: Create a new file to write the program.
8051 Keil 06.png


Step7: Type the code or Copy paste the below code snippet and save the file as main.c
8051 Keil 07.png


Step8:Save the file as main.c
8051 Keil 08.png

Step9:Add the file to the project using the option Add files to Source Group.
8051 Keil 09.png

Step10: Add the recently saved file to the project.
8051 Keil 10.png

Step11:Now the main.c file should appear in Project Source Group.
8051 Keil 11.png

Step12:Build the project and fix the compiler errors/warnings if any. 8051 Keil 12.png

Step13:Code gets compiled with no errors and .hex file is still not generated.
8051 Keil 13.png

Enable Hex File Generation

Step14:Click on Target Options to select the option for generating .hex file.
8051 Keil 14.png

Step15: Rebuild the target to generate the .hex file.
8051 Keil 15.png

Step16: Check teh project folder for generated .hex file. 8051 Keil 16.png


Uploading the Hex file

After generating the .hex file check the below tutorials for uploading it.

  1. Uploading Hex File Using nuvoTon ISP.
  2. Uploading Hex File To At89s52 using ISP Using Programmer.




Have a opinion, suggestion , question or feedback about the article let it out here!