Haberler:

Forum kuralları güncellendi LÜTFEN  okuyunuz:  https://bit.ly/2IjR3ME

Ana Menü

LCDyi farklı uçlara bağlamak

Başlatan dijital74, 27 Temmuz 2009, 13:12:46

dijital74

Sevgili arkadaşlar.

Elimde EasyPIC5 deneme kartı var ve ben yazdığım programlarda LCD bağlantısı olarak aşağıdaki şekilde bağlantı yapmak zorundayım.

RS = RB4
R/W = GND
E = RB5
D0 = GND
D1 = GND
D2 = GND
D3 = GND
D4 = RB0
D5 = RB1
D6 = RB2
D7 = RB3

Bu bağlantı için aşağıdaki  <Lcd.c> dosyasının hangi satırlarında değişiklik yapmam gerekir?

///////////////////////////////////////////////////////////////////////////
////                             LCDD.C                                ////
////                 Driver for common LCD modules                     ////
////                                                                   ////
////  lcd_init()   Must be called before any other function.           ////
////                                                                   ////
////  lcd_putc(c)  Will display c on the next position of the LCD.     ////
////                     The following have special meaning:           ////
////                      \f  Clear display                            ////
////                      \n  Go to start of second line               ////
////                      \b  Move back one position                   ////
////                                                                   ////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)    ////
////                                                                   ////
////  lcd_getc(x,y)   Returns character at position x,y on LCD         ////
////                                                                   ////
///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 Custom Computer Services           ////
//// This source code may only be used by licensed users of the CCS C  ////
//// compiler.  This source code may only be distributed to other      ////
//// licensed users of the CCS C compiler.  No other use, reproduction ////
//// or distribution is permitted without written permission.          ////
//// Derivative programs created using this software in object code    ////
//// form are not restricted in any way.                               ////
///////////////////////////////////////////////////////////////////////////

// As defined in the following structure the pin connection is as follows:
//     D0  enable
//     D1  rs
//     D2  rw
//     D4  D4
//     D5  D5
//     D6  D6
//     D7  D7
//
//   LCD pins D0-D3 are not used and PIC D3 is not used.

// Un-comment the following define to use port B
// #define use_portb_lcd TRUE


struct lcd_pin_map {                 // This structure is overlayed
           BOOLEAN enable;           // on to an I/O port to gain
           BOOLEAN rs;               // access to the LCD pins.
           BOOLEAN rw;               // The bits are allocated from
           BOOLEAN unused;           // low order up.  ENABLE will
           int     data : 4;         // be pin B0.
        } lcd;


#if defined use_portb_lcd
   #locate lcd = getenv("sfr:PORTB")    // This puts the entire structure over the port
   #define set_tris_lcd(x) set_tris_b(x)
#else
   #locate lcd = getenv("sfr:PORTD")    // This puts the entire structure over the port
   #define set_tris_lcd(x) set_tris_d(x)
#endif


#define lcd_type 2           // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40    // LCD RAM address for the second line


BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
                             // These bytes need to be sent to the LCD
                             // to start it up.


                             // The following are used for setting
                             // the I/O port direction register.

struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in



BYTE lcd_read_byte() {
      BYTE low,high;
      set_tris_lcd(LCD_READ);
      lcd.rw = 1;
      delay_cycles(1);
      lcd.enable = 1;
      delay_cycles(1);
      high = lcd.data;
      lcd.enable = 0;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(1);
      low = lcd.data;
      lcd.enable = 0;
      set_tris_lcd(LCD_WRITE);
      return( (high<<4) | low);
}


void lcd_send_nibble( BYTE n ) {
      lcd.data = n;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(2);
      lcd.enable = 0;
}


void lcd_send_byte( BYTE address, BYTE n ) {

      lcd.rs = 0;
      while ( bit_test(lcd_read_byte(),7) ) ;
      lcd.rs = address;
      delay_cycles(1);
      lcd.rw = 0;
      delay_cycles(1);
      lcd.enable = 0;
      lcd_send_nibble(n >> 4);
      lcd_send_nibble(n & 0xf);
}


void lcd_init() {
    BYTE i;
    set_tris_lcd(LCD_WRITE);
    lcd.rs = 0;
    lcd.rw = 0;
    lcd.enable = 0;
    delay_ms(15);
    for(i=1;i<=3;++i) {
       lcd_send_nibble(3);
       delay_ms(5);
    }
    lcd_send_nibble(2);
    for(i=0;i<=3;++i)
       lcd_send_byte(0,LCD_INIT_STRING[i]);
}


void lcd_gotoxy( BYTE x, BYTE y) {
   BYTE address;

   if(y!=1)
     address=lcd_line_two;
   else
     address=0;
   address+=x-1;
   lcd_send_byte(0,0x80|address);
}

void lcd_putc( char c) {
   switch (c) {
     case '\f'   : lcd_send_byte(0,1);
                   delay_ms(2);
                                           break;
     case '\n'   : lcd_gotoxy(1,2);        break;
     case '\b'   : lcd_send_byte(0,0x10);  break;
     default     : lcd_send_byte(1,c);     break;
   }
}

char lcd_getc( BYTE x, BYTE y) {
   char value;

    lcd_gotoxy(x,y);
    while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
    lcd.rs=1;
    value = lcd_read_byte();
    lcd.rs=0;
    return(value);
}

hasangurlek

Alıntı yapılan: "dijital74"RS = RB4
R/W = GND
E = RB5

D0 = GND
D1 = GND
D2 = GND
D3 = GND

D4 = RB0
D5 = RB1
D6 = RB2
D7 = RB3

?????
http://www.cyber-warrior.org, Although they like whiteness, sometimes twilight is required...  Hala evlilermi bilinmez ama kesinlikle artık uygun değiller !!!

tacettin

// istediğin bacağı yazabilirsin...
//coder: PCM Programmer
#define LCD_DB4 PIN_d2
#define LCD_DB5 PIN_d3
#define LCD_DB6 PIN_c4
#define LCD_DB7 PIN_d2

#define LCD_E PIN_c6
#define LCD_RS PIN_d4
#define LCD_RW PIN_c7

#define LCD_CGRAM_ADDR 0x40
#define LCD_DDRAM_ADDR 0x80

#define USE_LCD_RW 1

#define lcd_type 2

#define lcd_line_two 0x40

#define LCD_CHAR_1 0x01
#define LCD_CHAR_2 0x02
#define LCD_CHAR_3 0x03
#define LCD_CHAR_4 0x04
#define LCD_CHAR_5 0x05
#define LCD_CHAR_6 0x06
#define LCD_CHAR_7 0x07
#define LCD_CHAR_8 0x08

int8 const LCD_INIT_STRING[4] =
{0x20 | (lcd_type << 2),0xc,1,6};

void lcd_send_nibble(int8 nibble)
{
output_bit(LCD_DB4, !!(nibble & 1));
output_bit(LCD_DB5, !!(nibble & 2));
output_bit(LCD_DB6, !!(nibble & 4));
output_bit(LCD_DB7, !!(nibble & 8));
delay_cycles(1);

output_high(LCD_E);
delay_us(2);
output_low(LCD_E);
}

#ifdef USE_LCD_RW

int8 lcd_read_nibble(void)
{
int8 retval;

#bit retval_0 = retval.0
#bit retval_1 = retval.1
#bit retval_2 = retval.2
#bit retval_3 = retval.3
retval = 0;

output_high(LCD_E);
delay_cycles(1);

retval_0 = input(LCD_DB4);
retval_1 = input(LCD_DB5);
retval_2 = input(LCD_DB6);
retval_3 = input(LCD_DB7);

output_low(LCD_E);
return(retval);
}

#endif

#ifdef USE_LCD_RW

int8 lcd_read_byte(void)
{
int8 low;
int8 high;

output_high(LCD_RW);
delay_cycles(1);
high = lcd_read_nibble();
low = lcd_read_nibble();
return( (high<<4) | low);
}

#endif

void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);
#ifdef USE_LCD_RW

while(bit_test(lcd_read_byte(),7)) ;
#else
delay_us(60);
#endif

if(address)
output_high(LCD_RS);
else
output_low(LCD_RS);
delay_cycles(1);

#ifdef USE_LCD_RW
output_low(LCD_RW);
delay_cycles(1);
#endif

output_low(LCD_E);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}

void lcd_setcursor_vb(short visible, short blink) {
lcd_send_byte(0, 0xC|(visible<<1)|blink);
}

void lcd_init(void)
{
int8 i;

output_low(LCD_RS);

#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif

output_low(LCD_E);
delay_ms(15);

for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
}

lcd_send_nibble(0x02);
for(i=0; i < sizeof(LCD_INIT_STRING); i++)
{
lcd_send_byte(0, LCD_INIT_STRING);

#ifndef USE_LCD_RW
delay_ms(5);
#endif
}
}

void lcd_gotoxy(int8 x, int8 y)
{
int8 address;
if(y != 1)
address = lcd_line_two;
else
address=0;
address += x-1;
lcd_send_byte(0, 0x80 | address);
}

void lcd_putc(char c)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1);delay_ms(2);break;
case '\n':lcd_gotoxy(1,2);break;
case '\b':lcd_send_byte(0,0x10);break;

default:
lcd_send_byte(1,c);break;
}

}

#ifdef USE_LCD_RW

char lcd_getc(int8 x, int8 y)
{

char value;

lcd_gotoxy(x,y);
while(bit_test(lcd_read_byte(),7));
output_high(LCD_RS);
value = lcd_read_byte();

output_low(lcd_RS);
return(value);
}

#endif



adress : http://ccspic.com/driver/2x16-lcdler-icin-flexy-driver.html

dijital74

Alıntı yapılan: "hasangurlek"
Alıntı yapılan: "dijital74"RS = RB4
R/W = GND
E = RB5

D0 = GND
D1 = GND
D2 = GND
D3 = GND

D4 = RB0
D5 = RB1
D6 = RB2
D7 = RB3

?????

4 bit bağlantıda D0 ile D3 uçları ya açıkta bırakılır ya da şaseye çekilir.
R/W (okuma yazma) ucu sadece yazma yapılacaksa şaseye çekilir.
Benim EasyPIC de bu şekilde tasarlanmış. Sonradan bu uçları değiştiremem.

@tacettin

Yazdığın kodu LCD.c olarak mı kaydetmeliyim?

Edit: Yazdığın aşağıdaki satırlar benim LCD bağlantısına uymuyor.

#define LCD_DB4 PIN_d2
#define LCD_DB5 PIN_d3
#define LCD_DB6 PIN_c4
#define LCD_DB7 PIN_d2

#define LCD_E PIN_c6
#define LCD_RS PIN_d4
#define LCD_RW PIN_c7


Sadece burdaki bağlantıları değiştirmek benim işimi görür mü ?

hasangurlek

R/W yi tanımlamayınca derleyici kızmıyormu ?
http://www.cyber-warrior.org, Although they like whiteness, sometimes twilight is required...  Hala evlilermi bilinmez ama kesinlikle artık uygun değiller !!!

dijital74

Alıntı yapılan: "hasangurlek"R/W yi tanımlamayınca derleyici kızmıyormu ?

CCS C ile yeni yeni uğraşıyorum. LCD sürmek için bundan önce PBP kullanıyordum. R / W pinini tanımlamayınca herhangi bir sorun yaşamadım. Hiç LCDden bilgi okuma işi yapmadım ki.

ahmet2004

Lcd RW pini şaseye bağlanacak.

///////////////////////////////////////////////////////////////////////////
////                             EXLCD.C                                ////
////                 Driver for common LCD modules                     ////
////                                                                   ////
////  lcd_init()   Must be called before any other function.           ////
////                                                                   ////
////  lcd_putc(c)  Will display c on the next position of the LCD.     ////
////                     The following have special meaning:           ////
////                      \f  Clear display                            ////
////                      \n  Go to start of second line               ////
////                      \b  Move back one position                   ////
////                                                                   ////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)    ////
////                                                                   ////
////  lcd_getc(x,y)   Returns character at position x,y on LCD         ////
////                                                                   ////
///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 Custom Computer Services           ////
//// This source code may only be used by licensed users of the CCS C  ////
//// compiler.  This source code may only be distributed to other      ////
//// licensed users of the CCS C compiler.  No other use, reproduction ////
//// or distribution is permitted without written permission.          ////
//// Derivative programs created using this software in object code    ////
//// form are not restricted in any way.                               ////
///////////////////////////////////////////////////////////////////////////

// As defined in the following structure the pin connection is as follows:
//     D0  enable
//     D1  rs
//     D2  rw
//     D4  D4
//     D5  D5
//     D6  D6
//     D7  D7
//
//   LCD pins D0-D3 are not used and PIC D3 is not used.

// Un-comment the following define to use port B
 #define use_portb_lcd TRUE

struct lcd_pin_map {                 // This structure is overlayed
   int    data    : 4;         // be pin B0.
   BOOLEAN rs;
   BOOLEAN enable;
   BOOLEAN unused;
   BOOLEAN rw;      
} lcd;

#define use_portb_lcd

#if defined use_portb_lcd
   #locate lcd = getenv("sfr:PORTB")    // This puts the entire structure over the port
   #define set_tris_lcd(x) set_tris_b(x)
#else
   #locate lcd = getenv("sfr:PORTD")    // This puts the entire structure over the port
   #define set_tris_lcd(x) set_tris_d(x)
#endif


#define lcd_type 2           // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40    // LCD RAM address for the second line


BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
                             // These bytes need to be sent to the LCD
                             // to start it up.


                             // The following are used for setting
                             // the I/O port direction register.

struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in



BYTE lcd_read_byte() {
      BYTE low,high;
      set_tris_lcd(LCD_READ);
      //lcd.rw = 1;
      delay_cycles(1);
      lcd.enable = 1;
      delay_cycles(1);
      high = lcd.data;
      lcd.enable = 0;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(1);
      low = lcd.data;
      lcd.enable = 0;
      set_tris_lcd(LCD_WRITE);
      return( (high<<4) | low);
}


void lcd_send_nibble( BYTE n ) {
      lcd.data = n;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(2);
      lcd.enable = 0;
}


void lcd_send_byte( BYTE address, BYTE n ) {

      lcd.rs = 0;
      //while(bit_test(lcd_read_byte(),7));
     delay_cycles(200);
     delay_cycles(200);
      lcd.rs = address;
      delay_cycles(1);
      //lcd.rw = 0;
      delay_cycles(1);
      lcd.enable = 0;
      lcd_send_nibble(n >> 4);
      lcd_send_nibble(n & 0xf);
}


void lcd_init() {
    BYTE i;
    set_tris_lcd(LCD_WRITE);
    lcd.rs = 0;
    //lcd.rw = 0;
    lcd.enable = 0;
    delay_ms(15);
    for(i=1;i<=3;++i) {
       lcd_send_nibble(3);
       delay_ms(5);
    }
    lcd_send_nibble(2);
    for(i=0;i<=3;++i)
       lcd_send_byte(0,LCD_INIT_STRING[i]);
}


void lcd_gotoxy( BYTE x, BYTE y) {
   BYTE address;

   if(y!=1)
     address=lcd_line_two;
   else
     address=0;
   address+=x-1;
   lcd_send_byte(0,0x80|address);
}

void lcd_putc( char c) {
   switch (c) {
     case '\f'   : lcd_send_byte(0,1);
                   delay_ms(2);
                                           break;
     case '\n'   : lcd_gotoxy(1,2);        break;
     case '\b'   : lcd_send_byte(0,0x10);  break;
     default     : lcd_send_byte(1,c);     break;
   }
}

char lcd_getc( BYTE x, BYTE y) {
   char value;

    lcd_gotoxy(x,y);
    while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
    lcd.rs=1;
    value = lcd_read_byte();
    lcd.rs=0;
    return(value);
}

dijital74

struct lcd_pin_map {      


Kodu derleme sırasında hata veriyor. Hata şöyle;

A #DEVICE required before this line

ahmet2004

Kodlar proteus import dosyası paylaşım alanımıza ekledim.

http://www.4shared.com/file/121110735/8ff8f346/ADC_LCD.html

Birde bunları deneyebilirmisin?

dijital74

@ahmet2004

Bu LCD dosyalarının CCS C derleyicisinde derlenebilmesi gerekmez mi? Yukarıdaki hata mesajının aynısını yine alıyorum. Aynı satır için.

ahmet2004

İlginç derleyememeniz.

Windows xp mi? CCS-C versiyonlarınız nedir?

CCS versiyon farkı olabilir büyük ihtimal.

dijital74

Windows Vista Home Premium x86 SP2 Tr

CCS C versiyonları tamamı 4.013

ahmet2004

Ben CCS C versiyonu 4.084 de derledim.

CCS de eski sürümler sorun çıkartıyor.

dijital74

Yeni versiyonu indirip deneyip, sonucu burada paylaşırım.

ferdem

Hocam lcd.c kendi başına derlenmez tabii. Asıl kodun olduğu sayfaya "include" ettikten sonra derleyin.
tacettin arkadaşın verdiği bağlantıdaki lcd kütüphanesi istenilen pinlerin LCD de kullanılmasına göre düzenlemiş, en baştaki satırlarda pinler ayarlanıyor.
http://ccspic.com/driver/2x16-lcdler-icin-flexy-driver.html

Alıntı yapılan: "dijital74"
#define LCD_DB4 PIN_d2 
#define LCD_DB5 PIN_d3 
#define LCD_DB6 PIN_c4 
#define LCD_DB7 PIN_d2 

#define LCD_E PIN_c6 
#define LCD_RS PIN_d4 
#define LCD_RW PIN_c7

Sadece burdaki bağlantıları değiştirmek benim işimi görür mü ?
Görmesi lazım. Ben deneyemiyorum ancak bu kütüphaneyi proteusta kolayca test edebilirsiniz.

O kodları lcd2.c olarak kaydedip "drivers" klasörüne attıktan sonra kodunuza lcd.c yerine lcd2.c yi "include" edin. Çalışması lazım.
Kolay gelsin.