es doc

7
  Embedded System Practical Steps to be followed: 1. Create New Project 2. Select or create the directory/folder for new project 3. Save the project in the directory 4. Select the Microcontroller 5. Create file for typing source code 6. Type the source code 7. Save the file with “.c” extension 8. Add the newly created “.c” file to source group1 9. Run the Build Process 10. Click Debug 11. Select peripherals 12. Run the program List of Practical: 1. Display pattern on LED 2. Control timer control register of 8051 3. Simulate binary counter on LEDs 4. Serial I/O 5. DAC : Generate Square wave frequency 6. DAC : Generate Triangular wave frequency 7. DAC : Generate Sine wave frequency

Upload: monu

Post on 05-Oct-2015

218 views

Category:

Documents


0 download

DESCRIPTION

pratical

TRANSCRIPT

  • Embedded System Practical

    Steps to be followed:

    1. Create New Project

    2. Select or create the directory/folder for new project

    3. Save the project in the directory

    4. Select the Microcontroller

    5. Create file for typing source code

    6. Type the source code

    7. Save the file with .c extension

    8. Add the newly created .c file to source group1

    9. Run the Build Process

    10. Click Debug

    11. Select peripherals

    12. Run the program

    List of Practical:

    1. Display pattern on LED

    2. Control timer control register of 8051

    3. Simulate binary counter on LEDs

    4. Serial I/O

    5. DAC : Generate Square wave frequency

    6. DAC : Generate Triangular wave frequency

    7. DAC : Generate Sine wave frequency

  • PRACTICAL 1 & 2

    #include //Header file for 8051 microcontroller

    void T0Delay(void); //function prototype declaration

    void main(void) // main function

    {

    while(1) //repeat forever

    {

    P1=0xFF; //make high all bits of port 1

    T0Delay(); // call delay routine

    P1=0x00; // make low all bits of port 1

    T0Delay(); // call delay routine

    }

    } //End of main

    void T0Delay() //delay function

    {

    TMOD=0x01; // use timer 0 , mode 1

    //Load value "FC" in timer 0 lower byte & //load

    value "65" in timer 0 higher //byte for 1 second

    delay

    TL0=0xFC; // load TL0

    TH0=0x65; //load TH0

    TR0=1; // turn on Timer 0

    while(TF0==0); //wait for TF0(timer 0 overflow flag) to roll

    over(overflow)

    TR0=0; //turn off timer 0 run control bit

    TF0=0; // clear timer 0 overflow flag bit.

    }

  • PRACTICAL 3

    #include

    void delay(int time); // delay() function prototype

    //this function generates

    //delay = (time x 1msec)

    // For example delay(500).

    // Generates delay of (500 x 1msec) = 500msec

    void main() // Start of main() function

    {

    P1 = 00000000; // Initialize Port 1 as Output Port

    while(1) // Infinite Loop

    {

    P1++; // Increment Port 1 (Binary Counter)

    delay(100); // Call delay() function.

    //Add some delay for output on

    //LED. To generate 1 sec delay pass value 1000.

    } // i.e. 1000 x 1msec = 1sec.

    } // End of Main() function

    void delay(int time) // Start of delay() function.

    //Delay() function generates delay of desired amount.

    {

    int i,j; // Initialize variale i,j for generating Delay

    for(i=0;i

  • PRACTICAL 4

    #include

    void send(char x); // Prototype of send() function. To transmit any character

    from 8051 to PC, call

    //send() function. For example, to send character 'A' we

    use, send('A').

    void main(void) // Start of main() function

    {

    TMOD = 0x20; // 0x20 is stored in TMOD register to set Timer1 in 8-Bit

    Auto-Reload Mode

    TH1 = 0xFD; // TH1 register is loaded with value 0xFD to generate baud

    rate of 9600

    SCON = 0x50; // 0x50 is loaded into SCON register to configure Timer1 in

    Mode1,8-bit data,1 start-bit,1 stop-bit

    TR1 = 1; // When TR = 1, Timer1 starts functioning or running.

    TImer1 has been started

    send('Y'); // Call send() function to transmit character 'Y' from 8051

    to PC

    send('E'); // Call send() function to transmit character 'E' from 8051

    to PC

    send('S'); // Call send() function to transmit character 'S' from 8051

    to PC

    send('\r');

    while(1); // After send 'YES' do nothing

    } // End of main() function

    void send(char x) // Send() function transmits the character passed to it

    {

    SBUF = x; // the character passed ('x') is loaded in SBUF register.

    After it is loaded the serial

    //trasnmision starts automatically. After trasmission is

    finished TI flag is set to 1.

    while(TI==0); // Wait till transmission is finised i.e. wait until TI =

    1

    TI=0; // When TI=1 the program gets out of the while loop and TI

    flag is again cleared (TI=0)

    }

  • PRACTICAL NO 5

    /*********************************************************************************

    This program generates a square wave of 2kHz when Port1 in interfaced with DAC

    ***********************************************************************************/

    #include

    void delay(int time); // delay() function prototype, this function

    generates delay = (time x 1msec)

    // For example delay(500). Generates delay of (500 x

    1msec) = 500msec

    void main() // Start of main() function

    {

    P1 = 0x00; // Initialize Port 1 as Output Port

    while(1) // Infinite Loop

    {

    P1 = 0xFF; // Send maximum value to Port1 for getting High

    Period of Square Wave

    delay(1); // Call delay() to get 1msec of duty cycle for High

    Period

    // Delay calculated as 1 x 1msec = 1msec

    P1 = 0x00; // Send maximum value to Port1 for getting Low Period

    of Square Wave

    delay(1); // Call delay() to get 1msec of duty cycle for Low

    Period

    }

    }

    void delay(int time) // Start of delay() function. Delay() function

    generates delay of desired amount.

    {

    int i,j; // Initialize variable i,j for generating Delay

    for(i=0;i

  • PRACTICAL NO 6

    /*************************************************************************************

    This program generates a triangular wave of 2kHz when Port1 in interfaced with DAC

    **************************************************************************************/

    #include

    void main() // Start of main() function

    {

    P1 = 0x00; // Initialize Port 1 as Output Port

    while(1) // Infinite Loop

    {

    do

    {

    P1 += 0x05;

    }

    while(P10x00);

    }

    }

  • PRACTICAL NO 7

    #include

    #include

    void main() // Start of main() function

    {

    int WAVEVALUE[12] = { 128,192,238,255,238,192,128,64,17,0,17,64};

    // Create a look-up table (array) named

    WAVEVALUE to send appropriate

    values to DAC so that a sine-wave is

    generated. Refer to table

    int i; // variable i used in for loop

    while(1) // Infinite loop. The program will run

    forever

    {

    for(i=0;i