You are on page 1of 2

Lab No 7 Embedded System Design Lab

LAB NO 7
Task 1: Task 1: Write an Embedded C Program for PIC16F877A
microcontroller to control the direction of a motor using L293D .
 Use toggle switch to control the direction of motor.
 Provide 2 second delay while changing the direction of the motor.
 Motor forward/reverse string should be displayed on LCD .

Code :
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D4 at RC2_bit;
sbit LCD_D5 at RC3_bit;
sbit LCD_D6 at RC4_bit;
sbit LCD_D7 at RC5_bit;
sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D4_Direction at TRISC2_bit;
sbit LCD_D5_Direction at TRISC3_bit;
sbit LCD_D6_Direction at TRISC4_bit;
sbit LCD_D7_Direction at TRISC5_bit;
void main()
{
TRISD.F0=1;
TRISB.F0=0;
TRISB.F1=0;
TRISB.F2=0;
PORTB.F2=1;
PORTB.F1=0;
PORTB.F0=0;
TRISC=0;
PORTC=0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
while(1){
if(PORTD.F0==1){
Delay_ms(2000);
PORTB.F0=1;
PORTB.F1=0;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Motor Forward.");
}
else if(PORTD.F0 ==0)
{
Delay_ms(2000);
PORTB.F0=0;

ZUBAIR YOUSUF 1
Lab No 7 Embedded System Design Lab
PORTB.F1=1;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Motor Backward.");
}
}
}
Output :

ZUBAIR YOUSUF 2

You might also like