Tuesday 12 June 2012

EMBEDDED PROGRAMMING BASIC PROGRAMS




           EMBEDDED PROGRAMMING















                     SQUARE WAVE GENERATOR                    




AIM:
      To develop the source code for square wave generator using Keil µ vision and to implement it using Proteus tool.


THEORY:
      One requirement in a wide range of applications is a spontaneous source of some continuous signal, having a regular and definable wave shape. One of the most important of these is a square wave.
     The circuit to the right uses a comparator with both positive and negative feedback to control its output voltage. Because the negative feedback path uses a capacitor while the positive feedback path does not, however, there is a time delay before the comparator is triggered to change state. As a result, the circuit oscillates, or keeps changing state back and forth at a predictable rate.













SOURCE CODE:

#include<regx51.h>
sfr out1=0x90;
sfr out2=0xa0;
sfr out3=0xb0;
unsigned int i;

void main()
{
out1=out2=out3=0x00;
while(1)
  {
    out1=out2=out3=0xaa;
    for(i=0;i<25000;i++);
    out1=out2-out3=0x55;
    for(i=0;i<25000;i++);
  }
}




















RESULT:
 Thus the source code for square wave generator is written using Keil and implemented in Proteus and verified.   













                   BCD TO SEVEN SEGMENT DISPLAY



AIM:
      To develop the source code for BCD to seven segment display using Keil µ vision and to implement it using Proteus tool.

THEORY:
     A 7-segment display is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot-matrix displays. Seven-segment displays are widely used in digital clocks, electronic meters, and other electronic devices for displaying numerical information.
The seven segments are arranged as a rectangle of two vertical segments on each side with one horizontal segment on the top, middle, and bottom. The segments of a 7-segment display are referred to by the letters A to G, where the optional DP decimal point (an "eighth segment") is used for the display of non-integer numbers.


BCD I/P
SEGMENT O/P
DISPLAY
g f e d c b a
0   0   0   0
0 1 1 1 1 1 1
0
0   0   0   1
0 0 0 0 1 1 0
1
0   0   1   0
1 0 1 1 0 1 1
2
0   0   1   1
1 0 0 1 1 1 1
3
0   1   0   0
0 1 1 0 0 1 1
4
0   1   0   1
1 1 0 1 1 0 1
5
0   1   1   0
0 0 1 1 1 1 1
6
0   1   1   1
0 0 0 0 1 1 1
7
1   0   0   0
1 1 1 1 1 1 1
8
1   0   0   1
1 1 0 0 1 1 1
9











SOURCE CODE:

#include<regx51.h>
sfr out=0xA0; //P3
sfr inp=0x90; //P1
unsigned char temp;
unsigned char const lookup[10]=
           {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};

void main()
{
out=0x00;
inp=0xFF;
while(1)
  {
     temp=inp & 0x0F;
     if(temp>=0x0A)
          out=0x00;
     else
          out=~(lookup[temp]);
  }
}

















RESULT:
     Thus the source code for BCD to seven segment display is written using Keil and implemented in Proteus and verified.   











                 TWO SEVEN SEGMENT DISPLAY


AIM:
     To develop the source code for two seven segment display using Keil µ vision and to implement it using Proteus tool.

THEORY:
      There are two types of LED 7-segment displays: common cathode (CC) and common anode (CA). The difference between the two displays is the common cathode has all the cathodes of the 7-segments connected directly together and the common anode has all the anodes of the 7-segments connected together. Shown below is a common anode seven segment.

      As shown above all the anode segments are connected together. When working with a CA seven segment displays, power must be applied externally to the anode connection that is common to all the segments. Then by applying a ground to a particular segment connection (a-g), the appropriate segment will light up. An additional resistor must be added to the circuit to limit the amount of current flowing through each LED segment.
     A common cathode seven segment is different from a common anode segment in that the cathodes of all the LEDs are connected together. For the use of this seven segment the common cathode connection must be grounded and power must be applied to appropriate segment in order to illuminate that segment.

















SOURCE CODE:

#include<regx51.h>
sfr out1=0xa0;
sfr out2=0xb0;
#define max 36000
unsigned int i, temp=0x00;
unsigned char const lookup[10]=
                         {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
void main(void)
{
out1=0x00;
out2=0x00;
while(1)
{
    if(temp!=100)
       {
          out1=~(lookup[temp/10]); //MSB
          out2=~(lookup[temp%10]);          //LSB
          for(i=0;i<max;i++);
          temp++;
      }
  else
  temp=0x00;
}
}












RESULT:
    Thus the source code for two seven segment display is written using Keil and implemented in Proteus and verified.   
















                       3 PHASE USING TIMER


AIM:
     To develop the source code for 3 phase timer using Keil µ vision and to implement it using Proteus tool.

THEORY:
In electrical engineering, three-phase electric power systems have at least three conductors carrying voltage waveforms that are 2π⁄3 radians (120°, 1⁄3 of a cycle) offset in time. In this article angles will be measured in radians except where otherwise stated.

Let x be the instantaneous phase of a signal of frequency f at time t:


Using this, the waveforms for the three phases are,



where VP is the peak voltage and the voltages on L1, L2 and L3 are measured relative to the neutral.











REGISTER DESCRIPTION:

TMOD : Counter/Timer Mode Register

·         GATE : Permits INTx pin to enable/disable counter.
·         C/T    : Set for counter operation, reset for timer operation.
·         M1, M0 :
00 : Emulate 8048 counter/timer (13-bits).
01 :16-bit counter/timer.
10 : 8-bit auto-reload mode
11 :Timer 0  = two 8-bit timers.


TCON : Counter/Timer Control Register

·         TF1, TF0 : Overflow flags for Timer 1 and Timer 0.
·         TR1, TR0 : Run control bits for Timer 1 and Timer 0. Set to run, reset to hold.
·         IE1, IE0 : Edge flag for external interrupts 1 and 0. Set by interrupt edge, cleared when interrupt is processed.
·         IT1, IT0 : Type bit for external interrupts. Set for falling edge interrupts, reset for 0 level interrupts.

TL0/TH0 : Timer 0 Low byte & Timer 0 High byte. These two SFRs, taken together, represent timer 0. This increments for each clock cycle.












SOURCE CODE:
#include<regx51.h>
sbit r=0xA0;     //P2.0
sbit g=0xA1;    //P2.1
sbit b=0xA2;    //P2.2
void delay(void);

void main(void)
{
  r=g=b=0;

  while(1)
   {
     r=1;
    delay();

    r=0;g=1;
    delay();

    g=0;b=1;
    delay();
    b=0;
  }
}

void delay()
 {
   TMOD=0x01;
   TH0=0xE6;
   TL0=0x37;
   TR0=1;
   while(TF0==0);
   TF0=0;
}






RESULT:
    Thus the source code for clock using timer is written using Keil and implemented in Proteus and verified.   





CIRCUIT SCHEMATIC & OUTPUT:








                     REAL TIME CLOCK USING TIMER



AIM:
     To develop the source code for clock using timer using Keil µ vision and to implement it using Proteus tool.


THEORY:
     
A clock is an instrument used to indicate, keep, and co-ordinate time. The word clock is derived ultimately (via Dutch, Northern French, and Medieval Latin) from the Celtic words clagan and clocca meaning "bell". A silent instrument missing such a mechanism has traditionally been known as a timepiece. In general usage today a "clock" refers to any device for measuring and displaying the time. Watches and other timepieces that can be carried on one's person are often distinguished from clocks.
A real-time clock (RTC) is a computer clock (most often in the form of an integrated circuit) that keeps track of the current time. Although the term often refers to the devices in personal computers, servers and embedded systems, RTCs are present in almost any electronic device which needs to keep accurate time.

REGISTER DESCRIPTION:

IE : Interrupt Enable Register

·         EA      : Global interrupt enable.
·         ES      : Serial interrupt enable flag
·         ET1    : Timer 1 interrupt enable flag.
·         EX1    : External interrupt 1 (INT1) interrupt enable flag.
·         ET0    : Timer 0 interrupt enable flag.
·         EX0    : External interrupt 0 (INT0) interrupt enable flag.








SOURCE CODE:
#include<regx51.h>
sfr min1=0xB0;   //P3
sfr min10=0x90; //P1
sfr sec1=0xA0;   //P2
sfr sec10=0x80; //P0
unsigned int MIN,SEC,a=0x00;
code unsigned char const lut[]=
                    {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
void main(void)
 MIN=SEC=0;
 IE=0x82;
 TMOD=0x01;
 TR0=1;
 while(1)
  {
sec10=~(lut[SEC/10]);
sec1=~(lut[SEC%10]);
min10=~(lut[MIN/10]);
min1=~(lut[MIN%10]);
  }
}
void t0_isr(void) interrupt 1
{
 a++;
 if(a==15)
        {  a=0x00;
           SEC++;
        }
 if(SEC==60)
        { SEC=a=0x00;
          MIN++;
        }
 if(MIN==60)
        MIN=0x00;
}




RESULT:
    Thus the source code for clock using timer is written using Keil and implemented in Proteus and verified.   








                              FREQUENCY MULTIPLIER


AIM:
     To develop the source code for frequency multiplier using Keil µ vision and to implement it using Proteus tool.

THEORY:
      In electronics, a frequency multiplier is an electronic circuit that generates an output signal whose output frequency is a harmonic (multiple) of its input frequency. Frequency multipliers consist of a nonlinear circuit that distorts the input signal and consequently generates harmonics of the input signal. A subsequent band pass filter selects the desired harmonic frequency and removes the unwanted fundamental and other harmonics from the output.
    Frequency multipliers are often used in frequency synthesizers and communications circuits. It can be more economic to develop a lower frequency signal with lower power and less expensive devices, and then use a frequency multiplier chain to generate an output frequency in the microwave or millimeter wave range. Some modulation schemes, such as frequency modulation, survive the nonlinear distortion without ill effect (but schemes such as amplitude modulation do not).
   Frequency multiplication is also used in nonlinear optics. The nonlinear distortion in crystals can be used to generate harmonics of laser light.







SOURCE CODE:
#include<regx51.h>
sfr p1=0x90;
sbit in1=0x90;
sbit in2=0x91;
sbit in3=0x92;
sbit in4=0x93;
sbit out=0xa0;
unsigned int sum, f, t1;
void main(void)
{
t1=0x00;
IE=0x82;
TMOD=0x02;
TH0=TL0=0x00;
while(1)
    {
    f=0x01;
    if(in1==0)
        {
        f=f*2;
        }
  if(in2==0)







    {
       f=f*4;
     }
  if(in3==0)
     {
     f=f*6;
     }
  if(in4==0)
    {
    f=f*8;
    }
 if((p1&0x0f)==0x0f)
   {
   TR0=0;
    t1=0x01;
   }
 else if(t1!=f)
   {
   t1=f;
   sum=(255-(1000000/(f*2*1000)));
   TH0=TL0=sum;
   TR0=1;
    }



 



  }
}
void in(void) interrupt 1
{
out=~out;
}





RESULT:
    Thus the source code for frequency multiplier is written using Keil and implemented in Proteus and verified.   







                              FREQUENCY ADDER

AIM:
   To develop the source code for frequency adder using Keil µ vision and to implement it using Proteus tool.
THOERY:
  The frequency adder which has four inputs and one output. The frequency of the output wave is depends upon the input switches if first switch ON, only the frequency of the output wave is 2kHz.If the second switch ON, only the frequency of the output wave is 4kHz. If the both switches ON condition the frequency of the output wave is (2+4)6 kHz. Frequency adders  are often used in frequency synthesizers and communications circuits. It can be more economic to develop a lower frequency signal with lower power and less expensive devices, and then use a frequency adder chain to generate an output frequency in the microwave or millimeter wave range.










SOURCE CODE:
#include<regx51.h>
sfr p1=0x90;
sbit in1=0x90;
sbit in2=0x91;
sbit in3=0x92;
sbit in4=0x93;
sbit out=0xa0;
unsigned int sum, f, t1;
void main(void)
{
t1=0x00;
IE=0x82;
TMOD=0x02;
TH0=TL0=0x00;
while(1)
    {
    f=0x00;
    if(in1==0)
        {
        f=f+2;
        }
  if(in2==0)
       {





       f=f+4;
     }
  if(in3==0)
     {
     f=f+6;
     }
  if(in4==0)
    {
    f=f+8;
    }
 if((p1&0x0f)==0x0f)
   {
   TR0=0;
    t1=0x00;
   }
 else if(t1!=f)
   {
   t1=f;
   sum=(255-(1000000/(f*2*1000)));
   TH0=TL0=sum;
   TR0=1;
    }
  }
}





void in(void) interrupt 1
{
out=~out;
}














RESULT:
    Thus the source code for frequency adder is written using Keil and implemented in Proteus and verified.   











                          SERIAL TRANSMISSION




AIM:
  To develop the source code for serial transmission using Keil µ vision and to implement it using Proteus tool.
THEORY:
              In telecommunication and computer science, serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to parallel communication, where several bits are sent as a whole, on a link with several parallel channels. Serial communication is used for all long-haul communication and most computer networks, where the cost of cable and synchronization difficulties make parallel communication impractical. Serial computer buses are becoming more common even at shorter distances, as improved signal integrity and transmission speeds in newer serial technologies have begun to outweigh the parallel bus's advantage of simplicity (no need for serializer and deserializer, or SerDes) and to outstrip its disadvantages (clock skew, interconnect density).

     Serial transmission is the process of transmitting data, one bit at a time (one bit after the other). Contrast with "parallel transmission," which uses multiple lines to transmit several bits simultaneously (8, 16, 32, etc.). External communications networks use serial transmission.















SOURCE CODE:

#include<regx51.h>
unsigned char const *dat="HAVE A NICE DAY-GCT";
unsigned int i;
void main(void)
{
          SCON=0x40;
          TMOD=0x20;
          TH1=0xfd;
          TL1=0x00;
          TR1=1;
while(1)
  {
while(*dat)
    {
          SBUF=*dat;
          TI=0;
          while(TI==0);
          for(i=0;i<=32000;i++);
          dat++;
    }
  }
}






RESULT:
       Thus the source code for serial transmission was written using Keil and implemented in Proteus and verified.   




CIRCUIT SCHEMATIC & OUTPUT:








              SERIAL TRANSMISSION & RECEPTION



AIM:
    
          To develop the source code for serial transmission and reception  using Keil µ vision and to implement it using Proteus tool.

THEORY:
           Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to parallel communication, where several bits are sent as a whole, on a link with several parallel channels. Serial communication is used for all long-haul communication and most computer networks, where the cost of cable and synchronization difficulties make parallel communication impractical.
        Serial reception is the process of receiving data, one bit at a time (one bit after the other). Contrast with "parallel reception," which uses multiple lines to receive several bits simultaneously (8, 16, 32, etc.). External communications networks use serial transmission and reception.






SOURCE CODE:

#include<regx51.h>
unsigned int i,temp;
void main(void)
{
          SCON=0x50;
          TMOD=0x20;
          TH1=0xFD;
          TL1=0x00;
          TR1=1;
while(1)
  {

    while(RI==0);
          RI=0;
          temp=SBUF;
          for(i=0;i<=10000;i++);
          TI=0;
          SBUF=temp;
          while(TI==0);
          for(i=0;i<=20000;i++);
   
  }
}






RESULT:

Thus the source code  serial transmission and reception  is written using Keil and implemented in Proteus and verified.   










                     LCD AUTO DISPLAY



AIM:
      
            To develop the source code for LCD auto display  using Keil µ vision and to implement it using Proteus tool.

THEORY:

      LCD is a very commonly used output device to display alphanumeric characters. The LCD displays the character corresponding to the data received on its input data port i.e., it treats the data as the ASCII value of the character to be displayed. So if the value 65 is given to its data port the character “A” will be displayed and if the value 49 is given to the LCD the numeric digit “1” will be displayed. At many instances it is required to display a number like 123 on LCD. Displaying this number is tricky. If the data port of the LCD is loaded with the number 123, then the character corresponding to it will be displayed        
       LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. This LCD has two registers, namely, Command and Data.
The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.






SOURCE CODE:

#include<regx51.h>
sfr out=0x90;
sbit rs=0xa0;
sbit rw=0xa1;
sbit e=0xa2;
sbit in=0xa3;
sbit out1=0xa4;
sbit out2=0xa5;
sbit out3=0xa6;
sbit out4=0xa7;
void lcd_init();
void lcd_command(unsigned char);
void lcd_data(unsigned char const *dat);
void delay(unsigned int);

void main(void)
{
   out=0x00;
   rs=rw=e=out1=out2=out3=out4=0;
   in=0;
   lcd_init();
   while(in==0)
   {
          out1=out2=1;
          out3=out4=0;
          lcd_command(0x80);
          lcd_data("WELCOME");
          lcd_command(0xC2);
          lcd_data("by VLSI-GCT");
   }
   while(in==1)
   {
          out1=out2=0;



out3=out4=1;
          lcd_command(0x80);
          lcd_data("Good Morning");
          lcd_command(0xC2);
          lcd_data("  Alarm ON   ");
   }
}
void lcd_init()
 {
   lcd_command(0x38);
   delay(200);
   lcd_command(0x06);
   delay(200);
   lcd_command(0x0c);
   delay(200);
   lcd_command(0x01);
   delay(200);
 }
void lcd_command(unsigned char a)
  {
          out=a;
          rs=0;
          e=1;
          delay(1000);
          e=0;
  }
void lcd_data(unsigned char const *dat)
{
while(*dat)
  {
    out=(*dat);
    rs=1;
    e=1;
    delay(1000);
    e=0;


 dat++;
  }
}
void delay(unsigned int x)
{
while(x--);
}













  


RESULT:

 Thus the source code for LCD auto display is written using Keil and implemented in Proteus and verified.   

1 comments:

  1. hi dude here some of the websites helps to improve the knowledge in 8051..

    http://nptel.iitm.ac.in/courses/Webcourse-contents/IIT-KANPUR/microcontrollers/micro/ui/Course_home2_9.htm

    and

    www.8051.com

    ReplyDelete

Search Here...