Total Pageviews

Friday, January 24, 2014

PIC16F877A basic tutorial

PIC16F877A
PIN DIAGRAMS

I/O PORTS                DIRECTION CONTROL REG.    NO OF PINS
PORTA                                  TRISA                                                6
PORTB                                  TRISB                                                8
PORTC                                  TRISC                                                8
PORTD                                  TRISD                                                8
PORTE                                  TRISE                                                3

EXAMPLE:
                        TRISB=0XFF     MAKE PORTB AS INPUT PORT
                        TRISB=0X00      MAKE PORTB AS OUTPUT PORT
BASIC PROGRAM TO ON/OFF LED’S
#include<pic.h>
void delay()
{
int i;
for(i=0;i<10000;i++);
}

void main()
{
TRISA=0X00;                       // MAKE PORTA AS OUTPUT//
while(1)
{
PORTA=0XFF;                    //LED’S - ON//
delay();
PORTA=0X00;                     //LED’S-OFF//
delay();
}
}

UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (USART)



SPBRG=X
BAUD RATE =FOSC / (16(X+1))

BASIC PGM FOR TRANSMISSION
# include<pic.h>
#define _XTAL_FREQ 4000000
__CONFIG(WDTDIS & XT & UNPROTECT);

void main()
{
TXSTA=0X24;
RCSTA=0X90;
SPBRG=0X19;
TRISC=0X80;
while(1)
{
TXREG='k';
while(TXIF==0);
TXIF=0;
}
}
LCD INTERFACING PROGRAM
#include<pic.h>
#define _XTAL_FREQ 4000000
__CONFIG(WDTDIS & XT & UNPROTECT);
void delay()
{
int i;
for(i=0;i<10;i++);
}
void COMMAND(char t)
{
PORTD=t;
RC0=0;
RC1=0;
RC2=1;
delay();
RC2=0;
}
void data(char t)
{
PORTD=t;
RC0=1;
RC1=0;
RC2=1;
delay();
RC2=0;
}
void main()
{
TRISC=0X00;
TRISD=0X00;
COMMAND(0X06);
COMMAND(0X0E);
COMMAND(0X01);
COMMAND(0X80);
COMMAND(0X38);
while(1)
{
data('w');
delay();
}

}

No comments:

Post a Comment