Haberler:

Eposta uyarılarını yanıtlamayınız ( ! ) https://bit.ly/2J7yi0d

Ana Menü

4x20 LCD yardım

Başlatan MURSEL, 07 Ağustos 2007, 19:53:32

MURSEL

merhaba arkadaslar 16f877 port d için 4x20 LCD driver dosyası varmı.  bu konuda çalışmaları olan arkadaşlaran yardımlarını bekliyorum. Allah'a Emanet Olun

alayli

Tam olarak ne istediğini anlamadım. Kod örneği mi istiyorsun? Hangi dili kullanıyorsun? Basic? C? Assembly?
Anca kazganmiş itmiş ilimiz törümüz erti. Türk Oguz begleri budun esiding. Üze tengri basmasar, asra yir telinmeser, Türk budun, ilingin törüngin kim artati? (udaci erti)

erdinch

Dostum CCS için 4x20 lcd driver.

/////////////////////////////////////////////////////////////////////////// 
//// FLEX_LCD420.C //// 
//// Driver for common 4x20 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 //// 
//// \c Cursor on //// 
//// \d Blink character //// 
//// \1 Custom character DegC //// 
//// //// 
//// 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,1997 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. //// 
//////////////////////////////////////////////////////////////////////////// 

// These pins are for the PIC development board: 
// B1 enable 
// B2 rs 
// B3 rw 
// B4 D4 
// B5 D5 
// E1 D6 
// E0 D7 

#define LCD_E PIN_B1 
#define LCD_RS PIN_B2 
#define LCD_RW PIN_B3 
#define LCD_DB4 PIN_B4 
#define LCD_DB5 PIN_B5 
#define LCD_DB6 PIN_E1 
#define LCD_DB7 PIN_E0 

// Clear and home 
#define LCD_CLR_DISP 0x01 // Clear screen, home cursor, unshift display 
#define LCD_RETURN_HOME 0x02 // Home cursor, unshift display 

// Set entry mode: display shift on/off, dec/inc cursor move direction 
#define LCD_ENTRY_DEC 0x04 // Display shift off, dec cursor move dir 
#define LCD_ENTRY_DEC_SHIFT 0x05 // Display shift on, dec cursor move dir 
#define LCD_ENTRY_INC 0x06 // Display shift off, inc cursor move dir 
#define LCD_ENTRY_INC_SHIFT 0x07 // Display shift on, inc cursor move dir 

// Display on/off, cursor on/off, blinking char at cursor position 
#define LCD_DISP_OFF 0x08 // Display off 
#define LCD_DISP_ON 0x0C // Display on, cursor off 
#define LCD_DISP_ON_BLINK 0x0D // Display on, cursor off, blink char 
#define LCD_DISP_ON_CURSOR 0x0E // Display on, cursor on 
#define LCD_DISP_ON_CURSOR_BLINK 0x0F // Display on, cursor on, blink char 

// Move cursor/shift display 
#define LCD_MOVE_CURSOR_LEFT 0x10 // Move cursor left (decrement) 
#define LCD_MOVE_CURSOR_RIGHT 0x14 // Move cursor right (increment) 
#define LCD_MOVE_DISP_LEFT 0x18 // Shift display left 
#define LCD_MOVE_DISP_RIGHT 0x1C // Shift display right 

// Function set: set interface data length and number of display lines 
#define LCD_FUNCTION_4BIT_1LINE 0x20 // 4-bit interface, single line, 5x7 dots 
#define LCD_FUNCTION_4BIT_2LINES 0x28 // 4-bit interface, dual line, 5x7 dots 
#define LCD_FUNCTION_8BIT_1LINE 0x30 // 8-bit interface, single line, 5x7 dots 
#define LCD_FUNCTION_8BIT_2LINES 0x38 // 8-bit interface, dual line, 5x7 dots 

#define LCD_CGRAM_BASE_ADDR 0x40 // Set the CGRAM address 
#define LCD_DDRAM_BASE_ADDR 0x80 // Set the DDRAM address 

// Address positions 
#define LCD_LINE_1 0x80 // Position of start of line 1 
#define LCD_LINE_2 0xC0 // Position of start of line 2 
#define LCD_LINE_3 0x94 // Position of start of line 3 
#define LCD_LINE_4 0xD4 // Position of start of line 4 

#define LCD_DEGREE_CHAR 0x00 // Ascii 00 

#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines 

BYTE const LCD_INIT_STRING[4] = { 
LCD_FUNCTION_4BIT_2LINES | (lcd_type << 2), // Set mode: 4-bit, 2 lines, 5x7 dots 
LCD_DISP_ON, 
LCD_CLR_DISP, 
LCD_ENTRY_INC }; 

BYTE const LCD_CUSTOM_CHARS[] = { 
0x1C,0x14,0x1C,0x00,0x00,0x00,0x00,0x00, // DegC 
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used 
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used 
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used 
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used 
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used 
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F, // Not used 
0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F }; // Not used 

BYTE lcd_line; 

BYTE lcd_read_nibble() { 
BYTE 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); 
} 

BYTE lcd_read_byte() { 
BYTE low,high; 

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

void lcd_send_nibble( BYTE n ) { 
output_bit(LCD_DB4, !!(n & 1)); 
output_bit(LCD_DB5, !!(n & 2)); 
output_bit(LCD_DB6, !!(n & 4)); 
output_bit(LCD_DB7, !!(n & 8)); 
delay_cycles(1); 
output_high(LCD_E); 
delay_us(2); 
output_low(LCD_E); 
} 

void lcd_send_byte( BYTE address, BYTE n ) { 
output_low(LCD_RS); 
while (bit_test(lcd_read_byte(),7)); // wait until busy flag is low 
if (address) 
output_high(LCD_RS); 
else 
output_low(LCD_RS); 
delay_cycles(1); 
output_low(LCD_RW); 
delay_cycles(1); 
output_low(LCD_E); 
lcd_send_nibble(n >> 4); 
lcd_send_nibble(n & 0xf); 
} 

void lcd_init() { 
BYTE i; 

lcd_line = 1; 
output_low(LCD_RS); 
output_low(LCD_RW); 
output_low(LCD_E); 
delay_ms(15); 
for (i=1;i<=3;++i) { 
lcd_send_nibble(3); 
delay_ms(5); 
} 
lcd_send_nibble(2); 
for (i=0;i<=sizeof(LCD_INIT_STRING);++i) 
lcd_send_byte(0, LCD_INIT_STRING[i]); 
} 

void lcd_init_custom_chars() { 
BYTE i; 

lcd_send_byte(0,LCD_CGRAM_BASE_ADDR); 
for (i=0;i<64;i++) { 
lcd_send_byte(1,LCD_CUSTOM_CHARS[i]); 
delay_ms(2); 
} 
} 

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

switch(y) { 
case 1 : address=LCD_LINE_1; break; 
case 2 : address=LCD_LINE_2; break; 
case 3 : address=LCD_LINE_3; break; 
case 4 : address=LCD_LINE_4; break; 
} 
address+=x-1; 
lcd_send_byte(0,0x80 | address); 
} 

void lcd_putc( char c ) { 
switch(c) { 
case '\f' : lcd_send_byte(0,LCD_CLR_DISP); 
lcd_line=1; 
delay_ms(2); break; 
case '\n' : lcd_gotoxy(1,++lcd_line); break; 
case '\b' : lcd_send_byte(0,LCD_MOVE_CURSOR_LEFT); break; 
case '\c' : lcd_send_byte(0,LCD_DISP_ON_CURSOR); break; 
case '\d' : lcd_send_byte(0,LCD_DISP_ON_BLINK); break; 
case '\1' : lcd_send_byte(1,LCD_DEGREE_CHAR); 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 
output_high(LCD_RS); 
value = lcd_read_byte(); 
output_low(LCD_RS); 
return(value); 
}

MURSEL

merhaba arkadeşler biraz acele yazdım kusura bakmayın  ccs derleyici için istiyorum arkadaşlar ccs içindeki 420.c driveri port b ye göre uyarlandıgı için istedigime  cevab vermiyor ben port d kullanarak 4x40lcd  kontrol etmek istiyorum 4x20 driverlerda genelde port b göre uyarlanmış
// These pins are for the PIC development board:
// d1 enable
// d2 rs
// d3 rw
// d4 D4
// d5 D5
// d6 D6
// d7 D7

#define LCD_E PIN_d1
#define LCD_RS PIN_d2
#define LCD_RW PIN_d3
#define LCD_DB4 PIN_d4
#define LCD_DB5 PIN_d5
#define LCD_DB6 PIN_d6
#define LCD_DB7 PIN_d7

@erdinc arkadaşımın verdigi driverda
bu sekilde degişiklik yapsam olurmu:(  ilginiz ve yardımlarınız hepinize tesekkürler a.e.o

zafzaf82

//4x20 LCD

 /**** LCD pinleri ****/
 #define LCD_en PIN_D2 //lcdyi yetkilendirmek icin
 #define LCD_rs PIN_D3  //konut yada kod yapmak icin 
 #define LCD_D7 PIN_D7   //lcd veri yolu pin tasarrufu için 4 bit kullandık 
 #define LCD_D6 PIN_D6
 #define LCD_D5 PIN_D5
 #define LCD_D4 PIN_D4 
 /*********************/


 //LCD_rw ucu 0'a bagli

 #define LCD_DELAY 250 /* yaklasik  1 ms */
 #define LCD_clear() LCD_command(0x01)   /* Clear display LCD */
 #define LCD_origin() LCD_command(0x2)   /* Set to origin LCD */
 #define lcd_line_bir  0x80 // LCD RAM address 1. satir
 #define lcd_line_iki  0xC0 // LCD RAM address 2. satir
 #define lcd_line_uc   0x94 // LCD RAM address 3. satir
 #define lcd_line_dort 0xD4 // LCD RAM address 4. satir

/***************************************************
 * Prototype(s)                                    *
 ***************************************************/
void LCD_enable();                        // LCD yetkilendirme
void LCD_command(unsigned char command);      // LCD komut 
void LCD_putc(unsigned char ascii);            // LCD tek karakter yazma 
void LCD_puts(unsigned char *lcd_string);      // LCD string yazma
void LCD_init();
void LCD_gotoxy(unsigned char x,unsigned char y);
/***************************************************
 * Sources                                         *
 ***************************************************/

//===================================================
void LCD_enable()
//===================================================
{
    output_bit( LCD_en,0); /* Clear bit en */   //lcd yi bir kere yetki,lendirmek için 
    delay_ms(1);
    output_bit( LCD_en,1); /* Set bit en */
}

//===================================================
void LCD_command(unsigned char command)   //lcdye komut gönder
//===================================================
{
   unsigned char nibble;
   output_bit( LCD_rs, 0); /* Clear bit P2.5 */
   nibble = (command>>4) & 0x0F;  //ilk 4 bitini gönderdik 
   output_bit(LCD_D4, (nibble & 0x01) );   //pinlere tek tek gönderdik. buton tek seferde göndermediği için 
   output_bit(LCD_D5, (nibble>>1 & 0x01) ); 
   output_bit(LCD_D6, (nibble>>2 & 0x01) );
   output_bit(LCD_D7, (nibble>>3 & 0x01) );
   LCD_enable();
   nibble = command & 0x0F;
   output_bit(LCD_D4, (nibble & 0x01) );   
   output_bit(LCD_D5, (nibble>>1 & 0x01) ); 
   output_bit(LCD_D6, (nibble>>2 & 0x01) );
   output_bit(LCD_D7, (nibble>>3 & 0x01) );
   LCD_enable();
   delay_ms(1);
}
//===================================================
void LCD_putc(unsigned char ascii)   //karakter gönderir. tek karakter 
//===================================================
{   unsigned char nibble;
    output_bit( LCD_rs, 1); /* Set bit P2.5 *///veri gönderdiğin için 1 oldu. 
    nibble = (ascii>>4) & 0x0F;//0x0f ile maskeliyor. 
   output_bit(LCD_D4, (nibble & 0x01) );   
   output_bit(LCD_D5, (nibble>>1 & 0x01) ); 
   output_bit(LCD_D6, (nibble>>2 & 0x01) );
   output_bit(LCD_D7, (nibble>>3 & 0x01) );
    LCD_enable();
    nibble = ascii & 0x0F;
   output_bit(LCD_D4, (nibble & 0x01) );   
   output_bit(LCD_D5, (nibble>>1 & 0x01) ); 
   output_bit(LCD_D6, (nibble>>2 & 0x01) );
   output_bit(LCD_D7, (nibble>>3 & 0x01) );
    LCD_enable();
    delay_ms(1);
}

//===================================================
void LCD_puts(unsigned char *lcd_string)
//===================================================
{
   while (*lcd_string) 
   {
      LCD_putc(*lcd_string++);
   }
}

void LCD_init()
{
    output_bit( LCD_en, 1); /* Set bit P2.4 */
    output_bit( LCD_rs, 0); /* Clear bit P2.5 */   
    LCD_command(0x33);
    LCD_command(0x32);
    LCD_command(0x28);
    LCD_command(0x0C);
    LCD_command(0x06);
    LCD_command(0x01); /* Clear */
    delay_ms(256);
}

//===================================================
void LCD_gotoxy(unsigned char x, unsigned char y)   //lcdye istediğimiz yere veri yazmamızı sağlar. satir ve sütün olarak 
//x ,y=sutun,satir
//===================================================
{
int address;  //ramdeki adresi tutar 

   switch( y )
   {
   case 1:
   address = lcd_line_bir;
   break;
   case 2:
   address = lcd_line_iki;
   break;
   case 3:
   address = lcd_line_uc;
   break;
   case 4:
   address = lcd_line_dort;
   break;
   }

address += x-1;     
LCD_command(address); //lcdye veri gönderiyor
}


istediğin port veya işlemciye uyarlayabilirsin bu kodu
Mikroişlemci bi araçtır, amaç değil.....