نمایش نتایج: از 1 به 8 از 8

موضوع: ماژول نمایشگر lcd 128 x 64 دارای ارتباط i2c

  1. #1
    مدیر گروه
    تاریخ عضویت
    Nov 2013
    محل سکونت
    ایران
    نوشته ها
    4,064

    ماژول نمایشگر lcd 128 x 64 دارای ارتباط i2c

    ماژول نمایشگر LCD 128 X 64 دارای ارتباط I2C

    ترتیب اتصال پینها :

    Arduino LCD
    6 LED
    7 A0
    8 RST
    9 CS
    11 SDA
    13 SCL
    GND GND
    VCC VCC

    نمونه کد :
    کد:
    
    
    
    #include <U8glib.h>
    
    
    byte ledBacklight = 150;
    const byte lcdLED = 6;                   // LED Backlight
    const byte lcdA0 = 7;                    // Data and command selections. L: command  H : data
    const byte lcdRESET = 8;                 // Low reset
    const byte lcdCS = 9;                    // SPI Chip Select (internally pulled up), active low
    const byte lcdMOSI = 11;                 // SPI Data transmission
    const byte lcdSCK = 13;                  // SPI Serial Clock
    
    
    const byte bufferSize = 60;//32
    
    
    // SW SPI:
    //U8GLIB_MINI12864_2X u8g(lcdSCK, lcdMOSI, lcdCS, lcdA0, lcdRESET);
    // HW SPI:
    U8GLIB_MINI12864_2X u8g(lcdCS, lcdA0, lcdRESET);
    
    
    const byte LINE_MAX = 30;          // setup input buffer
    byte line_buf[LINE_MAX];
    byte line_pos = 0;
    const byte ROW_MAX = 12;           // setup a text screen to support scrolling
    byte screen[ROW_MAX][LINE_MAX];
    byte rows, cols;
    const byte LINE_PIXEL_HEIGHT = 7;  // line height, which matches the selected font (5x7)
    
    
    // Print character arrays to console
    void u8g_print(char* theString) {
      char ch;
      byte i = 0;
      while ((ch = theString[i++]) != '\0') {
    	read_line(ch);
        }
    }
    // Print character arrays with a new line at the end
    void u8g_println(char* theString) {
      u8g_print(theString);
      read_line('\r');
    }
    // Print character arrays saved in program memory to console
    void u8g_print_P( const char  *theString) {
      char ch;
      while ((ch = pgm_read_byte(theString++)) != '\0') {
    	read_line(ch);
        }
    }
    // Print character arrays saved in program memory with a new line at the end
    void u8g_println_P(const char  *theString) {
      u8g_print_P(theString);
      read_line('\r');
    }
    
    
    // Clear entire screen, called during setup
    void clear_screen(void) {
      byte i, j;
      for( i = 0; i < ROW_MAX; i++ )
        for( j = 0; j < LINE_MAX; j++ )
          screen[i][j] = 0;  
    }
    // Append a line to the screen, scroll up
    void add_line_to_screen(void) {
      byte i, j;
      for( j = 0; j < LINE_MAX; j++ )
        for( i = 0; i < rows-1; i++ )
          screen[i][j] = screen[i+1][j];
      
      for( j = 0; j < LINE_MAX; j++ )
        screen[rows-1][j] = line_buf[j];
    }
    // U8GLIB draw procedure: output the screen
    void draw(void) {
      byte i, y;
      // graphic commands to redraw the complete screen are placed here    
      y = 0;       // reference is the top left -1 position of the string
      y--;           // correct the -1 position of the drawStr 
      for( i = 0; i < rows; i++ )
      {
        u8g.drawStr( 0, y, (char *)(screen[i]));
        y += u8g.getFontLineSpacing();
      }
    }
    void exec_line(void) {
      // Add the line to the screen
      add_line_to_screen();
      // U8GLIB picture loop
      u8g.firstPage();  
      do {
        draw();
      } while( u8g.nextPage() );
    }
    // Clear current input buffer
    void reset_line(void) { 
          line_pos = 0;
          line_buf[line_pos] = '\0';  
    }
    // Add a single character to the input buffer 
    void char_to_line(char c) {
          line_buf[line_pos] = c;
          line_pos++;
          line_buf[line_pos] = '\0';  
    }
    // Handle new console character
    void read_line(char c) {
      if ( line_pos >= cols-1 ) {
        exec_line();
        reset_line();
        char_to_line(c);
      } 
      else if ( c == '\n' ) {
        // ignore '\n' 
      }
      else if ( c == '\r' ) {
        exec_line();
        reset_line();
      }
      else {
        char_to_line(c);
      }
    }
    
    
    // From http://playground.arduino.cc/Code/AvailableMemory
    int freeRam () {
      extern int __heap_start, *__brkval; 
      int v; 
      return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
    }
    
    
    void setup()
    {
        char buf[bufferSize];
    
    
        // Turn on LED backlight
        analogWrite(lcdLED, ledBacklight);
    
    
        // Setup U8glib
        u8g.begin();
        u8g.setFont(u8g_font_5x7);    // Set font for the console window
        u8g.setFontPosTop();          // Set upper left position for the string draw procedure
        // Calculate the number of rows for the display
        rows = u8g.getHeight() / u8g.getFontLineSpacing();
        if ( rows > ROW_MAX )
          rows = ROW_MAX;
        // Estimate the number of columns for the display
        cols = u8g.getWidth() / u8g.getStrWidth("m");
        if ( cols > LINE_MAX-1 )
          cols = LINE_MAX-1;
        clear_screen();               // Clear screen
        delay(1000);                  // Delay
        reset_line();                 // Clear input buffer
        
        // Print some information
        u8g_println_P(PSTR("U8glib Fio Console"));
        u8g_println_P(PSTR("semifluid.com"));
        u8g_println_P(PSTR(""));
        u8g_println_P(PSTR("Starting..."));
        u8g_print_P(PSTR("Free Memory: "));
        String(freeRam(),DEC).toCharArray(buf, sizeof(buf));u8g_println(buf);
    }
    
    
    int i = 0;
    void loop()
    {
        char buf[bufferSize];
        
        // Start timer
        unsigned long theStart = micros();
        
        // Display an incrementing counter
        String(i,DEC).toCharArray(buf, sizeof(buf));u8g_print(buf);
        u8g_print_P(PSTR("-"));
        String(i,HEX).toCharArray(buf, sizeof(buf));u8g_print(buf);
        u8g_print_P(PSTR("-"));
        String(i,BIN).toCharArray(buf, sizeof(buf));u8g_print(buf);
        u8g_print_P(PSTR("-"));
        i++;
        
        // Approximate time in microseconds that it took to display the information
        unsigned long theEnd = micros();
        unsigned long delta = theEnd - theStart;
        String(delta,DEC).toCharArray(buf, sizeof(buf));u8g_println(buf);
        
        // No delay, so loop as quickly as possible
    }
    فایل های پیوست شده فایل های پیوست شده

  2. #2
    Member
    تاریخ عضویت
    Jun 2016
    محل سکونت
    ایران عزیر
    نوشته ها
    74
    چرا تو نمونه کد از ارتباط spi استفاده شده

  3. #3
    Junior Member
    تاریخ عضویت
    Aug 2016
    نوشته ها
    12
    سلام . آقا این ال سی دی اصلا روی UNO جواب میده؟ من هر کاری میکنم جواب نمیگیرم
    فقط وقتی نمونه کدی رو که شما نوشتین مینویسم و اپلود میکنم یه مشت اعداد و ارقام با سرعت روی صفحه میان . ولی از طریق فایل پیوست شده کتابخونه و مثالهاش فقط ارور میده .
    خواهش میکنم راهنمایی بفرمایید .
    این هم دو نمونه از ارورها
    نوع اول

    exit status 1
    Error compiling for board Arduino/Genuino Uno.

    نوع دوم

    exit status 1
    'u8g' was not declared in this scope

    قابل توجه که من هیچگونه تغییری در مثالها ندادم ولی باز هم این ارور رو میده

  4. #4
    مدیر گروه
    تاریخ عضویت
    Nov 2013
    محل سکونت
    ایران
    نوشته ها
    4,064
    این فایلها اطلاعاتی هستن که سایت رفرنس در اختیار قرار داده:
    فایل های پیوست شده فایل های پیوست شده

  5. #5
    Junior Member
    تاریخ عضویت
    Oct 2016
    نوشته ها
    2
    خیلی ممنون از کدی که زحمت کشیدید
    عینا توی arduino uno کپی و تست شد

  6. #6
    elf
    elf آنلاین نیست.
    Junior Member
    تاریخ عضویت
    Jan 2016
    نوشته ها
    2
    سلام من آردینو کار نمیکنم ولی اینو راه انداختم بکارتون امد بگید کمک کنمبرای دیدن سایز بزرگ روی عکس کلیک کنید

نام: 13022017008.jpg
مشاهده: 220
حجم: 84.8 کیلو بایت
    ویرایش توسط elf : 02-15-2017 در ساعت 06:47 PM

  7. #7
    Junior Member
    تاریخ عضویت
    Mar 2017
    نوشته ها
    1
    این که بازم ۸ تا پورت استفاده میکنه!!!
    راه افتاد ولی من اگه قرار بود ۸ تا پورت اشغال کنم که این ال سی دی رو نمی خریدم!!!!

  8. #8
    Junior Member
    تاریخ عضویت
    Jan 2014
    نوشته ها
    1
    سلام مهندس لطف میکنی کدت رو به اشتراک بذاری؟

مجوز های ارسال و ویرایش

  • شما نمیتوانید موضوع جدیدی ارسال کنید
  • شما امکان ارسال پاسخ را ندارید
  • شما نمیتوانید فایل پیوست کنید.
  • شما نمیتوانید پست های خود را ویرایش کنید
  •  

SEO by vBSEO