Professional Documents
Culture Documents
American University of Science & Technology: Department of Mechatronics Engineering
American University of Science & Technology: Department of Mechatronics Engineering
Report # 4
Prepared by
Mahmoud al abed
Presented to
Dr. Mohamad
Contents
Abstract............................................................................................................................................3
Ultrasonic with LCD and 6 LEDs...................................................................................................3
Seven segments................................................................................................................................6
Seven segment with a decoder.........................................................................................................8
Abstract
This report will talk about the ultrasonic sensor with the lcd module and 6 LEDs for the binary
representation. Pic with the seven segment display and the seven segment display with the 7448
decoder
#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
#include <xc.h>
#include "lcd.h"
#include <pic16f877a.h>
void main()
int a;
TRISB4 = 1;
TRISB0=0;
TRISC=0;
PORTC=0;
Lcd_Init();
Lcd_Set_Cursor(1,1);
Lcd_Write_String("Booting");
Lcd_Set_Cursor(2,1);
Lcd_Write_String("Up");
__delay_ms(500);
Lcd_Clear();
while(1)
TMR1ON = 1;
Lcd_Clear();
Lcd_Set_Cursor(1,1);
if(a>=2 && a<=20)
Lcd_Write_String("Too Close!");
PORTC=0b00111111;
Lcd_Write_String("Close");
PORTC=0b00001111;
if(a>81)
Lcd_Write_String("Safe Distance");
PORTC=0b00000011;
else
Lcd_Clear();
Lcd_Set_Cursor(1,1);
Lcd_Write_String("Out of Range");
__delay_ms(1000);
}
}
Seven segments
#include <stdio.h>
#include <stdlib.h>
#include <pic16f877a.h>
#include <xc.h>
void main()
TRISD=0;
PORTD=0;
int
seg[]={0b0111111,0b0000110,0b1011011,0b1001111,0b1100110,0b1101101,0b1111100,0b00
00111,0b1111111,0b1101111};
//seg[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7C,0x07,0x7F,0x6F}
while(1)
for(int i=0;i<10;i++)
PORTD=seg[i];
__delay_ms(1000);
}
}