Friday 31 October 2014

Generate a Delay using for loop in Embedded C using Microcontroller 8051

/* In Microcontroller programming if you want to generate a normal delay then you can generate using for loop also.
Here i m gonna write a program to toggle a bit of port P0 of microcontroller using delay.
*/

#include<Reg51.h>

sbit MyBit = PO^1 ;
void My_Delay(unsigned char z) ;

void main()
{
   while(1)
       {
          MyBit = 1 ;
            My_Delay(1500) ;
          MyBit = 0 ;
            My_Delay(1500) ;
       }


}

void My_Delay(unsigned char z)
   {
       int i ;
   for(i=0 ; i <= z ; i++) ; //to generate more delay you can use two for loops
   }

Proteous Simulation of above code is here



Wednesday 29 October 2014

8051 Microcontroller interfacing with seven segment using Embedded C and simulation over proteous.

   
//this program run and compile with kiel uvision 3
// Here is your program :-
#include<reg51.h>
#define SegmentPort P1   //this line assigne variable segmentport to port P1

void MsDelay(int x) ;   //delay function prototype
void main()
{     
    unsigned char z,x ;
  char MyArray[]={0xc0,0xf9,0xA4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff} ;
    //this array content hex value equal to 0 to 9 decimal values this value can be change according to seven segment.
  SegmentPort = 0x00 ;  //here P1 define as a output port
   while(1)
    {
          for(z=0;z<=11;z++)
           {
                   P2 = MyArray[z] ;
                   MsDelay(4000); //this will generate 4 second delay
                   }

void MsDelay(int x) //this function takes value to generate dealy
{
        int i;
        for(i=0;i<x;i++)
        {
           TH0=0xFC;  //this values generate 1 ms delay but we write this code
           TL0=0x18; //in for loop this mean if we entere 4000 it will gives 4 sec   
            TR0=1;  // of delay
                while(TF0==0);
                TR0=0;
                TF0=0;
        }
 }



Proteous interfacing of seven segment with 8051 controller



Thursday 9 October 2014

Basic Rules of VHDL coding for Beginner

:-Basic Rules of VHDL which should be in mind before start with This language

1-Its Hardware description language that means it’s not an only programming language it’s a language with the help of we can design a new hardware. Every single line of your code can affect hardware. we can design a new controller also and other digital logic using VHDL language.

2-you have a little knowledge how your hardware should look like because VHDL is a very powerful language you should have knowledge about basic digital circuits. Design a digital circuit is similar to other high level programming language but VHDL is complicated language it’s not like other programming language.

:-TOOL needed for VHDL

     Every engineer without its tool is like angel without her magical wand so here also to work with VHDL language you need some tool.Here I mention few basic tool which you need during your digital design.

:-SOFTWARE

XILINX ISE –This is IDE(integrated development Enviroment) where you write                    your VHDL codes its comes with inbuilt simulation tool names ISIM which is use to see output.

Modelsim student PE- This is a product of mentor graphics you can download a license student version its use for simulation purpose.

:-Hardware

FPGA Board –field programmable gate array this is hardware in which we will test our design.


CPLD  Board- Complex programmable logic device this is also we can use for same purpose.

C program which return power of integer Value using a function (base to the power)

   C program which return power of integer Value using a function (base power)

Question-> Write a integer power function which return the power of base

      This program return the value of any integer power the integer value will entered by user for example 52 = 25,5= 125. Here I used a function which both value base and exponent.function name is integer_power you can redefine this function it takes two integer type variable.This program is only for integer values.

#include<stdio.h>

int integer_power(int x,int y) ; //prototype of function

int main()
{
  int base,exponent ;
  int final_answer ;  //variable      
  printf("-------Enter the value of base and exponent---------\n") ;
  printf("Enter value of base-") ;
  scanf ( "%d" , &base) ; //fetch base value from user
  printf( "Enter value of exponent-" ) ;
  scanf( "%d" , &exponent) ; //fetch exponent value from user
  final_answer = integer_power(base,exponent) ;
  printf( "\nyour final answer is %d" ,final_answer) ;
}

int integer_power(int x , int y) //here my function which return final value
{
        int z;
        int total=1;
        for(z=1 ; z<=y ; z++)
         {
                total = x*total ; //return final value
         }
        return total ;


C program to Send 0-255 Character to port P0 in 8051 Controller

#include<reg51.h> //header file used in 8051 controller                
                             // programming
void main()
{
  Unsigned char x  ;
 For (x=0 ; x <= 255 ; x++)
          {
      P1 = x ;
          }


} //End of main

Compiler for C,C++ and Python {paste your programme to see the output}