
The peripheral features of the PIC16F877 are:
• Timer0: 8-bit timer/counter with 8-bit prescaler
• Timer1: 16-bit timer/counter with prescaler, can be incremented during SLEEP via external
Crystal/clock
• Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler
• Two Capture, Compare, PWM modules
Capture is 16-bit, max. Resolution is 12.5 ns
- Compare is 16-bit, max. Resolution is 200 ns
- PWM max. Resolution is 10-bit
• 10-bit multi-channel Analog-to-Digital converter
• Synchronous Serial Port (SSP) with SPI. (Master mode)and I2C. (Master/Slave)
• Universal Synchronous Asynchronous Receiver
Transmitter (USART/SCI) with 9-bit address detection
• Parallel Slave Port (PSP) 8-bits wide, with external RD, WR and CS controls (40/44-pin only)
• Brown-out detection circuitry for Brown-out Reset (BOR)
The LCD standardrequires 3 control lines and 8 I/O lines for the data bus.
• 8 datapins D7:D0
Bi-directionaldata/command pins.
Alphanumeric characters are sent in ASCII format.
• RS: Register Select
RS= 0 -> Command Register is selected
RS = 1 -> Data Register is selected
• R/W:Read or Write
0 -> Write, 1 -> Read
• E:Enable (Latch data)
Usedto latch the data present on the data pins.
A high-to-low edge is needed to latch the data.
The 8 data lines are connected to PORT 1 of 8051microcontroller. The three control lines( RS,RW and EN ) are connected to PORT3.5,3.6 and 3.7 respectively.
LCD SUB-PROGRAM:
void lcd_data(unsigned char);
void lcd_cmd(unsigned char);
void lcd_str(char* );
void delay(unsigned int);
void lcd_init();
void lcd_init()
{
lcd_cmd(0x0E);
lcd_cmd(0x80);
lcd_cmd(0x38);
}
void lcd_data(unsigned char lcd_val)
{
PORTD=lcd_val;
RE2=1;
RE1=0;
RE0=1;
delay(100);
RE0=0;
}
void lcd_cmd(unsigned char lcd_val)
{
PORTD=lcd_val;
RE2=0;
RE1=0;
RE0=1;
delay(6500);
RE0=0;
}
void lcd_str(char *lcd_str1)
{
while(*lcd_str1)
{
lcd_data(*lcd_str1++);
}
}
void delay(unsigned int del)
{
while(del--);
}
EXAMPLE:
#include<htc.h>
#include "lcdsub.c"
void main()
{
TRISA=0xFF;
TRISE0=0;
TRISE1=0;
TRISE2=0;
TRISD=0x00;
TRISB0=0;
TRISB1=0;
ADCON1=0x82;
while(1)
{
lcd_cmd(0x80);
lcd_str(" SPIRO SOLUTION ");
lcd_cmd(0xc0);
lcd_str("CHENNAI ");
delay(65500);
}
}