[Hiển thị] Cho mình xin file lcd_lib_4bit.c

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • nbb3i
    Thành viên tích cực
    • Dec 2007
    • 540

    #1

    [Hiển thị] Cho mình xin file lcd_lib_4bit.c

    Mình lập trình cho PIC sử dụng CCS C bản 4.0.38 nhưng trong thư viện của nó thiếu mất file trên. Bạn nào có thể gửi cho mình được không?
    Nếu có thể thì send qua mail vào nbb3i@hotmail.com giúp mình nhé! Xin cảm ơn!
    123...
  • chestnut
    Thành viên tích cực
    • Jun 2008
    • 400

    #2
    Nguyên văn bởi nbb3i Xem bài viết
    Mình lập trình cho PIC sử dụng CCS C bản 4.0.38 nhưng trong thư viện của nó thiếu mất file trên. Bạn nào có thể gửi cho mình được không?
    Nếu có thể thì send qua mail vào nbb3i@hotmail.com giúp mình nhé! Xin cảm ơn!
    Đây là file của tớ hay sài.Hy vọng giúp dc cậu
    The goal of power electronics is control the flow of energy from an electrical source to an electrical load with high efficiency, high availability, high reliability, light weight and low cost.

    Comment

    • chestnut
      Thành viên tích cực
      • Jun 2008
      • 400

      #3
      Nhớ sửa lại file lcd.h cho phù hợp nhé.
      Attached Files
      The goal of power electronics is control the flow of energy from an electrical source to an electrical load with high efficiency, high availability, high reliability, light weight and low cost.

      Comment

      • nbb3i
        Thành viên tích cực
        • Dec 2007
        • 540

        #4
        Cảm ơn bạn đã gửi file thư viện cho mình.
        Nhưng tớ phải sửa gì ở file lcd.h vậy?
        Mình chỉ thấy trong thư viện noc có file lcd.c với những hàm sau
        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


        #define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
        #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);
        }
        Mọi người viết chương trình lại khai báo sử dụng thư việ lcd_lib_4bit.c. Mình mới học về lập trình C cho PIC nên muốn xem ví dụ qua các bài đó để dễ dàng học hơn. Nhưng khi chạy thì nó báo thiếu file đó. Hình như trong cái lcd_lib_4bit.c nó có thêm mấy cái hàm lcd_putcmd() hay sao ấy. Bạn nào có thể nói rõ giúp mình là hàm lcd_putcmd() nó khác gì hàm lcd_putchar() không?
        Đây là hàm lcd_putchar()
        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;
        }
        123...

        Comment

        • linhnc308
          Moderator
          • Aug 2005
          • 1084

          #5


          Bạn vào theo link trên để load các file bạn cần. File lcd_lib_4bit.c tôi viết ra dùng để giao tiếp với LCD. Trong đó đã có đủ hàm khởi tạo, ghi lệnh, ghi dữ liệu cho LCD. Bạn có thể từ đó phát triển thêm các hàm khác như dịch con trỏ, dịch chữ...
          Ethernet-RS232, PIC Webserver, RFID Reader
          CallerID, Cảnh báo BTS, ...
          0988006696
          linhnc308@gmail.com
          http://linhnc308.blogspot.com

          Comment

          • chestnut
            Thành viên tích cực
            • Jun 2008
            • 400

            #6
            Nguyên văn bởi linhnc308 Xem bài viết
            http://linhnc308.googlepages.com/myprojects

            Bạn vào theo link trên để load các file bạn cần. File lcd_lib_4bit.c tôi viết ra dùng để giao tiếp với LCD. Trong đó đã có đủ hàm khởi tạo, ghi lệnh, ghi dữ liệu cho LCD. Bạn có thể từ đó phát triển thêm các hàm khác như dịch con trỏ, dịch chữ...
            Trong hàm LCD của em cung cấp cũng có đầy đủ những thứ đó chứ ạ.
            The goal of power electronics is control the flow of energy from an electrical source to an electrical load with high efficiency, high availability, high reliability, light weight and low cost.

            Comment

            • chestnut
              Thành viên tích cực
              • Jun 2008
              • 400

              #7
              Nguyên văn bởi nbb3i Xem bài viết
              Cảm ơn bạn đã gửi file thư viện cho mình.
              Nhưng tớ phải sửa gì ở file lcd.h vậy?
              Mình chỉ thấy trong thư viện noc có file lcd.c với những hàm sau
              Thì bạn phải sửa lại khai báo chân cho LCD của bạn chứ.Thư viện này là thư viện chuẩn dành cho tất cả các MCU.Bạn đọc code sẽ hiểu thôi mà.Cũng đơn giản lắm
              The goal of power electronics is control the flow of energy from an electrical source to an electrical load with high efficiency, high availability, high reliability, light weight and low cost.

              Comment

              • nbb3i
                Thành viên tích cực
                • Dec 2007
                • 540

                #8
                Hì hì! Cảm ơn anh linhnc308, cảm ơn bạn chestnut!
                Mình đã tìm được file cần thiết rùi. 2 hôm vọc vạch học lập trình cho LCD với lại giao tiếp RS232 thấy vỡ ra nhiều quá. Rất mừng là mình có cả 1 cộng đồng để hỏi)
                123...

                Comment

                • babybaby002
                  Thành viên mới
                  • Nov 2010
                  • 1

                  #9
                  Nguyên văn bởi nbb3i Xem bài viết
                  Hì hì! Cảm ơn anh linhnc308, cảm ơn bạn chestnut!
                  Mình đã tìm được file cần thiết rùi. 2 hôm vọc vạch học lập trình cho LCD với lại giao tiếp RS232 thấy vỡ ra nhiều quá. Rất mừng là mình có cả 1 cộng đồng để hỏi)
                  bạn ơi, bạn có thể post file lcd_lib_4bit.c lên cho mình với đc ko? hay bạn gửi vào mail của mình cũng đc, bnktunganh@gmail.com, thanks.

                  Comment

                  • ctrang
                    Thành viên mới
                    • Jan 2012
                    • 1

                    #10
                    bạn nào có file lcd_lib_4bit.c cho mình xin với.gmail congtrang1505@gmail.com
                    thanks

                    Comment

                    • chung1608
                      Thành viên tích cực
                      • Sep 2009
                      • 4160

                      #11
                      Nguyên văn bởi ctrang Xem bài viết
                      bạn nào có file lcd_lib_4bit.c cho mình xin với.gmail congtrang1505@gmail.com
                      thanks
                      CCS :: View topic - Flexible LCD driver

                      Comment

                      • quangnhat
                        Thành viên tích cực
                        • Jul 2005
                        • 940

                        #12
                        //#include <stddef.h>

                        #define LCD_RS PIN_B5
                        //#define LCD_RW PIN_B1
                        #define LCD_EN PIN_B4

                        #define LCD_D4 PIN_B3
                        #define LCD_D5 PIN_B2
                        #define LCD_D6 PIN_B1
                        #define LCD_D7 PIN_B0

                        // misc display defines-
                        #define Line_1 0x80
                        #define Line_2 0xC0
                        #define Clear_Scr 0x01

                        // prototype statements
                        #separate void LCD_Init ( void );// ham khoi tao LCD
                        #separate void LCD_PutChar ( unsigned int cX );// Ham viet1kitu/1chuoi len LCD
                        #separate void LCD_PutCmd ( unsigned int cX) ;// Ham gui lenh len LCD
                        #separate void LCD_PulseEnable ( void );// Xung kich hoat
                        #separate void LCD_SetData ( unsigned int cX );// Dat du lieu len chan Data
                        // D/n Cong

                        #use standard_io (B)
                        //#use standard_io (D)

                        //khoi tao LCD**********************************************
                        #separate void LCD_Init ( void )
                        {
                        LCD_SetData ( 0x00 );
                        // output_low ( LCD_RW );// che do gui lenh
                        delay_ms(50); /* wait enough time after Vdd rise >> 15ms */
                        output_low ( LCD_RS );// che do gui lenh
                        LCD_SetData ( 0x03 ); /* init with specific nibbles to start 4-bit mode */
                        LCD_PulseEnable();
                        LCD_PulseEnable();
                        LCD_PulseEnable();
                        LCD_SetData ( 0x02 ); /* set 4-bit interface */
                        LCD_PulseEnable(); /* send dual nibbles hereafter, MSN first */
                        LCD_PutCmd ( 0x2C ); /* function set (all lines, 5x7 characters) */
                        LCD_PutCmd ( 0x0C ); /* display ON, cursor off, no blink */
                        LCD_PutCmd ( 0x06 ); /* entry mode set, increment & scroll left */
                        LCD_PutCmd ( 0x01 ); /* clear display */
                        }
                        #separate void LCD_PutChar ( unsigned int cX )
                        {
                        /* this subroutine works specifically for 4-bit Port A */
                        output_high ( LCD_RS );
                        LCD_PutCmd( cX );
                        output_low ( LCD_RS );
                        }

                        #separate void LCD_PutCmd ( unsigned int cX )
                        {
                        /* this subroutine works specifically for 4-bit Port A */
                        LCD_SetData ( swap ( cX ) ); /* send high nibble */
                        LCD_PulseEnable();
                        LCD_SetData ( swap ( cX ) ); /* send low nibble */
                        LCD_PulseEnable();
                        }
                        #separate void LCD_PulseEnable ( void )
                        {
                        output_high ( LCD_EN );
                        delay_us ( 3 ); // was 10
                        output_low ( LCD_EN );
                        delay_ms ( 3 ); // was 5
                        }

                        #separate void LCD_SetData ( unsigned int cX )
                        {
                        output_bit ( LCD_D4, cX & 0x01 );
                        output_bit ( LCD_D5, cX & 0x02 );
                        output_bit ( LCD_D6, cX & 0x04 );
                        output_bit ( LCD_D7, cX & 0x08 );
                        }
                        Quang Nhat
                        ---------------------------------------
                        Yahoo :quangnhat85ls
                        Mail :
                        Nhận thiết kế và ép nhựa cho đồ điện tử

                        Comment

                        • quangnhat
                          Thành viên tích cực
                          • Jul 2005
                          • 940

                          #13
                          lưu lại thành dạng lcd_lib_4bit.c ) nhá
                          Quang Nhat
                          ---------------------------------------
                          Yahoo :quangnhat85ls
                          Mail :
                          Nhận thiết kế và ép nhựa cho đồ điện tử

                          Comment

                          • thenam
                            Thành viên mới
                            • Nov 2013
                            • 3

                            #14
                            anh ! thu vien nay bi loi "separate" la sao anh

                            Comment

                            • thenam
                              Thành viên mới
                              • Nov 2013
                              • 3

                              #15
                              a/c cho minh xin thu vien "lcd_lib_4bit1.c"
                              code em co dung "LCD_putchar" va "LCD_putcmd"
                              minh da tai cac file o tren ve roi nhung van k dich duoc hai ham tren.
                              minh cam on cac a/c
                              mail: cubom_sg@yahoo.com.vn

                              Comment

                              Về tác giả

                              Collapse

                              nbb3i Tìm hiểu thêm về nbb3i

                              Bài viết mới nhất

                              Collapse

                              Đang tải...