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 10-10-2006, 11:07 AM   #1
hoangminh1234
Đệ 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);
}
trong đó có 3 hàm áp vô là chạy:

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.
File Kèm Theo
File Type: rar proteus file.rar (5.9 KB, 161 lần tải)
hoangminh1234 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à 09:22 AM.


Đượ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