Ðăng Nhập

View Full Version : Không hiển thị được LCD, giúp mình với


ngdnhanbk
06-01-2012, 10:33 AM
Mình làm mạch hiển thị theo sơ đồ nguyên lý sau
http://i333.photobucket.com/albums/m396/nguyennhan612/PIC/16F877A_LCD.png
và sử dụng file lcd_lib_4bit.c đã được post ở diễn đàn

#include <stddef.h>

#define LCD_RS PIN_D0
#define LCD_RW PIN_D1
#define LCD_EN PIN_D2
#define LCD_D4 PIN_D4
#define LCD_D5 PIN_D5
#define LCD_D6 PIN_D6
#define LCD_D7 PIN_D7

// misc display defines-
#define Line_1 0x80
#define Line_2 0xC0
#define Clear_Scr 0x01
#separate void LCD_Init ();// ham khoi tao LCD
#separate void LCD_SetPosition ( unsigned int cX );//Thiet lap vi tri con tro
#separate void LCD_PutChar ( unsigned int cX );// Ham viet1kitu/1chuoi len LCD
#separate void LCD_PutCmd ( unsigned int cX) ;// Ham gui lenh len LCD
#separate void LCD_PulseEnable ( void );// Xung kich hoat
#separate void LCD_SetData ( unsigned int cX );// Dat du lieu len chan Data


// prototype statements

// D/n Cong
#use standard_io (D)
//#use standard_io (D)

//khoi tao LCD**********************************************
#separate void LCD_Init ()
{
LCD_SetData ( 0x00 );
delay_ms(20); /* wait enough time after Vdd rise >> 15ms */
output_low ( LCD_RS );// che do gui lenh
LCD_SetData ( 0x03 ); /* init with specific nibbles to start 4-bit mode */
LCD_PulseEnable();
LCD_PulseEnable();
LCD_PulseEnable();
LCD_SetData ( 0x02 ); /* set 4-bit interface */
LCD_PulseEnable(); /* send dual nibbles hereafter, MSN first */
LCD_PutCmd ( 0x2C ); /* function set (all lines, 5x7 characters) */
LCD_PutCmd ( 0x0C ); /* display ON, cursor off, no blink */
LCD_PutCmd ( 0x06 ); /* entry mode set, increment & scroll left */
LCD_PutCmd ( 0x01 ); /* clear display */

// Init for BarGraph

}

#separate void LCD_SetPosition ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
LCD_SetData ( swap ( cX ) | 0x08 );
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) );
LCD_PulseEnable();
}

#separate void LCD_PutChar ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
output_high ( LCD_RS );
LCD_PutCmd( cX );
output_low ( LCD_RS );
}

#separate void LCD_PutCmd ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
LCD_SetData ( swap ( cX ) ); /* send high nibble */
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) ); /* send low nibble */
LCD_PulseEnable();
}
#separate void LCD_PulseEnable ( void )
{
output_high ( LCD_EN );
delay_us ( 3 ); // was 10
output_low ( LCD_EN );
delay_ms ( 3 ); // was 5
}

#separate void LCD_SetData ( unsigned int cX )
{
output_bit ( LCD_D4, cX & 0x01 );
output_bit ( LCD_D5, cX & 0x02 );
output_bit ( LCD_D6, cX & 0x04 );
output_bit ( LCD_D7, cX & 0x08 );
}

Chương trình hiển thị

#include <16F887.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#include "lcd_lib_4bit.c"
void main()
{
set_tris_d(0x00);
LCD_init();
LCD_putchar('X');
delay_ms(100);
LCD_putchar('I');
delay_ms(100);
LCD_putchar('N');
delay_ms(100);
LCD_putchar(' ');
delay_ms(100);
LCD_putchar('C');
delay_ms(100);
LCD_putchar('H');
delay_ms(100);
LCD_putchar('A');
delay_ms(100);
LCD_putchar('O');
delay_ms(100);
}

Nhưng chỉ hiện ra cái màn hình trắng trơn, ai chỉ giúp mình sai chỗ nào. Cảm ơn

ngdnhanbk
08-01-2012, 01:13 AM
http://i333.photobucket.com/albums/m396/nguyennhan612/PIC/lcd.jpg
Mình viết chương trình hiển thị dòng WELCOME TO VIETNAM bằng file lcd.c có sẵn trong ccs nhưng không được. Mọi người xem giúp mình sai chỗ nào

#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#include <lcd.c>
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7

#define LCD_RS PIN_D0
#define LCD_RW PIN_D1
#define LCD_E PIN_D2
void main()
{
lcd_init();
lcd_putc("Welcome to VIETNAM");
}

hcmut.khoamaisi
08-01-2012, 01:24 AM
Hiện tượng là như thế nào bạn nói rõ hơn được không! coi code ko thì cũng khó biết

ngdnhanbk
08-01-2012, 03:45 AM
Mình cần code để hiển thị dòng kí tự lên LCD như mô phỏng trong proteus như hình trên.
DÙng lcd.c có sẵn trog CCS

ngdnhanbk
10-01-2012, 07:33 PM
Mình đã làm được lcd.c như chỉ khi đổi nối thành
E RD0
RS RD1
RW RD2
còn trường hợp nối
RS RD0
RW RD1
E RD2
thì không được mặc dù mình đã define lại chân như sau trong chương trình
#define LCD_RS PIN_D0
#define LCD_RW PIN_D1
#define LCD_E PIN_D2

thanhdtk6
11-01-2012, 01:04 AM
bạn viết 1 đoạn code đơn giản thui tets thử theo cách đố sem

phatcddt08a
11-01-2012, 12:58 PM
mình làm mạch hiển thị theo sơ đồ nguyên lý sau
http://i333.photobucket.com/albums/m396/nguyennhan612/pic/16f877a_lcd.png
và sử dụng file lcd_lib_4bit.c đã được post ở diễn đàn

#include <stddef.h>

#define lcd_rs pin_d0
#define lcd_rw pin_d1
#define lcd_en pin_d2
#define lcd_d4 pin_d4
#define lcd_d5 pin_d5
#define lcd_d6 pin_d6
#define lcd_d7 pin_d7

// misc display defines-
#define line_1 0x80
#define line_2 0xc0
#define clear_scr 0x01
#separate void lcd_init ();// ham khoi tao lcd
#separate void lcd_setposition ( unsigned int cx );//thiet lap vi tri con tro
#separate void lcd_putchar ( unsigned int cx );// ham viet1kitu/1chuoi len lcd
#separate void lcd_putcmd ( unsigned int cx) ;// ham gui lenh len lcd
#separate void lcd_pulseenable ( void );// xung kich hoat
#separate void lcd_setdata ( unsigned int cx );// dat du lieu len chan data


// prototype statements

// d/n cong
#use standard_io (d)
//#use standard_io (d)

//khoi tao lcd**********************************************
#separate void lcd_init ()
{
lcd_setdata ( 0x00 );
delay_ms(20); /* wait enough time after vdd rise >> 15ms */
output_low ( lcd_rs );// che do gui lenh
lcd_setdata ( 0x03 ); /* init with specific nibbles to start 4-bit mode */
lcd_pulseenable();
lcd_pulseenable();
lcd_pulseenable();
lcd_setdata ( 0x02 ); /* set 4-bit interface */
lcd_pulseenable(); /* send dual nibbles hereafter, msn first */
lcd_putcmd ( 0x2c ); /* function set (all lines, 5x7 characters) */
lcd_putcmd ( 0x0c ); /* display on, cursor off, no blink */
lcd_putcmd ( 0x06 ); /* entry mode set, increment & scroll left */
lcd_putcmd ( 0x01 ); /* clear display */

// init for bargraph

}

#separate void lcd_setposition ( unsigned int cx )
{
/* this subroutine works specifically for 4-bit port a */
lcd_setdata ( swap ( cx ) | 0x08 );
lcd_pulseenable();
lcd_setdata ( swap ( cx ) );
lcd_pulseenable();
}

#separate void lcd_putchar ( unsigned int cx )
{
/* this subroutine works specifically for 4-bit port a */
output_high ( lcd_rs );
lcd_putcmd( cx );
output_low ( lcd_rs );
}

#separate void lcd_putcmd ( unsigned int cx )
{
/* this subroutine works specifically for 4-bit port a */
lcd_setdata ( swap ( cx ) ); /* send high nibble */
lcd_pulseenable();
lcd_setdata ( swap ( cx ) ); /* send low nibble */
lcd_pulseenable();
}
#separate void lcd_pulseenable ( void )
{
output_high ( lcd_en );
delay_us ( 3 ); // was 10
output_low ( lcd_en );
delay_ms ( 3 ); // was 5
}

#separate void lcd_setdata ( unsigned int cx )
{
output_bit ( lcd_d4, cx & 0x01 );
output_bit ( lcd_d5, cx & 0x02 );
output_bit ( lcd_d6, cx & 0x04 );
output_bit ( lcd_d7, cx & 0x08 );
}

chương trình hiển thị

#include <16f887.h>
#fuses hs,nowdt,noprotect,nolvp
#use delay(clock=4000000)
#include "lcd_lib_4bit.c"
void main()
{
set_tris_d(0x00);
lcd_init();
lcd_putchar('x');
delay_ms(100);
lcd_putchar('i');
delay_ms(100);
lcd_putchar('n');
delay_ms(100);
lcd_putchar(' ');
delay_ms(100);
lcd_putchar('c');
delay_ms(100);
lcd_putchar('h');
delay_ms(100);
lcd_putchar('a');
delay_ms(100);
lcd_putchar('o');
delay_ms(100);
}

nhưng chỉ hiện ra cái màn hình trắng trơn, ai chỉ giúp mình sai chỗ nào. Cảm ơn
cách này quá thủ công .bạn cho vào mảng rồi dùng vòng lặp ghi ra một lượt cho dễ

akatsu
11-01-2012, 03:23 PM
bạn đưa code và mạch mô phỏng proteus lên diễn đàn đi...Mình đoán là do bạn chọn tần số thạch anh không chính xác...chuẩn là 20Mhz

ngdnhanbk
12-01-2012, 01:51 AM
Tức là trong mô phỏng Proteus phải chọn tần số thạch anh của chip là 20MHz mới được hả

hoc_picpicpic
12-01-2012, 09:44 AM
Mình làm mạch hiển thị theo sơ đồ nguyên lý sau
http://i333.photobucket.com/albums/m396/nguyennhan612/PIC/16F877A_LCD.png
và sử dụng file lcd_lib_4bit.c đã được post ở diễn đàn

#include <stddef.h>

#define LCD_RS PIN_D0
#define LCD_RW PIN_D1
#define LCD_EN PIN_D2
#define LCD_D4 PIN_D4
#define LCD_D5 PIN_D5
#define LCD_D6 PIN_D6
#define LCD_D7 PIN_D7

// misc display defines-
#define Line_1 0x80
#define Line_2 0xC0
#define Clear_Scr 0x01
#separate void LCD_Init ();// ham khoi tao LCD
#separate void LCD_SetPosition ( unsigned int cX );//Thiet lap vi tri con tro
#separate void LCD_PutChar ( unsigned int cX );// Ham viet1kitu/1chuoi len LCD
#separate void LCD_PutCmd ( unsigned int cX) ;// Ham gui lenh len LCD
#separate void LCD_PulseEnable ( void );// Xung kich hoat
#separate void LCD_SetData ( unsigned int cX );// Dat du lieu len chan Data


// prototype statements

// D/n Cong
#use standard_io (D)
//#use standard_io (D)

//khoi tao LCD**********************************************
#separate void LCD_Init ()
{
LCD_SetData ( 0x00 );
delay_ms(20); /* wait enough time after Vdd rise >> 15ms */
output_low ( LCD_RS );// che do gui lenh
LCD_SetData ( 0x03 ); /* init with specific nibbles to start 4-bit mode */
LCD_PulseEnable();
LCD_PulseEnable();
LCD_PulseEnable();
LCD_SetData ( 0x02 ); /* set 4-bit interface */
LCD_PulseEnable(); /* send dual nibbles hereafter, MSN first */
LCD_PutCmd ( 0x2C ); /* function set (all lines, 5x7 characters) */
LCD_PutCmd ( 0x0C ); /* display ON, cursor off, no blink */
LCD_PutCmd ( 0x06 ); /* entry mode set, increment & scroll left */
LCD_PutCmd ( 0x01 ); /* clear display */

// Init for BarGraph

}

#separate void LCD_SetPosition ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
LCD_SetData ( swap ( cX ) | 0x08 );
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) );
LCD_PulseEnable();
}

#separate void LCD_PutChar ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
output_high ( LCD_RS );
LCD_PutCmd( cX );
output_low ( LCD_RS );
}

#separate void LCD_PutCmd ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
LCD_SetData ( swap ( cX ) ); /* send high nibble */
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) ); /* send low nibble */
LCD_PulseEnable();
}
#separate void LCD_PulseEnable ( void )
{
output_high ( LCD_EN );
delay_us ( 3 ); // was 10
output_low ( LCD_EN );
delay_ms ( 3 ); // was 5
}

#separate void LCD_SetData ( unsigned int cX )
{
output_bit ( LCD_D4, cX & 0x01 );
output_bit ( LCD_D5, cX & 0x02 );
output_bit ( LCD_D6, cX & 0x04 );
output_bit ( LCD_D7, cX & 0x08 );
}

Chương trình hiển thị

#include <16F887.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#include "lcd_lib_4bit.c"
void main()
{
set_tris_d(0x00);
LCD_init();
LCD_putchar('X');
delay_ms(100);
LCD_putchar('I');
delay_ms(100);
LCD_putchar('N');
delay_ms(100);
LCD_putchar(' ');
delay_ms(100);
LCD_putchar('C');
delay_ms(100);
LCD_putchar('H');
delay_ms(100);
LCD_putchar('A');
delay_ms(100);
LCD_putchar('O');
delay_ms(100);
}

Nhưng chỉ hiện ra cái màn hình trắng trơn, ai chỉ giúp mình sai chỗ nào. Cảm ơn





code này thiếu lệnh: lcd_gotoxy(0,0); // lệnh này đặt trước LCD_putchar('X');

lệnh này có tác dụng là thiết lập vị trí hiển thị