Picproje Elektronik Sitesi

DERLEYİCİLER => Microchip XC Serisi => Konuyu başlatan: enteresan10 - 06 Ağustos 2018, 18:56:44

Başlık: 18f4550 xc8 cevap lütfen
Gönderen: enteresan10 - 06 Ağustos 2018, 18:56:44
/*

#include <pic18f4550.h>
#include "Configuration_Header_File.h"

/*********************Definition of Ports********************************/

#define RS LATB0                   /*PIN 0 of PORTB is assigned for register select Pin of LCD*/
#define EN LATB1                    /*PIN 1 of PORTB is assigned for enable Pin of LCD */
#define ldata LATD                  /*PORTB(PB4-PB7) is assigned for LCD Data Output*/
#define LCD_Port TRISD             /*define macros for PORTB Direction Register*/

/*********************Proto-Type Declaration*****************************/

void MSdelay(unsigned int );        /*Generate delay in ms*/
void LCD_Init();                    /*Initialize LCD*/
void LCD_Command(unsigned char );   /*Send command to LCD*/
void LCD_Char(unsigned char x);     /*Send data to LCD*/
void LCD_String(const char *);      /*Display data string on LCD*/
void LCD_String_xy(char, char , const char *);
void LCD_Clear();                   /*Clear LCD Screen*/


int main(void)
{   
   
    OSCCON = 0x72;                        /*Use internal oscillator and
                                           * set frequency to 8 MHz*/
LCD_Init();                           /*Initialize LCD to 5*8 matrix in 4-bit mode*/   
LCD_String_xy(1,5,"Merhaba");           /*Display string on 1st row, 5th location*/
    LCD_String_xy(2,1,"Dunya"); /*Display string on 2nd row,1st location*/           
while(1);
}

//****************************Functions********************************

void LCD_Init()
{
    LCD_Port = 0;                   /*PORT as Output Port*/
    MSdelay(15);                    /*15ms,16x2 LCD Power on delay*/
    LCD_Command(0x02);              /*send for initialization of LCD
                                     *for nibble (4-bit) mode */
    LCD_Command(0x28);              /*use 2 line and
                                     *initialize 5*8 matrix in (4-bit mode)*/
LCD_Command(0x01);              /*clear display screen*/
    LCD_Command(0x0c);              /*display on cursor off*/
LCD_Command(0x06);              /*increment cursor (shift cursor to right)*/    
}

void LCD_Command(unsigned char cmd )
{
ldata = (ldata & 0x0f) |(0xF0 & cmd);   /*Send higher nibble of command first to PORT*/
RS = 0;                                 /*Command Register is selected i.e.RS=0*/
EN = 1;                                 /*High-to-low pulse on Enable pin to latch data*/
NOP();
EN = 0;
MSdelay(1);
    ldata = (ldata & 0x0f) | (cmd<<4);      /*Send lower nibble of command to PORT */
EN = 1;
NOP();
EN = 0;
MSdelay(3);
}


void LCD_Char(unsigned char dat)
{
ldata = (ldata & 0x0f) | (0xF0 & dat);   /*Send higher nibble of data first to PORT*/
RS = 1;                                  /*Data Register is selected*/
EN = 1;                                  /*High-to-low pulse on Enable pin to latch data*/
NOP();
EN = 0;
MSdelay(1);
    ldata = (ldata & 0x0f) | (dat<<4);               /*Send lower nibble of data to PORT*/
EN = 1;                         /*High-to-low pulse on Enable pin to latch data*/
NOP();
EN = 0;
MSdelay(3);
}
void LCD_String(const char *msg)
{
while((*msg)!=0)
{
  LCD_Char(*msg);
  msg++;
    }
}

void LCD_String_xy(char row,char pos,const char *msg)
{
    char location=0;
    if(row<=1)
    {
        location=(0x80) | ((pos) & 0x0f);      /*Print message on 1st row and desired location*/
        LCD_Command(location);
    }
    else
    {
        location=(0xC0) | ((pos) & 0x0f);      /*Print message on 2nd row and desired location*/
        LCD_Command(location);   
    } 
   

    LCD_String(msg);

}
void LCD_Clear()
{
    LCD_Command(0x01);     /*clear display screen*/
}

void MSdelay(unsigned int val)
{
 unsigned int i,j;
 for(i=0;i<=val;i++)
     for(j=0;j<81;j++);             /*This count Provide delay of 1 ms for 8MHz Frequency */
 }




Burada RS için RB0, E için RB1 ve D4 için RD4, D5 için RD5, D6 için RD6 ,D7 için RD7 kullanmak istiyorum. Ama bu kod çalışmıyor yardımcı olursanız sevinirim. Tşkler...
Başlık: Ynt: 18f4550 xc8 cevap lütfen
Gönderen: sigmoid - 06 Ağustos 2018, 21:08:56
Kodu incelemedim. Ben aşağıdaki kodu kullanıyorum.

https://github.com/gencmucitler/XC8-Kutuphane/tree/master/Lcd

Lcd.c ve lcd.h indirip projenize ekleyiniz.

Lcd.h içinde gerekli konfigürasyonları yapıp kullanabilirsiniz

Nasıl kullanılacağıyla ilgili videoya https://youtu.be/06N3_u4BzAs

Adresinden ulaşabilirsiniz. Kolay gelsin.
Başlık: Ynt: 18f4550 xc8 cevap lütfen
Gönderen: exmachine - 07 Ağustos 2018, 09:26:02
Bu kod XC8 için yazılmış gibi durmuyor. Eski sürüm derleyicilere ait olabilir.
@sigmoid 'in link verdiği yerden indirip projene dahil et. Birde öyle dene.
Başlık: Ynt: 18f4550 xc8 cevap lütfen
Gönderen: enteresan10 - 07 Ağustos 2018, 15:33:11
Teşekkürler...