PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Các ngôn ngữ lập trình khác (CCS C, HT PIC,...)

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 31-07-2007, 05:44 PM   #1
nhnp0708
Đệ tử 1 túi
 
nhnp0708's Avatar
 
Tham gia ngày: May 2005
Nơi Cư Ngụ: HCM
Bài gửi: 23
:
LCD với CCS :(

em dùng LCD 2x16, mô phỏng bằng proteus hiển thị rất đúng, nhưng khi ráp vào mạch thực tế thì .... nó chỉ hiện được đến cột 10, mạch để test là PIC2+ RED
cho em hỏi nguyên nhân tại sao quái thế ???

code lcd_lib_4bit.c
Code:
#include "d:\code ccs\drivers\stddef.h"

#define LCD_RS PIN_A3
#define LCD_RW PIN_A2
#define LCD_EN PIN_A1

#define LCD_D4 PIN_D0
#define LCD_D5 PIN_D1
#define LCD_D6 PIN_D2
#define LCD_D7 PIN_D3

// misc display defines-
#define Line_1 0x80
#define Line_2 0xC0
#define Clear_Scr 0x01

// prototype statements
#separate void LCD_Init ( void );// 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

//khoi tao LCD**********************************************
#separate void LCD_Init ( void )
{
output_low(LCD_RW);
LCD_SetData ( 0x00 );
delay_ms(200); 
output_low ( LCD_RS );// che do gui lenh
LCD_SetData ( 0x03 ); 
LCD_PulseEnable();
LCD_SetData ( 0x02 ); 
LCD_PulseEnable(); 
LCD_PutCmd ( 0x2C ); 
LCD_PutCmd ( 0b00001100); 
LCD_PutCmd ( 0x06 ); 
LCD_PutCmd ( 0x01 ); 
}

#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 );
//delay_ms(0);
}

#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 );
}
code main
Code:
#include "d:\code ccs\devices\16F877A.h"
#include "d:\code ccs\define\def_16F877A.h"
#device *=16 ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#include "d:\code ccs\func\lcd_lib_4bit.c"

//Main
void main(void)
{
	set_tris_d(0x00);
	lcd_init();

		LCD_putcmd(Line_1);
		LCD_putchar("0123456789012345");
		LCD_putcmd(Line_2);
		LCD_putchar("0123456789012345");
}
__________________
Largo Winch
nhnp0708 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 06:38 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam