![]() |
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> :D |
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. |
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. |
oh thanks pác xuan_86 nhé. :d
|
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
|
tình hình là về test thử mà hok chạy, khổ thê hehe
|
Trích:
http://www.mediafire.com/?8r1m29aeo6af9 Code:
#include "16f877.h" |
Đú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í :D
|
Trích:
|
Trích:
|
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.
|
Trích:
|
nhờ giúp đỡ
1 Attachment(s)
mấy ngày này mình bận quá nên giờ mới vào được.
code va mạch mình đính kèm rồi đó.thanks' sao khong up được mạch.mạch đơn giản thôi. chân D0 đến D7 của LCD nối với chân RC0 đến RD7. RS nối với RB5 RW nối với RB6 E nối với RB7 có gì liên lạc với mình qua "anhbaobkdn@gmail.com" cảm ơn nhiều! |
Trích:
Code:
#include <16f877a.h> http://www.mediafire.com/?729kml5lg755g |
có bạn nào có thể viết một chưong trình chay chữ dich phải liên tục trên LCD từ trá1 qua phải không.Trong LCD có lệnh dịch phải nhưng nó không dịch phải như theo ý của mình(ý mình muốn nói là dòng chự phải chạy liên tục từ trái qua phải giống như mấy dòng chữ trên các bảng điện tử ngoài đường ấy!!!)
|
Múi giờ GMT. Hiện tại là 07:30 PM. |
Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam