Search This Blog

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

 

Wednesday, August 28, 2013

compiling c program-linux

Compiling a c program in linux:

to run a c program in your linux machine you need 2 software packages

1.vi or vim editor
2.gcc compiler


check those software by typing the gcc and vi or vim command on the terminal
if it shows command not found then you need to install that software

to do so a simple command is useful for you

yum install software

yum command automatically searches the software package and installs the latest one

so type
yum install gcc vi vim

the it automatically install the 3 packages

vi and vim both are code editors vi is a default one but it show the code in single color
where as vim show the different colors .like variables,strings,functions...etc

its look like



see the colors in vim editor






after installing the packages first create  c file uisng vim editor

vim hw.c

its creats hw.c file and enter into editor now editor is in command mode so you need to enter into insert mode to edit the code for the type 'i'
the edit the code

the press 'esc' key to enter into command mode the ':x' to save and exit

* :x<Return> quit vi, writing out modified file to file named in original invocation
  :wq<Return> quit vi, writing out modified file to file named in original invocation
  :q<Return> quit (or exit) vi
* :q!<Return> quit vi even though latest changes have not been saved for this vi call


after exiting the editor compile the code using gcc compiler

gcc hw.c------------by default it outputs the file with a.out name

gcc hw.c -o hw.o----now the output fie name is hw.o

if there are no errors it will creates the output file
to run that file type

./a.out   or   ./hw.o

then your code will shows the output..


Tuesday, August 27, 2013

create folder-linux

Creating a folder

mkdir is a simple command to create a folder/directory

mkdir espot

then espot directory is created

cd espot

navigates to 'espot' directory

here  
ls
command  shows the files and directories with in present directory




remove folder -linux

Command to remove a empty and non-empty directory:

rm directory
or
rmdir directory

both will deletes the 'directory' if it is an empty directory

and
if it is not a empty directory then these commands will return an error message

for rm command:
rm: cannot remove ‘directory’: Is a directory

for rmdir command:
rmdir: failed to remove ‘directory’: Directory not empty


Solution is with rmdir we can not delete the non-empty directory

by using rm command with argument

rm -rf directory

 Here,




-r, -R, --recursive
              remove directories and their contents recursively

-f, --force
              ignore  nonexistent  files  and  arguments,  never
              prompt