Arduino Projects    |   Raspberry Pi  |     Electronic Circuits   |   Electronics Reference Design Library  |   AVR    |    PIC    |    8051    |    Electronic Projects

Keil interfacing programs for 8051

Written By: 
A. M. Bhatt


DAC interfacing:

Hardware:-a 8 bit DAC is connected to P2. Its two control signals WR and CS are tied to ground. Here I am writing a program to generate three different types of waveforms square, triangular and staircase type. To select desire waveform three push buttons are connected at P3.0 to P3.2.

#include<reg51.h>

 

void delay1();                                                   //key debounce delay

void delay2();                                                   // delay for frequency

void sqrarwave();                                             // function to generate square wave

void triwave();                                                  // function to generate triangular wave

void stairwave();                                               // function to generate staircase wave

 

void delay1()                                                    // approx. 100 ms delay

  {

            int a,b;

            for(a=0;a<100;a++)

                        for(b=0;b<1000;b++);

  }

void delay2()                                                    // approx 1 ms delay

  {

            int c;

            for(c=0;c<1000;c++);

  }

void squarwave()

  {

            while(P3==0xFF)                                 // till any button is not pressed

              {

                        P2=0xFF;                                // first send all high to P2

                        Delay2();

                        P2=0x00;                                 // then send all low to P2

                        Delay2();

              }

  }

void triwave()

  {

            unsigned char d;

            while(P3==0xFF)

              {

                        for(d=0x00;d<0xFF;d++)        // send values 00 to FF

                          {

                                    P2=d;                           // one by one for positive ramp             

                          }

                        for(d=0xFF;d<0x00;d--)          // send values FF to 00

                          {

                                    P2=d;                           // one by one for negative ramp

                          }

              }

void stairwave()

  {

            while(P3==0xFF)

              {

P2=0x00;                                 // step by step increment

                        Delay2();

                        P2=0x20;                                 // values sent to P2

                        Delay2();

                        P2=0x40;

                        Delay2();

                        P2=0x80;

                        Delay2();

              }

  }

 

void main()

  {

            P2=0x00;                                 // P2 as output port

            P3=0xFF;                                // P3 as input port

            While(P3=0xFF);                     // wait till any button is pressed

            Switch(P3)

              {

                        case 0xFE:                   // for first button

                                    delay1();           // key debounce delay

                                    P3=0xFF;        // send all 1’s again to P3

                                    squarwave();    // generate square wave

                                    break;

                        case 0xFD:

                                    delay1();

                                    P3=0xFF;

                                    triwave();

                                    break;

                        case 0xFB:

                                    delay1();

                                    P3=0xFF;

                                    stairwave();

                                    break;

              }

  }     

 

 

APPLICATIONS & TECHNOLOGIES

Learn about the latest applications and industry trends with tutorials and white paper design resources on vertical markets.

Automotive
Energy Harvesting
MEMS Technology
OpenSource Hardware
RFID & NFC
RF Wireless
Sensor
Solar
Touch
Wireless Charging

 

You are here