giúp đỡ LCD ghép với 30F4011
1 Attachment(s)
Em đang làm ví dụ về LCD, mà ko tài nào xuất ra được, em dùng 30F4011, file em gửi kèm, anh em gỡ rối hộ em với. Em dùng CCS
thanks các bác nhiều |
Trích:
Thân, |
code này em lấy ở bên dientuvietnam, và chạy rất ngon với 16F877a, em chỉ define lại chân để dùng cho 30F4011 thôi anh ah, nhung lạ 1 cái là em nạp chuong trình vào chip thì chân Rs và E nó cứ phát xung mãi ko dừng, ngắt nguồn thì với dừng.
Em ko jai thích được hiện tựong này, anh giúp em với |
Trích:
Thân, |
Trích:
void main() { OUTPUT_LOW(PIN_B8); trisB = 0x00; trisC = 0x00; trisD = 0x00; trisE = 0x00; LCD_init(); Printf(LCD_putchar," PICVIETNAM tut"); LCD_putcmd(0xC3); Printf(LCD_putchar," LCD 4bit "); while(1) {} } em cũng chả hiểu sao nữa, làm đủ mọi cách mà ko giao tiếp dc với LCD, thế chương trình của em có bị lỗi ko anh |
tiện đây bác cho em hỏi luôn, để đổi chân theo ý mình trong đoặn này để dùng LCD thì mình đổi chỗ nào ah
/////////////////////////////////////////////////////////////////////////// //// LCDD.C //// //// Driver for common 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,2007 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 D3 is not used. // Un-comment the following define to use port B // #define use_portb_lcd TRUE 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; #if defined use_portb_lcd //#locate lcd = getenv("sfr:PORTB") // This puts the entire structure over the port #ifdef __pch__ #locate lcd = 0xf81 #else #locate lcd = 6 #endif #define set_tris_lcd(x) set_tris_b(x) #else //#locate lcd = getenv("sfr:PORTD") // This puts the entire structure over the port #ifdef __pch__ #locate lcd = 0xf83 #else #locate lcd = 8 #endif #define set_tris_lcd(x) set_tris_d(x) #endif #ifndef lcd_type #define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines #endif #define lcd_line_two 0x40 // LCD RAM address for the second line 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 lcd_read_byte() { BYTE low,high; set_tris_lcd(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_lcd(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_lcd(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; if(y!=1) address=lcd_line_two; else address=0; address+=x-1; lcd_send_byte(0,0x80|address); } void lcd_putc( char c) { switch (c) { case '\f' : lcd_send_byte(0,1); delay_ms(2); break; case '\n' : lcd_gotoxy(1,2); 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); while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low lcd.rs=1; value = lcd_read_byte(); lcd.rs=0; return(value); } |
Bác cho em hỏi 1 câu nữa, em dùng chương trình ở forum của CCS về và đã hiện chữ thành công trên LCD, file em gửi kèm, nhưng có 1 điều là ở hàm main em viết như này
void main() { trisB = 0x00; trisC = 0x00; trisD = 0x00; trisE = 0x00; lcd_init(); // Always call this first. lcd_putc("\fNGUYEN THE TUNG\n"); lcd_gotoxy(4,2); lcd_putc("DTD45-DH1"); while(1) { LATE3 = 0; delay_ms(250); LATE3 = 1; delay_ms(250); } } hiện tượng xảy ra là led nháy theo đúng như code trong khoảng 20s, rồi sáng liên tục trong khoảng 4s, đòng thời chữ trên LCD nhảy loạn trong 4s đó, hết 4s lại hiện chữ bình thường, và led lại nháy ngon. Chu kì cứ lặp lại như thế. Tại sao lại thế hả bac, hay dó em cấu hình ko đúng, em dùng thạch anh 11,0592 Mhz. Em mong chờ bác từng h |
Trích:
Tại sao bạn không thử với tutorial 3 cho dsPIC, có code và mạch đã được thử nghiệm thực tế, và chưa thấy ai phản ánh rằng nó có lỗi. Thân, |
Trích:
Thân, |
Trích:
Thân, |
1 Attachment(s)
Trích:
Thanks |
Bạn bỏ đoạn lệnh #include "def_30F4011.h" đi, tạm thời dùng toàn bộ hàm chuẩn của CCS trước. Hàm main viết như bên dưới.
Bạn dùng lại cái thư viện lcd_lib_4bit.c của tôi, cái đó hoàn toàn đúng, không sai được, tôi dùng nó mấy năm nay rồi, chạy tốt. Code:
void main() |
bác linh ơi, em làm theo như bác mà vẫn ko được, có lẽ thư viện của bác ko dùng được cho dspic, nhung mà em tắt WDT rồi mà vẫn bị hiện tượng cái led mắc ở chân Ẻ nháy 1 lúc theo đúng code rồi đúng lại 1 lúc, rồi nháy tiếp, và các chân Rs, E ... vẫn phát xung bác ah. Thật khó hiểu quá
Em ko thấy biểu tượng viết code của diễn đàn, nên em phải cop code vào đây, mong mod thông cảm Code: #include <30F4011.h> #FUSES NOWDT //No Watch Dog Timer #FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD) #FUSES PR //Promiary Oscillator #FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled #FUSES WPSB16 //Watch Dog Timer PreScalar B 1:16 #FUSES WPSA512 //Watch Dog Timer PreScalar A 1:512 #FUSES PUT64 //Power On Reset Timer value 64ms #FUSES NOBROWNOUT //No brownout reset #FUSES BORV47 //Brownout reset at 4.7V #FUSES LPOL_HIGH //Low-Side Transistors Polarity is Active-High (PWM 0,2,4 and 6) //PWM module low side output pins have active high output polar #FUSES HPOL_HIGH //High-Side Transistors Polarity is Active-High (PWM 1,3,5 and 7) //PWM module high side output pins have active high output polarity #FUSES NOPWMPIN //PWM outputs drive active state upon Reset #FUSES MCLR //Master Clear pin enabled #FUSES NOPROTECT //Code not protected from reading #FUSES NOWRT //Program memory not write protected #FUSES NODEBUG //No Debug mode for ICD #FUSES NOCOE //Device will reset into operational mode #FUSES ICS0 //ICD communication channel 0 #FUSES RESERVED //Used to set the reserved FUSE bits #use delay(clock=11059200) #include <lcd_lib_4bit.c> void main() { // Set Output set_tris_b(0x00); set_tris_c(0x00); set_tris_d(0x00); set_tris_e(0x00); // Init LCD, 4bit mode lcd_init(); // Always call this first. lcd_putcmd(1); // Clear LCD //lcd_putc("\fNGUYEN THE TUNG\n"); // Vi?t nhu th? này là sai, vì hàm lcd_putc ch? nh?n d?i s? là 1 byte char printf(lcd_putchar,"NGUYEN THE TUNG"); lcd_putcmd(0xC0 + 4); // hàng 2 c?t 4 //lcd_putc("DTD45-DH1"); printf(lcd_putchar,"DTD45-DH1"); while(1) { output_low(PIN_E3); delay_ms(250); output_high(PIN_E3); delay_ms(250); } } |
Trích:
http://www.picvietnam.com/forum/showthread.php?t=2610 Thân, |
Trích:
|
Múi giờ GMT. Hiện tại là 11:34 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