Isnin, 27 Februari 2012

LCD Display connection using PIC 16F887A

1. PIC 16F887A Microcontroller
2. LCD Display

LCD is connection to Port B of the PIC 16F887A. Normal LCD have 16 pin. 8 pin for data and 8 pin for other use. Connect the LCD pin to PIC port B as below. LCD pin consists of Enable pin, RS pin, RW pin ,D4, D5, D6, and D7.

//B0 enable
//B1 rs
//B2 rw
//B3 D4
//B4 D5
//B5 D6
//B6 D7
Lcd pin D0 -D3 are not used and PIC B3 is not used.


I / O pins
There are 40 pins on PIC16F877A. Most of them can be used as an IO pin. Others are already for specific functions. These are the pin functions.
A. MCLR - to reset the PIC
Two. RA0 - port A pin 0
Three. RA1 - port A pin 1
4. RA2 - port A pin 2
Five. RA3 - port A pin 3
6. RA4 - port A pin 4
7. RA5 - port A pin 5
Eight. RE0 - port E pin 0
9. ES 1 - port E pin 1
10. RE2 - port E pin 2
11. VDD - power supply
12. VSS - ground
13. OSC1 - connect to oscillator
14. OSC2 - connect to oscillator
15. RC0 - port C pin 0
16. RC1 - port C pin 0
17. RC2 - port C pin 0
18. RC3 - port C pin 0
19. RD0 - port D pin 0
20. RD1 - port D pin 1
21. RD2 - port D pin 2
22. RD3 - port D pin 3
23. RC4 - port C pin 4
24. RC5 - port C pin 5
25. RC6 - port C pin 6
26. RC7 - port C pin 7
27. RD4 - port D pin 4
28. RD5 - port D pin 5
29. RD6 - port D pin 6
30. RD7 - port D pin 7
31. VSS - ground
32. VDD - power supply
33. RB0 - port B pin 0
34. RB1 - port B pin 1
35. RB2 - port B pin 2
36. RB3 - port B pin 3
37. RB4 - port B pin 4
38. RB5 - port B pin 5
39. RB6 - port B pin 6
40. RB7 - port B pin 7

By utilizing all of this pin so many application can be done such as:
A. LCD - connect to Port B pin.
Two. LEDs - connect to any pin declared as output.
Three. Relay and Motor - connect to any pin declared as output.
4. External EEPROM - connect to I2C interface pin - RC3 and RC4 (SCL and SDA)
Five. LDR, Potentiometer and sensor - connect to analogue inputs such as RA0 pin.
6. GSM modem dial-up modem - connect to RC6 and RC7 - the interface using RS232 serial communication protocol.

For more detail for each specific pin function please refer to the device datasheet from Microchip.

Playing with a C Programming and PIC16F877A

If you would like to play with a C programming language and PIC16F877A, it's very easy to get started. What you need is a desktop computer and CCS C compiler with PIC16F877A development kit. There are many suppler out there that can supply this at a very cheap cost.


15 easy step to make you write your first intelligent in CCS C program:

A. Select your PIC type.
# Include <16f877a.h>

Two. Select your oscillator speed.
# USE DELAY (CLOCK = 20000000) / / 20MHz crystall

Three. Select the oscillator type.
# FUSES HS, NOWDT, NOPROTECT

4. Define the Address of PORTB
# Bytes port_b = 6

Five. Define the Address of PORTD
# Bytes port_d = 8

6. Declare main program.
main () {

7. Set port_b0 to be input.
set_tris_b (0b00000001);

Eight. Set of D0, D1 as output (D0 = LED, D1 = Relay to Motor)
set_tris_d (0b00000000);

9. Initialize PORTD all outputs to 0 Volt.
port_d = 0;

10. Do forever
for (; ;) {

11. Check and test PORTB pin 0 voltage.
if (INPUT (PIN_B0) == 0)

12. Turn LED and Motor ON button is pressed When.
{
       output_high (PIN_D0); / / LED Turn ON
       output_high (PIN_D1); / / Turn ON Motor
   }
13. Turn LED and Motor ON button is not pressed When.
  
else
      {
        output_low (PIN_D0); / / LED Turn OFF
        output_low (PIN_D1); / / Motor Turn OFF
       }
14. Close the for loop.
   } / / Close for loop

15. Close the main program.
} / / Close main



This program That seems too simple connection of normal power supply to push buttons and LEDs can do it. But make the LED blink ON and OFF for 1 seconds 1.5 seconds repeatedly for as long as you pressed the button. Then it is so difficult to do it without using the PIC as you need components such as timer, counter and so on. However PIC do not need other component to do it. All already inside the PIC chip. This LED to blink the code can be added:

if (INPUT (PIN_B0) == 0)
for (; ;)
  {
       output_high (PIN_D0); / / LED Turn ON
             delay_MS (1000); / / delay 1 seconds
       output_low (PIN_D0); / / LED Turn OFF
             delay_MS (1500); / / delay 1.5 seconds
   }


Crystal Clear LCD Technology Overview


Pin No.
Symbol
Description
1
VSS
Ground terminal of module
2
VDD
Supply terminal of module
3
VO
Power supply for Liquid Crystal Drive
4
RS
Register Select:
RS = 0 .... Instruction Register
RS = 1 .... Data Register
5
R / W
Read / Write:
High = Read
Low = Write
6
E
Enable
7-14
D0 to D7
Bi-directional Data Bus. Data Transfer is performed
once, thru D0 to D7, in the case of interface data
length is 8-bits.
15
(BL -)
LED power supply terminals
16
(BL +)
LED power supply terminals

As defined in the Following structure, the pin connection from PIC16F877A to the LCD pins is as follows:
B0 to E - enable
B1 to rs
B2 to rw
B4 to D4 (Data pin)
B5 to D5 (Data pin)
B6 to D6 (Data pin)
B7 to D7 (Data pin)
LCD Command:
lcd_init () Must be called BEFORE any other function.
lcd_putc (c) Will display c on the next position of the LCD.
The Following have special meaning:
\ F Clear display
\ N Go to start of second line
\ B Move back one position

lcd_gotoxy (x, y) Set write position on LCD (upper left is 1.1)

lcd_getc (x, y) Returns character at position x, y on LCD

C Code Example:
# Include <16F877.h>
# Fuses HS, NOWDT, NOPROTECT, NOLVP
# Use delay (clock = 20000000)
# Include <lcd.c>
void main ()
{
lcd_init ();
lcd_putc ("\ fWelcome to PIC16F877A tutorial ... \ n");

}

Tiada ulasan:

Catat Ulasan