Haberler:

Foruma Resim Yükleme ve Boyut Sınırlaması ( ! )  https://bit.ly/2GMFb8H

Ana Menü

LCD (HelloWorld!)

Başlatan akyarF, 18 Haziran 2014, 15:34:42

akyarF

Merhabalar,
MPLAB IDE'de C18 compiler ı kullanarak LCD'ye "HelloWorld" yazdırmaya çalışıyorum. Mikroişlemcim p18f13k22;
Konstrast sorunum olmadığını düşünüyorum yine de LCD'de yalnızca 16 tane siyah kare görüyorum.
Kodum burada
/* I'm using MPLAB IDE v8.86 and Mplab C18 v3.40 windows evaluation*/
//I'm using 20 MHz Crystal
#include <p18f13k22.h>
#include "mylcd.h"
#include<delays.h>
#include<stdio.h>
#pragma config FOSC = HS
#pragma config PWRTEN = ON

void DelayFor18TCY( void )
{
Delay10TCYx(2);        // 5us delay
return;
}
void DelayPORXLCD (void)
{
Delay1KTCYx(75); // Delay of 15ms
				//Cycles = (TimeDelay * Fosc) / 4
				//Cycles = (15ms * 20MHz) / 4
				//Cycles = 75,000
return;
}
void DelayXLCD (void)
{
Delay1KTCYx(25); // Delay of 5ms
				//Cycles = (TimeDelay * Fosc) / 4
				//Cycles = (5ms * 20MHz) / 4
                //Cycles = 25,000
 return;
}

void main(void)
{int i,a;
char mybuff[20]="HelloWorld!";
for(i=0;i<1000;i++)
{//just wait for a while
}
E_PIN=1; //Just negative
E_PIN=0; //edge trigger to send information.
for(i=0;i<1000;i++)
{//just wait for a while
}


OpenXLCD( FOUR_BIT & LINES_5X7 );//Configure the I/O lines used for controlling the LCD and initialize the LCD.
for(i=0;i<1000;i++)
{//just wait for a while
}
E_PIN=1; //Just negative
E_PIN=0; //edge trigger to send information.
for(i=0;i<1000;i++)
{//just wait for a while
}


RW_PIN=0; // Write data to LCD 
RS_PIN=1; //
for(i=0;i<1000;i++)
{//just wait for a while
}
E_PIN=1; //Just negative
E_PIN=0; //edge trigger to send information.
for(i=0;i<1000;i++)
{//just wait for a while
}

//WriteDataXLCD('e');
putrsXLCD( "HelloWorld" );
putsXLCD( mybuff );
SetDDRamAddr(0x40); //shift cursor to beginning of second line

putrsXLCD("LCD Display"); //Display "LCD display"
//putcXLCD('K');
SetDDRamAddr(0x40); //shift cursor to beginning of second line

for(i=0;i<1000;i++)
{//just wait for a while
}
E_PIN=1; //Just negative
E_PIN=0; //edge trigger to send information.
for(i=0;i<1000;i++)
{//just wait for a while
}
putrsXLCD("LCD Display"); //Display "LCD display"


for(i=0;i<1000;i++)
{//just wait for a while
}
E_PIN=1; //Just negative
E_PIN=0; //edge trigger to send information.
for(i=0;i<1000;i++)
{//just wait for a while
}
a= BusyXLCD();



while(a==1){
i++;
//Just an infinite loop
}
while(a==0){
i++;
}

}


İlgili header file da burada. <xlcd.h> ın aynısın. yalnızca bacak numaralarını kendime uygun hale getirdim.
#ifndef __XLCD_H
#define __XLCD_H
#include "p18cxxx.h"
/* PIC18 XLCD peripheral routines.
 *
 *   Notes:
 *      - These libraries routines are written to support the
 *        Hitachi HD44780 LCD controller.
 *      - The user must define the following items:
 *          - The LCD interface type (4- or 8-bits)
 *          - If 4-bit mode
 *              - whether using the upper or lower nibble
 *          - The data port
 *              - The tris register for data port
 *              - The control signal ports and pins
 *              - The control signal port tris and pins
 *          - The user must provide three delay routines:
 *              - DelayFor18TCY() provides a 18 Tcy delay
 *              - DelayPORXLCD() provides at least 15ms delay
 *              - DelayXLCD() provides at least 5ms delay
 */

/* Interface type 8-bit or 4-bit
 * For 8-bit operation uncomment the #define BIT8
 */
/* #define BIT8 */

/* When in 4-bit interface define if the data is in the upper
 * or lower nibble.  For lower nibble, comment the #define UPPER
 */
 /*#define UPPER*/ 

/* DATA_PORT defines the port to which the LCD data lines are connected */
 #define DATA_PORT      		PORTC
 #define TRIS_DATA_PORT 		TRISC

/* CTRL_PORT defines the port where the control lines are connected.
 * These are just samples, change to match your application.
 */
 #define RW_PIN   LATBbits.LATB5   		/* PORT for RW */
 #define TRIS_RW  TRISBbits.TRISB5    	/* TRIS for RW */

 #define RS_PIN   LATBbits.LATB4   		/* PORT for RS */
 #define TRIS_RS  TRISBbits.TRISB4    	/* TRIS for RS */

 #define E_PIN    LATBbits.LATB6  		/* PORT for D  */
 #define TRIS_E   TRISBbits.TRISB6    	/* TRIS for E  */

/* Display ON/OFF Control defines */
#define DON         0b00001111  /* Display on      */
#define DOFF        0b00001011  /* Display off     */
#define CURSOR_ON   0b00001111  /* Cursor on       */
#define CURSOR_OFF  0b00001101  /* Cursor off      */
#define BLINK_ON    0b00001111  /* Cursor Blink    */
#define BLINK_OFF   0b00001110  /* Cursor No Blink */

/* Cursor or Display Shift defines */
#define SHIFT_CUR_LEFT    0b00000100  /* Cursor shifts to the left   */
#define SHIFT_CUR_RIGHT   0b00000101  /* Cursor shifts to the right  */
#define SHIFT_DISP_LEFT   0b00000110  /* Display shifts to the left  */
#define SHIFT_DISP_RIGHT  0b00000111  /* Display shifts to the right */

/* Function Set defines */
#define FOUR_BIT   0b00101100  /* 4-bit Interface               */
#define EIGHT_BIT  0b00111100  /* 8-bit Interface               */
#define LINE_5X7   0b00110000  /* 5x7 characters, single line   */
#define LINE_5X10  0b00110100  /* 5x10 characters               */
#define LINES_5X7  0b00111000  /* 5x7 characters, multiple line */

#define PARAM_SCLASS auto
#define MEM_MODEL far  /* Change this to near for small memory model */

/* OpenXLCD
 * Configures I/O pins for external LCD
 */
void OpenXLCD(PARAM_SCLASS unsigned char);

/* SetCGRamAddr
 * Sets the character generator address
 */
void SetCGRamAddr(PARAM_SCLASS unsigned char);

/* SetDDRamAddr
 * Sets the display data address
 */
void SetDDRamAddr(PARAM_SCLASS unsigned char);

/* BusyXLCD
 * Returns the busy status of the LCD
 */
unsigned char BusyXLCD(void);

/* ReadAddrXLCD
 * Reads the current address
 */
unsigned char ReadAddrXLCD(void);

/* ReadDataXLCD
 * Reads a byte of data
 */
char ReadDataXLCD(void);

/* WriteCmdXLCD
 * Writes a command to the LCD
 */
void WriteCmdXLCD(PARAM_SCLASS unsigned char);

/* WriteDataXLCD
 * Writes a data byte to the LCD
 */
void WriteDataXLCD(PARAM_SCLASS char);

/* putcXLCD
 * A putc is a write
 */
#define putcXLCD WriteDataXLCD

/* putsXLCD
 * Writes a string of characters to the LCD
 */
void putsXLCD(PARAM_SCLASS char *);

/* putrsXLCD
 * Writes a string of characters in ROM to the LCD
 */
void putrsXLCD(const rom char *);

/* User defines these routines according to the oscillator frequency */
extern void DelayFor18TCY(void);
extern void DelayPORXLCD(void);
extern void DelayXLCD(void);

#endif

Şimdiden yardımlarınız için çok teşekkür ederim.

ferit06

16 siyah kare ;
1- Kontrast sorunum yok diyorsun neye göre karar veriyorsun?
2- data bağlantıları doğru mu?

XX_CİHAN_XX

LCD init işlemini yapamıyorsun. OpenXLCD fonksiyonun doğru şekilde çalışmıyor yada lcd kütüphanesinde belirtilen io lar fiziksel olarak doğru bağlanmamış olabilir.
Yirmi yaşındaki bir insan, dünyayı değiştirmek ister . Yetmiş yaşına gelince , yine dünyayı değiştirmek ister, ama yapamayacağını bilir.

akyarF

#3
XX_CİHAN_XX çok doğru bir noktaya parmak bastınız. Ben de init işlemi ile ilgili bir problem olduğunu düşünüyordum. LCD'mi nasıl resetleyebilirim?
Bir diğer düşündüğüm sorun ise belki de yazdırma fonksiyonumu doğru adrese gönderemiyorum. Bunu nasıl kontrol edebilirim?

Kabil ATICI

LCD reset işlemi aşamaları

https://www.sparkfun.com/datasheets/LCD/HD44780.pdf

8 bit için sayfa 45
4 bit için sayfa 46

Zamanlama aşamaları kritik olmasada önemlidir.
ambar7

XX_CİHAN_XX

#5
PIC in konfig ayarları doğru yapıldı mı?
Özellikle osc ayarı...
Birde lcd pinlerinin çıkış olarak ayarlanması ana programda gözükmüyor sanırım xlcd.c deki init fonksiyonunda yapılıyor?
Başka bir LCD kütüphanesi indirip denemeni öneririm C18 için net ortamında zilyon tane kütüphane olsa gerek.

mesaj birleştirme:: 18 Haziran 2014, 23:08:57

PICin osc sinin doğru ayarlandığından ve çalıştığından emin olmak için ana program döngünüzde atıyorum bir saniye aralıklarla 1-0 çıkartıp bunu ledle yada ölçü aletiyle gözlemleyin. En azından PIC kısmı mı sorunlu LCD kısmı mı onu bir netleştirmiş olursunuz.
Yirmi yaşındaki bir insan, dünyayı değiştirmek ister . Yetmiş yaşına gelince , yine dünyayı değiştirmek ister, ama yapamayacağını bilir.

akyarF

Teşekkürler ambar7 ve xx_CİHAN_xx,
    Söylediklerinizi denedim. Gecikmelerimi kristalime göre doğru ayarladığımı düşünüyorum. Farklı bir kütüphane ile LCD'yi sürmeye çalıştım.
"Address: 00000000 Expected Value: 000000b4 Received Value: 000000ff"
Hatasını aldım. Bu ne anlama geliyor?  LCD'den received value değerini okuyabildiğime göre LCD'nin data portlarını doğru bağladığımı ve de LCD ile haberleşebildiğimi söyleyebilir miyim?

XX_CİHAN_XX

Alıntı yapılan: akyarF - 19 Haziran 2014, 11:32:40
Teşekkürler ambar7 ve xx_CİHAN_xx,
    Söylediklerinizi denedim. Gecikmelerimi kristalime göre doğru ayarladığımı düşünüyorum. Farklı bir kütüphane ile LCD'yi sürmeye çalıştım.
"Address: 00000000 Expected Value: 000000b4 Received Value: 000000ff"
Hatasını aldım. Bu ne anlama geliyor?  LCD'den received value değerini okuyabildiğime göre LCD'nin data portlarını doğru bağladığımı ve de LCD ile haberleşebildiğimi söyleyebilir miyim?


Bahsettiğin hatalar nerden geldi anlamadım.
Sana tavsiyem isis gibi bir nimet varken devre kurmakla uğraşma bence devreni önce bir isiste kur, çalıştırmayı dene, hatayı orada düzeltince gerçek ortamda denersin. Isis te LCD data hattından çıkan, giren her datayı bilgisayar ortamında görebildiğin için doğru pinleri mi kullandın yanlış pinleri mi en azından bunu anlarsın.
Yirmi yaşındaki bir insan, dünyayı değiştirmek ister . Yetmiş yaşına gelince , yine dünyayı değiştirmek ister, ama yapamayacağını bilir.