RP Store Tìm linh kiện theo mã, gửi BOM nhận báo giá Gửi BOM

Dạy bang chủ học PIC18

Collapse
This is a sticky topic.
X
X
 
  • Giờ
  • Show
Clear All
new posts
  • caremlanh
    Đệ tử 3 túi
    • Jul 2010
    • 52

    #136
    Nguyên văn bởi QUOC_DUNG-NVN
    Dạo này không ai dạy ban chủ học pic nữa àh. có lẽ đã "nội công thâm hậu rồi", vậy có ai giúp mình không vậy???????????????

    buồn quá đã lâu lắm rồi nhưng k ai trả lời hết
    Bạn mở thư mục MPASM Suite, mở 2 file P18F1320.INC và P18f4520.INC
    Trong 2 file đó tìm đến đoạn nói về OSC (khoảng gần cuối) và so sánh các thanh ghi, kết quả như sau
    FSCM -> FCMEN
    BOR -> BOREN
    STVR -> STVREN
    INTIO2 -> INTIO67

    Sau đó tìm đoạn CONFIG, thì thấy giá trị khác nhau ở đây thôi

    _BOR_ON_2L EQU H'FF' ; Brown-out Reset enabled
    _BOR_OFF_2L EQU H'FD' ; Brown-out Reset disabled

    _BOREN_OFF_2L EQU H'F9' ; Brown-out Reset disabled in hardware and software
    _BOREN_ON_2L EQU H'FB' ; Brown-out Reset enabled and controlled by software

    Các thanh ghi kia tên thì khác nhưng giá trị ON, OFF giống nhau
    Chúc bạn thành công. Bạn nên đưa code lên thì dễ kiểm tra hơn nha
    Last edited by caremlanh; 16-04-2011, 03:28 PM.

    Comment

    • caremlanh
      Đệ tử 3 túi
      • Jul 2010
      • 52

      #137
      gửi project lun đi bạn
      bạn để code ở trên trong thẻ
      Code:
      [ code]...[ /code]
      đi, để vậy dài quá đọc hoa mắt @-)

      Comment

      • caremlanh
        Đệ tử 3 túi
        • Jul 2010
        • 52

        #138
        mail minh đi quangtri7121@gmail.com
        yahoo thì dưới avatar đó

        Comment

        • headman8x
          Nhập môn đệ tử
          • May 2010
          • 6

          #139
          giao tiếp pic8f4550 với LCD 4x16

          Chào tất cả mọi người!
          Các bạn giúp mình cách đổi Port xuất dữ liệu từ thư viện LCD420.c với.
          hiện tại trong thư viện LCD420.C của trình biên dịch CCS complier mặc định PortB xuất dữ liệu ra LCD 4x16 . Bây giờ mình muốn thay portB bằng PortD cho phù hợp với bài toán của mình , mình đã thử nhưng không đúng. Mong mọi người giúp đỡ

          cảm ơn tất cả !

          ////////////////////////////////////////////////////////////////////////////
          //// 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:
          // B0 enable
          // B1 rs
          // B2 rw
          // B4 D4
          // B5 D5
          // B6 D6
          // B7 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 = 6 // 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_b(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_b(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_b(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=0x90;break;
          case 4 : address=0xd0;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);
          }

          Comment

          • hc.coltech
            Nhập môn đệ tử
            • Nov 2010
            • 7

            #140
            Các pro giúp hộ cái..em dùng pic 18F2550 định built ra file .hex nhưng không có thư viện của p18cxxx.h nên ko built được ..pro nào có share cho với ...thanks nhiều

            Comment

            • pdkxlily
              Đệ tử 2 túi
              • Mar 2011
              • 27

              #141
              mình đang làm mạch nạp dùng con 18f4550 giao tiếp usb . bạn nào share mình đc ko

              Comment

              • nhat_minh1
                Nhập môn đệ tử
                • Sep 2010
                • 8

                #142
                vậy ma nói học lại tu đầu

                Comment

                • nhat_minh1
                  Nhập môn đệ tử
                  • Sep 2010
                  • 8

                  #143
                  mọi người viết từng đoạn code cơ bản + mạch (có kèm chu thích nha)
                  gửi lên cho em học với,
                  bất đầu bằng việc điều khiển led trước di
                  thanks cả nhà

                  Comment

                  • trungduc
                    Đệ tử 2 túi
                    • Oct 2008
                    • 44

                    #144
                    Mình mới mua 1 con pic18f4550 về học tài liệu về con này ít so với 16f877a. Mình bắt đầu bằng bài bật tắt LED nhưng vẫn chưa được. Các bạn nhiệt tình cho mình 1 đoạn code về tham khảo với. (ASM nha ).
                    Cảm ơn nhiều!

                    Comment

                    • kyanh911
                      Đệ tử 1 túi
                      • Jan 2010
                      • 11

                      #145
                      trungduc: hoc asm làm chi cho khổ....xài ccs đi bác ơi

                      Comment

                      • kyanh911
                        Đệ tử 1 túi
                        • Jan 2010
                        • 11

                        #146
                        em có đoạn code này giao tiếp lcd 4bit đã chạy ổn định....chân rs,rw,e đã nói trong code. còn chân D7 của LCD nối chân RB0, D6 nối RB1, D5 nối RB2, D4 nối RB3

                        #include<18f4550.h>
                        #fuses nowdt,hs,noprotect,nolvp
                        #use delay(clock=20000000)
                        #use fast_io(b)
                        #define rs pin_b7
                        #define rw pin_b6
                        #define e pin_b5

                        int8 dao(int8 xx)
                        {
                        int8 buff;
                        buff=0;
                        buff+=(xx>>7)&0x01;
                        buff+=(xx>>5)&0x02;
                        buff+=(xx>>3)&0x04;
                        buff+=(xx>>1)&0x08;

                        buff+=(xx<<1)&0x10;
                        buff+=(xx<<3)&0x20;
                        buff+=(xx<<5)&0x40;
                        buff+=(xx>>7)&0x80;
                        return buff;
                        }

                        void ghilenh(int8 malenh)
                        {
                        int8 tam;
                        tam=dao(malenh);
                        output_b(tam&0xf); //xuat 4 bit cao truoc
                        output_low(rs); //chon thanh ghi lenh
                        output_low(rw); //cho phep ghi
                        delay_us(2);
                        output_high(e);
                        delay_us(5);
                        output_low(e);
                        delay_us(500);

                        output_b(tam>>4); //xuat 4 bit thap sau
                        output_low(rs);
                        output_low(rw);
                        delay_us(2);
                        output_high(e);
                        delay_us(5);
                        output_low(e);
                        delay_us(500);
                        }

                        void ghikytu(int8 makytu)
                        {
                        int8 tam;
                        tam=dao(makytu);
                        output_b(tam&0xf);
                        output_high(rs);
                        output_low(rw);
                        delay_us(2);
                        output_high(e);
                        delay_us(5);
                        output_low(e);
                        delay_us(500);

                        output_b(tam>>4);
                        output_high(rs);
                        output_low(rw);
                        delay_us(2);
                        output_high(e);
                        delay_us(5);
                        output_low(e);
                        delay_us(500);
                        }
                        void khoitaolcd()
                        {
                        ghilenh(0x28);
                        ghilenh(0x28); //mã 28 chu k phai 38
                        delay_ms(10);
                        ghilenh(0x28); //vi giao tiep 4 bit
                        delay_ms(10);

                        ghilenh(0x28);
                        delay_ms(1);
                        ghilenh(0x0c);
                        delay_ms(1);
                        ghilenh(0x01);
                        delay_ms(1);
                        ghilenh(0x06);
                        delay_ms(100);
                        }
                        main()
                        {
                        set_tris_b(0x00);
                        khoitaolcd();
                        ghikytu('N');
                        ghikytu('b');
                        }


                        Vấn đề thắc mắc ở đây là sao đưa qua port D thì lại hổng chạy?

                        Comment

                        Working...