|  | 
|  10-10-2006, 11:07 AM | #1 | 
| Đệ tử 1 túi Tham gia ngày: Nov 2005 
					Bài gửi: 23
 : | 
				
				LCD fastfood
			 để giúp các bạn đi sau làm lcd cho nhanh tui up cái file này lên để hổ trợ việc giao tiếp lcd nè. Code: #include "16F877A.h" // PIC16F877A header file
#include <string.h>
#use delay(clock=4000000) // for 4Mhz crystal
#fuses XT, NOWDT, NOPROTECT, NOLVP // for debug mode
#define WRITE_DATA 0
#define WRITE_COMMAND 1
#define NCHAR_PER_LINE 16 // max char numbers per line
#define MS10 10 // 10 milliseconds
#define US400 400 // 400 microseconds
#define LCD_RS PIN_A1
#define LCD_RW PIN_A2
#define LCD_E PIN_A3
//DU LIEU XUAT RA LA CUA PORTB
//RS-----------A1
//RW-----------A2
//EN-----------A3
//DATA---------PB
///////////////////////////////////////////////////////////
//
/* private */ void lcd_write(byte dat, int1 option) {
delay_us(US400);
if (option == WRITE_DATA)
output_high(LCD_RS);
else // option == WRITE_COMMAND
output_low(LCD_RS);
output_low(LCD_RW);
output_b(dat);
output_high(LCD_E);
delay_us(US400);
output_low(LCD_E);
}
///////////////////////////////////////////////////////////
//
void lcd_init(void) {
output_low(LCD_E); // Let LCD E line low
lcd_write(0x38, WRITE_COMMAND); // Set LCD 16x2, 5x7, 8bits data
delay_ms(15);
lcd_write(0x01, WRITE_COMMAND); // Clear LCD display
delay_ms(MS10);
lcd_write(0x0f, WRITE_COMMAND); // Open display & current
delay_ms(MS10);
lcd_write(0x06, WRITE_COMMAND); // Window fixed (Character Entry Mode?)
delay_ms(MS10);
}
///////////////////////////////////////////////////////////
//
void lcd_display_char(int8 line, int8 pos, char ch) {
line = (line == 0) ? 0 : 1;
pos = (pos > NCHAR_PER_LINE) ? NCHAR_PER_LINE : pos;
lcd_write(0x80 + 0x40 * line + pos, WRITE_COMMAND);
lcd_write(ch, WRITE_DATA);
}
///////////////////////////////////////////////////////////
void lcd_display_str(int8 line, char str[], int8 nchars) {
int8 i;
for (i = 0; i < nchars; i++)
lcd_display_char(line, i, str[i]);
}
///////////////////////////////////////////////////////////
void marquee_text(int8 line,char string[]){
int8 l,m;
for(l=0;l<strlen(string);l++){
   for(m=0;m<strlen(string)-l+1;m++){
      lcd_display_char(line,m,string[l+m]);
      delay_ms(15);
   }
}   
}
///////////////////////////////////////////////////////////
/**
* Display characters to a 2x16 LCD
*
* (1) LCD1 to GND
* (2) LCD2 to VDD 5 volts
* (3) LCD4 (RS) - LCD5 (RW) - LCD6 (E) to A1, A2, A3
* (4) LCD7-LCD14 to B0-B7 (bus data)
*
* Ref: http://pic16.com/bbs/dispbbs.asp?boa...ID=5879&page=1
*/
void main(void) {
int8 i;
char LINE1[] = { "SNG" };
char LINE2[] = { "WEBSITE" };
lcd_init();
// use of lcd_display_char()
for (i = 0; i < 16; i++)
lcd_display_char(0, i, LINE1[i]);
// use of lcd_display_str
//lcd_display_str(1, LINE2, 40);
for(;;) marquee_text(1,LINE2);
}1.lcd_display_char =>hiển thị ký tự 2.lcd_display_str =>hiển thị chuỗi 3.marquee_text =>chữ chạy từ trái sang phải để hiển thị nhiều ký tự file này đọc dể hiểu+dể làm nên chỉ post cho newbie thôi. Các bác cao thủ góp ý nhe. | 
|   |   | 
|  25-11-2006, 09:14 AM | #2 | 
| Đệ tử 5 túi Tham gia ngày: Sep 2006 
					Bài gửi: 101
 : | chương trình của bạn chỉ dùng để điều khiển LCD 8 bit. Nếu bạn có chương trình điều khiển 4 bit thì post lên luôn nhé! | 
|   |   | 
|  05-02-2007, 03:42 PM | #3 | 
| Nhập môn đệ tử Tham gia ngày: Jan 2007 
					Bài gửi: 7
 : | cam on hoangminh 1234 rat nhieu chuc ban thanh cong! | 
|   |   | 
|  | 
| Ðiều Chỉnh | |
| Xếp Bài | |
| 
 | 
 |