![]() |
|
Tài trợ cho PIC Vietnam |
Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC |
![]() |
|
Ðiều Chỉnh | Xếp Bài |
|
![]() |
#1 |
Đệ tử 1 túi
Tham gia ngày: Sep 2010
Bài gửi: 12
: |
Làm thế nào để chữ chạy trên màn hình LCD ??
Mình khai báo như thế này
char const dong6[16]={'L','C','D',' ','V','A',' ','P','I','C','1','6','F','8','7','7'}; giờ mình muốn xuất nó ra LCD mà chạy từ phải sang trái thì phải viết như thế nào?? Mới học nên muốn biết thêm> ![]() |
![]() |
![]() |
![]() |
#2 | |
Nhập môn đệ tử
Tham gia ngày: Nov 2007
Bài gửi: 1
: |
Chạy chữ trên LCD
Trích:
1. lưu biến dong6[0] vào 1 biến tạm x. 2. dùng 1 vòng for tráo đổi vị trí ký tự (dong6[i]=dong6[i+1]) 3. sau khi kết thúc vòng for thì ta thay ký tự cuối cùng là x. 4. xuất dòng ký tự lên màn hình. 5. delay và lặp lại chương trình Để cụ thể hóa mình sẽ gửi tới bạn 1 code sau: chạy dòng chữ "Dai thang mua xuan 1975" làm ví dụ nhé. Mình dùng CCS //------------------------------------------------------------------------------ #include "C:\Documents and Settings\QUACH CUONG\My Documents\test PIC\pic18f4680_chuchay.h" #include <LCD_PIC18F4620_420_D.C> //dirver LCD cho pic18 (LCD su dung 4bit) #include <string.h> char chuoi[]; //------------------Chuong trinh con chay chu---------------------------------- void chay_chu(void) { int i; char x; x=chuoi[0]; for(i=0;i<(strlen(chuoi)-1);i++) // strlen() la ham lay chieu dai chuoi { chuoi[i]=chuoi[i+1]; } chuoi[strlen(chuoi)-1]=x; lcd_gotoxy(1,1); //ss=mid(chuoi, 0, 15) printf(lcd_putc,chuoi); } //----------------------------------------------------------------------------- void main() { setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF|ADC_TAD_MUL_0); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); lcd_init(); //Setup_Oscillator parameter not selected from Intr Oscillator Config tab // TODO: USER CODE!! strcpy(chuoi,"Dai thang mua xuan 1975. "); // phia sau dong chu nen de 1 khoang trang de phan biet dong chu khi chay. while(1) { chay_chu(); delay_ms(400); } } //================================================== =================================== Đây là driver cho LCD 4 bit ghép ở cổng D //////////////////////////////////////////////////////////////////////////// //// 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 //// //// //// //// 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. //// //////////////////////////////////////////////////////////////////////////// // As defined in the following structure the pin connection is as follows: // D0 enable // D1 rs // D2 rw // D4 D4 // D5 D5 // D6 D6 // D7 D7 // // LCD pins D0-D3 are not used and PIC B3 is not used. struct lcd_pin_map { // This structure is overlayed BOOLEAN enable; // on to an I/O port to gain BOOLEAN rs; // access to the LCD pins. BOOLEAN rw; // The bits are allocated from BOOLEAN unused; // low order up. ENABLE will int data : 4; // be pin B0. } lcd; #byte lcd = 0xF83 // This puts the entire structure // on to port B (at address 6) #define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6}; // These bytes need to be sent to the LCD // to start it up. // The following are used for setting // the I/O port direction register. struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in BYTE lcdline; BYTE lcd_read_byte() { BYTE low,high; set_tris_d(LCD_READ); lcd.rw = 1; delay_cycles(1); lcd.enable = 1; delay_cycles(1); high = lcd.data; lcd.enable = 0; delay_cycles(1); lcd.enable = 1; delay_us(1); low = lcd.data; lcd.enable = 0; set_tris_d(LCD_WRITE); return( (high<<4) | low); } void lcd_send_nibble( BYTE n ) { lcd.data = n; delay_cycles(1); lcd.enable = 1; delay_us(2); lcd.enable = 0; } void lcd_send_byte( BYTE address, BYTE n ) { lcd.rs = 0; while ( bit_test(lcd_read_byte(),7) ) ; lcd.rs = address; delay_cycles(1); lcd.rw = 0; delay_cycles(1); lcd.enable = 0; lcd_send_nibble(n >> 4); lcd_send_nibble(n & 0xf); } void lcd_init() { BYTE i; set_tris_d(LCD_WRITE); lcd.rs = 0; lcd.rw = 0; lcd.enable = 0; delay_ms(15); for(i=1;i<=3;++i) { lcd_send_nibble(3); delay_ms(5); } lcd_send_nibble(2); for(i=0;i<=3;++i) lcd_send_byte(0, LCD_INIT_STRING[i]); } void lcd_gotoxy( BYTE x, BYTE y) { BYTE address; switch(y) { case 1 : address=0x80;break; case 2 : address=0xc0;break; case 3 : address=0x94;break; case 4 : address=0xd4;break; } address+=x-1; lcd_send_byte(0,address); } void lcd_putc( char c) { switch (c) { case '\f' : lcd_send_byte(0,1); lcdline=1; delay_ms(2); break; case '\n' : lcd_gotoxy(1,++lcdline); break; case '\b' : lcd_send_byte(0,0x10); break; default : lcd_send_byte(1,c); break; } } char lcd_getc( BYTE x, BYTE y) { char value; lcd_gotoxy(x,y); lcd.rs=1; value = lcd_read_byte(); lcd.rs=0; return(value); } //================================================== ================================= // CHÚC VUI HA. |
|
![]() |
![]() |
![]() |
#3 |
Nhập môn đệ tử
Tham gia ngày: Sep 2010
Bài gửi: 4
: |
em moi tim hieu ve pic va lcd,cac bac nao co tai lieu ve lcd thi pót len cho em voi nha.e thanks rat
nhiu. |
![]() |
![]() |
![]() |
#4 |
Đệ tử 1 túi
Tham gia ngày: Sep 2010
Bài gửi: 12
: |
oh thanks pác xuan_86 nhé. :d
|
![]() |
![]() |
![]() |
#5 |
Nhập môn đệ tử
Tham gia ngày: Apr 2008
Bài gửi: 8
: |
Có cái code hiển thị thôi mà dài dữ bác,kiểu này còn xử lý...nữa thì chắc khiếp đây.hic
|
![]() |
![]() |
![]() |
#6 |
Đệ tử 1 túi
Tham gia ngày: Sep 2010
Bài gửi: 12
: |
tình hình là về test thử mà hok chạy, khổ thê hehe
|
![]() |
![]() |
![]() |
#7 | |
Đệ tử 4 túi
|
Trích:
http://www.mediafire.com/?8r1m29aeo6af9 Code:
#include "16f877.h" #include "def_877a.h" #fuses XT,NOWDT,NOPROTECT,NOLVP #use delay(clock=4000000) #use fast_io(b) #use fast_io(d) #define RS RD0 #define RW RD1 #define E RD2 #define LCD PORTB //LCD duoc dieu khien qua PORTB int i=0; const unsigned char key[]="LCD VA PIC16F877"; void comwrt(void) //ghi lenh ra LCD { RS=0; RW=0; E=1; E=0; delay_ms(1); } void datawrt(void) //ghi data ra LCD { RS=1; RW=0; E=1; E=0; delay_ms(1); } void initLCD(void) //Khoi tao gia tri dau cho LCD { LCD=0x38; comwrt(); LCD=0x0C; comwrt(); LCD=0x06; comwrt(); delay_ms(1); } void LCD_count() //dem thoi gian 15s cho cac den xanh-Do {i=0; While(i<=16) { LCD=key[i]; datawrt(); i=i+1; delay_ms(1000); //xuat lan luot 2 ki tu ra LCD } } void main(void) { While(1) { int j=0; set_tris_B(0); PORTB=0; set_tris_D(0); PORTD=0; initLCD(); //khoi tao LCD LCD_count(); delay_ms(1000); While(j<=16) { LCD=0b00011100; comwrt(); delay_ms(1000); j=j+1; } LCD=0x01; comwrt(); delay_ms(1000); } } |
|
![]() |
![]() |
![]() |
#8 |
Nhập môn đệ tử
Tham gia ngày: Nov 2010
Bài gửi: 4
: |
Mình có đoạn code dịch LCD này , thấy cũng giống trên bảng điện tử :d
Code:
#include <16f887.h> #fuses XT,NOWDT,NOPROTECT #use delay(clock=4000000) #define LCD_ENABLE_PIN PIN_E0 #define LCD_RS_PIN PIN_E1 #define LCD_RW_PIN PIN_E2 #define LCD_DATA4 PIN_D4 #define LCD_DATA5 PIN_D5 #define LCD_DATA6 PIN_D6 #define LCD_DATA7 PIN_D7 #include <lcd.c> unsigned char text[] = "LCD-PIC16F887"; int8 i = 0 , j = 0 , col = 2; void main() { lcd_init(); while(true) { if (j<=12) { lcd_gotoxy(1,1); for (i=12-j;i<=12;i++) lcd_putc (text[i]); } if ((j>=13)&&(j<=15)) { lcd_gotoxy(col,1); lcd_putc ("LCD-PIC16F887"); col++; } if ((j>=16)&&(j<=27)) { lcd_gotoxy(col,1); for(i=0;i<=27-j;i++) lcd_putc (text[i]); col++; } delay_ms(100); lcd_putc ("\f"); delay_ms (1); j++; if (j==28) { j=0; col=2; } } } |
![]() |
![]() |
![]() |
#9 |
Đệ tử 4 túi
|
[QUOTE=knd07;40056]Mình có đoạn code dịch LCD này , thấy cũng giống trên bảng điện tử
Bạn có sơ đồ phần cứng không!cho mình xin luôn đi!Không có sơ đồ phần cứng đọc khó hiểu!
__________________
My blog: http://autumnneverreturn.blogspot.com/ Đối thủ khó chiến thắng nhất là bản thân !!! |
![]() |
![]() |
![]() |
#10 |
Nhập môn đệ tử
Tham gia ngày: Nov 2010
Bài gửi: 4
: |
Kết nối chân như mình define trong chương trình đó bạn , đường dữ liệu chỉ dùng 4 bit cao của lcd ( D4-> D7 ). Nếu muốn thay đổi phần cứng cho phù hợp , bạn có thể chỉnh sửa lại #define
|
![]() |
![]() |
![]() |
#11 |
Đệ tử 1 túi
Tham gia ngày: Sep 2010
Bài gửi: 12
: |
Đúng thứ mình cần, nhưng cần phát triển thêm tí nữa. thanks pác rùi nhá hí hí
![]() |
![]() |
![]() |
![]() |
#12 |
Đệ tử 4 túi
|
|
![]() |
![]() |
![]() |
#13 |
Đệ tử 1 túi
Tham gia ngày: Sep 2010
Bài gửi: 12
: |
|
![]() |
![]() |
![]() |
#14 |
Nhập môn đệ tử
Tham gia ngày: Sep 2010
Bài gửi: 4
: |
Bác nào biết cách chạy một dòng chữ từ bên này qua bên kia màn hình cua LCD không chỉ giáo cho em với, em viết mãi mà nó cứ đứng yên một chổ, mới vào nghề nên còn lơ mơ lắm. VD như hiển thị dòng chữ "PICVIETNAM!" chẳng hạn. Cho em thanks trước.
|
![]() |
![]() |
![]() |
#15 | |
Đệ tử 4 túi
|
Trích:
![]() |
|
![]() |
![]() |
![]() |
|
|