Project1:- Servo motor control Using PIC Microcontroller
Hardware Design:-
Program:-
void Rotation0() //0 Degree
{
unsigned int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
Delay_us(800); // pulse of 800us
PORTB.F0 = 0;
Delay_us(19200);
}
}
void Rotation90() //90 Degree
{
unsigned int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
Delay_us(1500); // pulse of 1500us
PORTB.F0 = 0;
Delay_us(18500);
}
}
void Rotation180() //180 Degree
{
unsigned int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
Delay_us(2200); // pulse of 2200us
PORTB.F0 = 0;
Delay_us(17800);
}
}
void main()
{
TRISB = 0; // PORTB as Ouput Port
do
{
Rotation0(); //0 Degree
Delay_ms(1000);
Rotation90(); //90 Degree
Delay_ms(1000);
Rotation180(); //180 Degree
}
while(1);
}
Project2:- Ultrasonic Interface with Microcontroller
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
int a;
//Interrupt function will be automatically executed on Interrupt
void interrupt()
{
if(INTCON.RBIF == 1) //Makes sure that it is PORTB On-Change Interrupt
{
INTCON.RBIE = 0; //Disable On-Change Interrupt
if(PORTB.F4 == 1) //If ECHO is HIGH
T1CON.F0 = 1; //Start Timer
if(PORTB.F4 == 0) //If ECHO is LOW
{
T1CON.F0 = 0; //Stop Timer
a = (TMR1L | (TMR1H<<8))/58.82; //Calculate Distance
}
}
INTCON.RBIF = 0; //Clear PORTB On-Change Interrupt flag
INTCON.RBIE = 1; //Enable PORTB On-Change Interrupt
}
void main()
{
char txt[7];
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
TRISB = 0b00010000;
INTCON.GIE = 1; //Global Interrupt Enable
INTCON.RBIF = 0; //Clear PORTB On-Change Interrupt Flag
INTCON.RBIE = 1; //Enable PORTB On-Change Interrupt
Lcd_Out(1,3,"Developed By");
Lcd_Out(2,4,"FaboTronix");
Delay_ms(3000);
Lcd_Cmd(_LCD_CLEAR);
T1CON = 0x10; //Initializing Timer Module
while(1)
{
TMR1H = 0; //Setting Initial Value of Timer
TMR1L = 0; //Setting Initial Value of Timer
a = 0;
PORTB.F0 = 1; //TRIGGER HIGH
Delay_us(10); //10uS Delay
PORTB.F0 = 0; //TRIGGER LOW
Delay_ms(100); //Waiting for ECHO
a = a + 1; //Error Correction Constant
if(a>2 && a<400) //Check whether the result is valid or not
{
IntToStr(a,txt);
Ltrim(txt);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"DISTANCE = ");
Lcd_Out(1,12,txt);
Lcd_Out(1,15,"CM");
Lcd_Out(2,1," FaboTronix.com");
}
else
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"OUT OF RANGE");
Lcd_Out(2,1," FaboTronix.com");
}
Delay_ms(400);
}
}
Project3:- LCD Display
Hardware Design:
Program:
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
void main() {
Lcd_Init(); // Initialize LCD
while (1)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1," Welcome to ");
Lcd_Out(2,1," FaboTronix");
delay_ms(3000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"7 Protapdash Lan");
Lcd_Out(2,1,"Shingtola,Dhaka");
delay_ms(3000);
}