![]() |
|
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 |
Đệ 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í
![]() |
![]() |
![]() |
![]() |
#9 |
Đệ tử 4 túi
|
|
![]() |
![]() |
![]() |
#10 |
Đệ tử 1 túi
Tham gia ngày: Sep 2010
Bài gửi: 12
: |
|
![]() |
![]() |
![]() |
#11 |
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.
|
![]() |
![]() |
![]() |
#12 | |
Đệ tử 4 túi
|
Trích:
![]() |
|
![]() |
![]() |
![]() |
#13 |
Nhập môn đệ tử
Tham gia ngày: Sep 2010
Bài gửi: 4
: |
nhờ giúp đỡ
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! |
![]() |
![]() |
![]() |
#14 | |
Đệ tử 4 túi
|
Trích:
Code:
#include <16f877a.h> #include <def_877a.h> #device *=16 ADC=8 #FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT #use delay(clock=4000000) //============================================================================= //==========PHAN KHAI BAO PHAN CUNG=========================================== //---------------------------------------------------------------------------- #define rs rb5 #define rw rb6 #define e rb7 //---------------------------------------------------------------------------- //=====PHAN KHAI BAO BIEN===================================================== //----------------------------------------------------------------------------- int8 i,j; //----------------------------------------------------------------------------- //----------------KHAI BAO MANG------------------------------------------------ const unsigned char chu[]={"PICVIETNAM!"}; const unsigned char move[]={"DHBK TPHCM"}; //----------------------------------------------------------------------------- //=============================================================================== //=========================CHUONG TRINH CON====================================== //=============================================================================== void dieukhien(int8 a) { portc=a, rs=0; rw=0; e=1; e=0; delay_ms(100); } void hienthi(int8 a) { portc=a; rs=1; rw=0; e=1; e=0; delay_ms(100); } void lcd_init() { dieukhien(0x38); dieukhien(0x0c); dieukhien(0x06); } //-------------------------------------------------------------------------------------------------------------------------------- //============================================================================ //========================CHUONG TRINH CHINH=================================== void main() { trisb=0x00; trisc=0x00; portb=0x00; portc=0x00; delay_ms(100); lcd_init(); While(1) { j=0x80; while(j<=0x8f) { dieukhien(j); while(i<=10) { hienthi(chu[i]); i++; } j++; i=0; dieukhien(0xc2); while(i<=10) { hienthi(move[i]); i++; } i=0; delay_ms(1000); dieukhien(0x01); } } } http://www.mediafire.com/?729kml5lg755g
__________________
My blog: http://autumnneverreturn.blogspot.com/ Đối thủ khó chiến thắng nhất là bản thân !!! |
|
![]() |
![]() |
![]() |
#15 |
Đệ tử 4 túi
|
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!!!)
__________________
My blog: http://autumnneverreturn.blogspot.com/ Đối thủ khó chiến thắng nhất là bản thân !!! |
![]() |
![]() |
![]() |
|
|