Minggu, 30 Maret 2014

LCD 16x2 with PIC18F4520 Mplab


link download simulasi proteus dan file.HEX :

http://www.4shared.com/rar/1V5EpMqZ/PIC18f4520_LCD_16x2_with_PIC_M.html

/***********************************************/
/*                                             */
/*  program sofware design project PIC 18F4520 */
/*                                             */
/***********************************************/
#include <p18f4520.h>   
#include <delays.h>       
#include <string.h>   
#include <stdlib.h>
/***********************************************/
#define  LCD_DATA    PORTD          //deklarasi di awal program yang datanya tetap
#define     LCD_RS        PORTEbits.RE2
#define     LCD_RW        PORTEbits.RE1
#define     LCD_E        PORTEbits.RE0

const unsigned char write1[16]="SaFa Design soft";
const unsigned char write2[16]="   bismillah    ";

void write_inst(char inst) //sub program
{
    LCD_RS=0;
    LCD_RW=0;
    LCD_E=1;
    LCD_DATA=inst;        //mengkorversi isi data dari "inst" kedalam "LCD_DATA".
    Delay1KTCYx(1);
    LCD_E=0;
}

void write_data(char data)
{
    LCD_RS=1;
    LCD_RW=0;
    LCD_E=1;
    LCD_DATA=data;
    Delay1KTCYx(1);
    LCD_E=0;
}

void init_LCD(void)
{   
    write_inst(0x38);   
    write_inst(0x0C);
    write_inst(0x06);
    write_inst(0x01);
}

void locate_LCD(char x,char y)
{
unsigned char position;
     if(y==0){position=0x80+x;write_inst(position);}
     if(y==1){position=0xc0+x;write_inst(position);}
}

void clear_LCD(void)
{write_inst(0x01);}

void puts_LCD1(unsigned char *message1)
{
    unsigned char i=0;while(i<16)
    {write_data(message1[i]);i++;}
}

void main(void)
{
    ADCON1=0b00001111;
    TRISD=0x00;
    TRISE=0x00;
    init_LCD();
    clear_LCD();

while(1)
    {
    locate_LCD(0,0);
    puts_LCD1(write1);
    locate_LCD(0,1);
    puts_LCD1(write2);   
    }
}

0 komentar:

Posting Komentar