Interfacing Programs

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

List of practicals (write only the experiments given in the list)

1. Arithmetic, logical & code conversion problems using assembly/C


programming (this experiment includes: addition of array elements,
decimal to hex conversion, hex to decimal conversion)
2. Traffic light controller using 8051 microcontroller
3. Interfacing LCD to 8051Microcontroller
4. Waveform generation using DAC Interface to 8051Microcontroller (this
experiment includes: square wave generator)

Square wave generation:


Algo
1. Send data from acc to port 2 as FFH
2. Get delay
3. Compliment the data in acc
4. Get delay
5. Send data from acc to port 2
6. Goto step 3

#include <8051.h>
#include <stdio.h>
Void main()
{
Unsigned char a ;
A=0xFF;
While (1)
{
P2=a; send the data to port2
Delay(100);
A=~a
}
}

Triangular wave generation:


Algo
1. Send data from acc to port 2 as 00H
2. Get very small Delay
3. Inc acc
4. Check for acc contains are FFh
5. Goto step 2
6. If acc is FFh
7. Get very small Delay
8. Dec acc
9. Repeat till acc is 00h
10. If acc is 00h
11. Goto step 2

#include <8051.h>
#include <stdio.h>
Void main()
{
Unsigned char a ;
While (1)
{
For ( a=0;a<0xFF;a++)
{
P2 = a;
Delay(4)
}
For (a=0xFF; a<0;a--)
{
P2 = a;
Delay(4)
}
}
}

Interfacing A/D convertor


Algo
1. apply the analog signal to one of the channel.
2. Give the address of channel on CBA address lines.
3. Activate ALE signal to latch the analog signal on the channel by latching
address on CBA address lines.
4. Activate Start conversion signal
5. Continuously check for status of EOC signal, if EOC signal is activated
NO check for EOC
YES data conversion is complete read it from the 8 output lines.
6. Goto step 1

#include <8051.h>
#Include <stdio.h>
BIT AD_OE P3.6
BIT AD_SC P3.5
BIT AD_EOC P3.3
BIT AD_ALE P3.4
Bit ad0 P3.0; channel selection bits (address of channel)
Bit ad1 P3.1
Bit ad2 P3.2
Bit ad3 P1.0
Bit ad4 P1.1
Void main ()
{
P2 = 0XFF;
P3 = 0X08;
AD_ALE = 0;
AD0=0; ADDRESS TO SELECT CHANNEL IN0
AD1=0;
AD2=0;
AD_ALE = 1;
WHILE(1)
{
AD_OE=1;
AD_SC=0;
DELAY(100);
AD_SC=1;
DELAY(100);
AD_SC=0;
}
P2= A;
}

Interfacing LCD
Algo:
1. Initialise LCD
2. Send command code to LCD
3. Send data to LCD
4. Stop

#include <8051.h>
#include <stdio.h>
Bit reg_sel P2.3
Bit read_write P2.4
Bit enable P2.5
Void data_write();
Void cmd_write();
Void main()
{
Temp= 0x38;
Cmd_write();
Temp= 0x0C;
Cmd_write();
Temp= 0x01;
Cmd_write();
Temp= 0x06;
Cmd_write();
Temp= 0x80;
Cmd_write();
P0=0x0f;
Data_write();
}
Void cmd_write()
{
Reg_sel = 0;
Read_write = 0;
Enable = 1;
Enable = 0;
}
Void data_write()
{
Reg_sel = 1;
Read_write = 0;
Enable = 1;
Enable = 0;
}

Stepper motor

Code in sequence to be given to stepper motor is 3, 9, C, 6


0011, 1001, 1100, 0110

#include <8051.h>
#include <stdio.h>
# define phasea 0x03; data for stepper motor excitation
# define phaseb 0x09
# define phasec 0x0C
# define phased 0x06
Void main()
{
While(1)
{
P2 = phasea;
Delay(50);
P2 = phaseb;
Delay(50);
P2 = phasec;
Delay(50);
P2 = phased;
Delay(50);
}
}
Traffic light controller
Algo
1. Allow traffic on the road from north.
2. Allow traffic on the road from east.
3. Allow traffic on the road from south.
4. Allow traffic on the road from west.
5. Goto step 1

#include<reg51.h>
Void main()
{
Long int I;
For(i=0;i<=500;i++)
{
While(1)
{
//north
P1=0xd0;
P3=0x81;
Delay(50);
P1=0x84;
Delay(20);

//east
P1=0x0b;
P3=0x81;
Delay(50);
P1=0x21;
Delay(20);

//south
P1=0x81;
P3=0x0b;
Delay(50);
P1=0x21;
Delay();

//west
P1=0x81;
P3=0xd0;
Delay(50);
P1=0x84;
Delay();
}
}

You might also like