Monday, April 30, 2018

LED Flashing with PIC16F877



Hello, today I will do very simple project using PIC16F877. This is a basic project for begginer.
PIC16F877 is a very popular microcontroller. Those who are new with PIC micro controller, this project will demonstrate that how to make a specific pin of a port make high or low. PIC16f877 micro controller has 5 port. These are PORT A, PORTB, PORTC, PORTD and PORTE. Each port has some specific purpose. May be in other post we will discuss about this. To do this we need following software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2



MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language.

Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F887  IC.



To do this project we need following components;


   1. PIC16F877

   2. LED
   3. 16 MHz Crystal Oscillator
   4. Breadboard
   5. Wires
   6. 5V DC Power source

In the following figure we have the pinout of PIC16F877



Figure 1

MikroC Code:


// LED Flashing

void main() 

{
   TRISB = 0;
   PORTB = 0;
   ADCON1= 0x06;
   
   while(1)
   {
   
      PORTB = 0b00000001;
      delay_ms(200);
      
      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b00000010;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b00000100;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b00001000;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b00010000;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b00100000;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b01000000;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b10000000;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b10101010;
      delay_ms(1000);

      PORTB = 0b00000000;
      delay_ms(500);
      
      PORTB = 0b01010101;
      delay_ms(1000);

      PORTB = 0b00000000;
      delay_ms(500);
      
      PORTB = 0b11111111;
      delay_ms(1000);

      PORTB = 0b00000000;
      delay_ms(500);
   
   }
}

Diagram




Figure 2

Please don't forget to connect pin 1,11 and 32 to 5V source.
Connect pin 12 and 31 with Gnd. Also connect 16 MHz oscillator with pin 13 and 14.

THANKS A LOT.

Interfacing 16*2 LCD with PIC16f877



Today I will interface 16*2 LCD with PIC16F877. This is a very popular microcontroller. In this tutorial we will use the following Software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2

MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language.
Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F877  IC.

 16*2 LCD has 16 columns and 2 rows. To do this project we need following components: 

  1. PIC16F877
  2. 16*2 LCD
  3. 5V power source
  4. 16 MHz Crystal Oscillator
  5. Male header (to solder with LCD)
  6. 10K potentiometer (To control the brightness of the LCD)
  7. Breadboard
  8. Wires

LCD has 16 pins. We can transfer the data from microcontroller to LCD in 8 bits mode or in 4 bit modes. In this project we will transfer the data in 4 bit modes. In below I have given the pin out of 16*2 LCD.

  Pin 1  : GND
  Pin 2  : VCC
  Pin 3  : VEE
  Pin 4  : RS
  Pin 5  : R/W
  Pin 6  : EN
  Pin 7  : DB0
  Pin 8  : DB1
  Pin 9  : DB2 
  Pin 10: DB3
  Pin 11: DB4
  Pin 12: DB5
  Pin 13: DB6
  Pin 14: DB7
  Pin 15: Led +
  Pin 16: Led -


Figure 1

MikroC has some built in library to print the string in the LCD. In this code part we will demonstrate how to print something on the LCD. Following code will demonstrate how to print something on the LCD.

/*
Project Name: Showing name on LCD using PIC16F877
*/
// LCD connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;


sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// End LCD connections


void main()
{
   Lcd_Init();                            // Initialize LCD
   Lcd_Cmd(_LCD_CLEAR);                   // Clear display
   Lcd_Cmd(_LCD_CURSOR_OFF);              // Cursor off
   Lcd_Out(1,1,"  Hello WORLD   ");
   Lcd_Out(2,1," ARTECH-AHAMOD  ");
}


I have written another code which will scroll the lcd from left to right and again scroll from right to left. The code is given below:


/* 
Project Name: Showing name on LCD using PIC16F877
*/
// LCD connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;


sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// End LCD connections

 unsigned int i;

void main()
{
   Lcd_Init();                            // Initialize LCD
   Lcd_Cmd(_LCD_CLEAR);                   // Clear display
   Lcd_Cmd(_LCD_CURSOR_OFF);              // Cursor off
   Lcd_Out(1,1,"  Hello WORLD   ");
   Lcd_Out(2,1," ARTECH-AHAMOD  ");
   delay_ms(3000);
   
   while(1) 
   {                                      // Endless loop
    for(i=0; i<8; i++) 
    {                                     // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      delay_ms(500);
    }

    for(i=0; i<8; i++) 
    {                                     // Move text to the right 7 times
      Lcd_Cmd(_LCD_SHIFT_RIGHT);
      delay_ms(500);
    }
    
    delay_ms(2000);
  }
}


Circuit diagram is given below:


Figure 2



Figure 3

Please don't forget to connect pin 1,11 and 32 to 5V source.
Connect pin 12 and 31 with Gnd. Also connect 16 MHz oscillator with pin 13 and 14.

Pin 15 and pin 16 are backlight power of the LCD. Connect pin 15 with 5V and connect pin 16 with Gnd.
THANKS A LOT.

Friday, April 27, 2018

LM35 Temperature Sensor with PIC16F887



Today I will interface LM35 Temperature sensor with PIC16F887. It is a very basic and simple project. In this tutorial we will use the following Software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2

MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language.
Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F887  IC.

To do this project we need following components;

   1. PIC16F887
   2. LCD 20*4
   3. 16 MHz Crystal Oscillator
   4. LM35 Temperature Sensor
   5. Breadboard
   6. Wires
   7. 5V DC Power source
   8. male header (to solder with LCD)


Little bit about LM35


LM35 is a precision IC temperature sensor with its output proportional to the temperature (in oC). The sensor circuitry is sealed and therefore it is not subjected to oxidation and other processes. With LM35, temperature can be measured more accurately than with a thermistor. It also possess low self heating and does not cause more than 0.1 oC temperature rise in still air.   
The operating temperature range is from -55°C to 150°C. The output voltage varies by 10mV in response to every oC rise/fall in ambient temperature, i.e., its scale factor is 0.01V/ oC.


Figure 1




MikroC Code:

// LCD module connections
sbit LCD_RS at RC6_bit;
sbit LCD_EN at RC7_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 TRISC6_bit;
sbit LCD_EN_Direction at TRISC7_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 t;
char b;
char lcd[] = "000 Degree";

void main()
{
  ADCON1 = 0x04;
  Lcd_Init();
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_out(1,1, "PIC Microcontroller ");
  delay_ms(500);
  Lcd_out(2,1, " Temperature Sensor ");
  delay_ms(500);
  Lcd_out(3,1, "   Using LM35 and   ");
  delay_ms(500);
  LCD_out(4,1, "     PIC16F887      ");
  delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);
  delay_ms(200);

  do
  {
    Lcd_out(1,1,"     AHAMOD IBNE    ");
    Lcd_out(2,1,"      ABDUR ROUF    ");
    Lcd_out(3,1, "Temperature:   ");
    t = ADC_Read(0);

    t = t * 0.4887;
    b = t%10;
    lcd[2] = b + '0';

    t = t/10;
    b = t%10;
    lcd[1] = b + '0';

    t = t/10;
    b = t%10;
    lcd[0] = b + '0';

    Lcd_out(4,1,lcd);
    Delay_ms(200);
  }while(1);

}


Circuit Diagram:



Figure 2



Figure 3



Please don't forget to connect pin 1,11 and 32 to 5V source.
Connect pin 12 and 31 with Gnd. Also connect 16 MHz oscillator with pin 13 and 14.

For LCD we are using 4 bit data transfer mode. Connect the LCD according to the diagram. Pin 15 and pin 16 are backlight power of the LCD. Connect pin 15 with 5V and connect pin 16 with Gnd.

THANKS A LOT.


Line Follower Robot using Arduino

This project was a part of Line Follower Robot Competition