Search This Blog

Showing posts with label 8051. Show all posts
Showing posts with label 8051. Show all posts

Friday, August 30, 2013

Creating header file in keil

Creating header file in keil :

        To develop a complex or a big project in keil we need to write more code so , as the number of lines increasing the complexity of editing the code is also increases so we need to optimize the code structure to access it easily. we can do so by creating header files. Header files mainly contains some functions which are called by main function and these header files may stored in the same folder or in another folder. if the header file and the project is in the same folder then  "#include<header_file_name>" is used to call a header file. if the header files stored in other location then "#include"path../header_file_name"" is used.

        Here is the simple procedure is shown about creating header file in keil is shown. you can find the clear view in video on creating header file in keil.

there are some steps for this, those are

step1:first create 3 folders with in out project folder and name them as 
      'APP','DRV','OUT'
     APP-is for our application file i.e., main files
     DRV-is for driver functions 
     OUT-is for output files

step2: create a project in keil and in the target option add 2 source groups and name them as 'APP','DRV'

step3:make delay.c and delay.h files as shown in the video 
      delay.c file having the function body and delay.h file having the function declaration
      save the both files in DRV folder

step4: now add delay.c file to DRV source group so that it will get compile along with main.c file

step5:go to 'Options for target'  the go to 'output' tab then click on 'folder for objects' and select OUT       
     folder

step6:then go to 'C51' tab and in 'include paths' add 'APP' and 'DRV' folders so that the compiler 
     searches the header file in that included paths

step7:add #include "delay.h" line in main file  and compile the code

follow the video for better understanding of creating header file in keil




Full


led blinking-8051

LED Blinking program in 8051:

8051 is a 8-bit micro-controller. i.e.,it data  bus size is 8-bit  so that each port in 8051 having 8 pins and having 4 ports Port-0,Port-1,Port-2,Port-3

this example showing the led blinking for Port 1

#include <reg52.h>//header file for 8051 or 8052
void delay(int ch)
{
int i=0,j=0;
for(i=0;i<ch;i++)
{
    for(j=0;j<1275;j++)
    {
    }
}
}
void main()
{
while(1)
{
    P1=0x00;
    delay(20);
    P1=0xff;
    delay(20);
}   
}


here while(1) is a continues loop (infinity loop)

P1=0x00; means all pins are active low that means zero Volts
P1=0xff; means all pins are active high that means 5 Volts

we are providing a delay of  200 millisec for ON and OFF state

below video shows every thing