Search

Wednesday, September 3, 2014

USART Receiver With PIC18F4520

Title:USART Receiver With PIC18F4520

Program:

//Author : Palak Patel
//Contact No:9173211683
//Title: USART Receiver
//Platform: PIC18f4520
//Software: MPLAB

#include<p18f4520.h>
void cmd(unsigned char);
void dat(unsigned char);
void delay();
void main()
{
         unsigned char i,lcddata;
         TRISD=0x00;
         TRISB=0x00;        
         cmd(0x01);                          //Clear Lcd
         cmd(0x02);                          //4 Bit Specification
         cmd(0x28);                          //4 Bit specification
         cmd(0x0c);
         cmd(0x80);                          //Cursor starting point
               
         RCSTA=0x90;
         SPBRG=31;
         i=0;
         dat('I');
          while(1)
          {
                                while(PIR1bits.RCIF==0);
                                lcddata=RCREG;
                                PORTB=RCREG;
                                dat(lcddata);
                                //i++;
           }
}
void cmd(unsigned char k)
{
        PORTD &=0x0F;
        PORTD |=(k & (0xF0));
        PORTD |=(2<<0);
        delay();
        PORTD=PORTD & 0xFC;
        delay();

        PORTD &=0x0F;
        PORTD |=((k<<4) & (0xF0));
        PORTD |=(2<<0);
        delay();
        PORTD=PORTD & 0xFC;
        delay();
}
void dat(unsigned char k)
{
        PORTD &=0x0F;
        PORTD |=(k & 0xF0);
        PORTD |=(3<<0);
        delay();
        PORTD=PORTD & 0xFD;
        delay();

        PORTD &=0x0F;
        PORTD |=((k<<4) & (0xF0));
        PORTD |=(3<<0);
        delay();
        PORTD=PORTD & 0xFD;
        delay();
}

void delay()
{
                unsigned int i;
                for(i=0;i<40;i++);
}

Simulation:







For Basic Electronics Kindaly follow this Link:


No comments:

Post a Comment