Monday, November 7, 2011

LCD display using PIC

Many device sometime using LED to display the output that had been process by micro-controller etc. LCD display quite famous output display for project that need to display some valid data or represent something for user reference. There is so many type of LCD today. Below is example of LCD type:
128x64



16x2

320x240 QVGA

  



16x1














There are so much brand in market. The famous one brand among students in university is Hitachi 16x2 Alphanumeric LCD module (refer specification). It can show display 16 bit output with 2 row which is equal to 32 bit in real time. We cannot just connect LCD to micro-controller because every each pin have the reserved function based on data sheet. Below is example pin configuration for 16x2 LCD module:
   
Pin
Symbol
Description
1
VSS
Ground
2
VDD
+5V Power Supply
3
VEE
Contrast Adjustment
4
RS
0: Command Register
1: Data register
5
RW
0: Write
1:Read
6
E
Enable
7-14
D0-D8
Data bus
15
LED+
Backlight Positive Power Supply
16
LED-
Backlight Ground
 Table 1: Pin configuration

For circuit connection LCD to micro-controller has shown below: 
 
Figure : LCD module connection

 As we can see, VSS is going for ground, VDD to +5V and VEE to contrast adjustment. Here we using variable resistor, so we can adjust how much brightness that we want. Other pin is refer to coding that we want to program. Some person say that pin D0-D7 should connect to port D on micro-controller, but exactly we can put it on port where we want. All this depends on our programming, whether we declare the variable at port C, port D or else.  

Ok, lets move on to the programming method. Now is the part that need to understand carefully. Here the step before start the programming:
  1. Determine which port your want to use to connect with pin D0-D7 and RS, RW and E on LCD module. 
  2.  Connect circuit like picture above (except port that you have determine in step 1).
  3. Turn on power and see whether the LCD is function or not. 
  4. If ok, go to step programming.
  5. Open MPLAB, and write programming.
Now we will do some programming for send text on LCD display. It quite tricky actually if you don't know the basic.

LCD Progamming

To program the LCD with micro-controller is little bit tricky. You must need to read the datasheet and must know your compiler. Different compiler different style. Here i'm using C18 compiler since my previous project is using PIC18F family. Below show the simple programming for LCD with PIC:


/*Header******************************************************/

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

unsigned char ch;                    //
unsigned int adc_rd;                 // Declare variables
char *text;                          //
long tlong;                          //

void main() {
    INTCON = 0;                      // All interrupts disabled
    ANSEL = 0x04;                    // Pin RA2 is configured as an analog input
    TRISA = 0x04;
    ANSELH = 0;                      // Rest of pins are configured as digital
   
    Lcd_Init();                      // LCD display initialization
    Lcd_Cmd(_LCD_CURSOR_OFF);        // LCD command (cursor off)
    Lcd_Cmd(_LCD_CLEAR);             // LCD command (clear LCD)
   
    text = "mikroElektronika";       // Define the first message
    Lcd_Out(1,1,text);               // Write the first message in the first line
    text = "LCD example";            // Define the second message
    Lcd_Out(2,1,text);               // Define the first message
   
    ADCON1 = 0x82;                   // A/D voltage reference is VCC
    TRISA = 0xFF;                    // All port A pins are configured as inputs
    Delay_ms(2000);
   
    text = "voltage:";               // Define the third message
   
    while (1) {
        adc_rd = ADC_Read(2);        // A/D conversion. Pin RA2 is an input.
        Lcd_Out(2,1,text);           // Write result in the second line
        tlong = (long)adc_rd * 5000; // Convert the result in millivolts
        tlong = tlong / 1023;        // 0..1023 -> 0-5000mV
        ch = tlong / 1000;           // Extract volts (thousands of millivolts)
                                     // from result
        Lcd_Chr(2,9,48+ch);          // Write result in ASCII format
        Lcd_Chr_CP('.');
        ch = (tlong / 100) % 10;     // Extract hundreds of millivolts
        Lcd_Chr_CP(48+ch);           // Write result in ASCII format
        ch = (tlong / 10) % 10;      // Extract tens of millivolts
        Lcd_Chr_CP(48+ch);           // Write result in ASCII format
        ch = tlong % 10;             // Extract digits for millivolts
        Lcd_Chr_CP(48+ch);           // Write result in ASCII format
        Lcd_Chr_CP('V');
        Delay_ms(1);
    }
}


*source from mikroElektronika website.

Programming LCD screen is not simple as it look. We need to study a little bit about LCD background which can find in datasheet/ catalog and as a result practice make perfect.

Thursday, April 28, 2011

Line Follower Robot

Robot is used for doing task given. Robot doesn’t have emotion, sense, pain and so on. In the world today mostly work is being taken over by robot. Not 100%. We can see robot is used for  industry field where robot is assemble part of the car, in oil and gas field robot is drill the ground to find an oil, and also for entertainment where now is very popular among Japanese people.

Here i will show my first line follower robot using PIC18F4550. This robot will follow command where it will move on the track according to the programming we have written. Using sensor as input and motor as output to PIC, the robot will follow the line. Here it will detect white surface to give a respond to PIC.
 
This line follower robot is very popular among university and polytechnic student. This is because the capability of PIC to write and read again and again to do different task. PIC microcontroller is using EEPROM memory technology. It can be erase and write again and again, but before write anything it must be erase first using electrical voltage generated externally or internally in EEPROM.
Some of the famous EEPROM manufacturers are ATMEL, Microchip Technology, Infineon, ON Semiconductor and many more. This project we are using Microchip Technology manufacturers.

 In PIC microcontroller also has ADC (analog to digital converter) this term is familiar among electronic student. This ADC will convert analog input to digital output. We must declare it first in programming or algorithm to make sure that PIC operate like we want. All this specification we can find it in data sheet.



PIC18F4550 also can communicate using USB 2.0. This is advantages to PIC18Fxxx than PIC16Fxxx family where its only can support serial communication (RS232). With these advantages we can build USB bootloader for this PIC.


For build a Line Follower Robot, we must consider this all circuit :

  • USB bootloader circuit
  • Sensor circuit
  • Motor driver circuit
We just need 3 circuit, but the connection is complicated at all for the beginner.

USB bootloader circuit :


Sensor circuit :


We using LM324 comparator. This will allow analog to digital converter.

Motor driver circuit :
We using H-Bridge L293D for motor driver. Here we gonna use DC motor.
Here some table for reference :




All design circuit is depend on user. If user want to use 4 sensor so it will have 4 sensor circuit.

USB bootloader.hex for PIC18F4550
PIC18F4550 data sheet

The main important thing that you should know is :
  1. USB Bootloader circuit
  2. Sensor circuit & type of sensor (e.g IR sensor)
  3. Motor driver circuit & type of motor (e.g motor driver)
  4. C Programming
Step Guided
  1. Build a USB bootloader, sensor, and motor driver circuit
  2. Burn USB bootloader.hex into PIC using programmer (e.g PICkit 2,BZchip)
  3. Test USB bootloader by connect it to the laptop or computer
  4. Construct which PORT you want to connect to input for sensor and output for motor. (here I'm using PORT B as input sensor and PORT D as output motor)
  5. Make sure polarity for sensor and motor driver is correct.
  6. Write programming in MPLAB using C18 compiler
  7. Burn into PIC using USB bootloader
  8. Test robot and diagnose problem
  9. Finish
This step guided will show process from the beginning until the end. You can use mine programming for Line Follower Robot by download link below for reference :

line follower robot.c

Below some picture about my robot :



Contact me if you got any problem.

Tuesday, April 19, 2011

Introduction

Assalamualaikum.

For the 1st time I update this blog to test it whether it suitable for me to continue this blogging activities or not.
Many people say that blogging is wasting of time, but the entire thing in this world has their pro and contra. It’s all depending on how that people to manage or handle it. It's like an emotion.
The first reasonable I create this blog is to make and gather as much an idea to implement something more valuable to human kind.


Anything around us is very valuable if we can be a part of it, especially water. Water has a large amount in our earth. Imagine if we live without water. We will suffer from thirst, breath and so on.

That's proof we cannot be separate from nature and we have to love the nature, not destroy it.
So wake up my friends and love the nature as they love us for a long long time.....


Your friends,
the writer

Tuesday, March 22, 2011