[Atmel] 用ASF跑SAMD21程序(30) SPILED

[复制链接]
1068|0
 楼主| ddllxxrr 发表于 2015-2-9 22:27 | 显示全部楼层 |阅读模式
首先,建立ASF工程,然后选SAMD21开发板。然后加入OLED模块:



然后加入以下代码:

  1. #include <asf.h>

  2. int main(void)
  3. {
  4.         //! the page address to write to
  5.         uint8_t page_address;
  6.         //! the column address, or the X pixel.
  7.         uint8_t column_address;
  8.         //! store the LCD controller start draw line
  9.         uint8_t start_line_address = 0;

  10.         system_init();
  11.         delay_init();

  12.         // Initialize SPI and SSD1306 controller
  13.         ssd1306_init();

  14.         // set addresses at beginning of display
  15.         ssd1306_set_page_address(0);
  16.         ssd1306_set_column_address(0);

  17.         // fill display with lines
  18.         for (page_address = 0; page_address <= 8; page_address++) {
  19.                 ssd1306_set_page_address(page_address);
  20.                 for (column_address = 0; column_address < 128; column_address++) {
  21.                         ssd1306_set_column_address(column_address);
  22.                         /* fill every other pixel in the display. This will produce
  23.                         horizontal lines on the display. */
  24.                         ssd1306_write_data(0x0f);
  25.                 }
  26.         }

  27.         // scroll the display using hardware support in the LCD controller
  28.         while (true) {
  29.                 ssd1306_set_display_start_line_address(start_line_address++);
  30.                 delay_ms(250);
  31.         }
  32. }
其管脚定义在config里。

  1. #ifndef CONF_SSD1306_H_INCLUDED
  2. #define CONF_SSD1306_H_INCLUDED

  3. #include <board.h>

  4. // Interface configuration for SAM D21 Xplained Pro
  5. #  define SSD1306_SPI                 EXT3_SPI_MODULE
  6. #  define CONFIG_SSD1306_FRAMEBUFFER

  7. #  define SSD1306_DC_PIN              EXT3_PIN_5
  8. #  define SSD1306_RES_PIN             EXT3_PIN_10
  9. #  define SSD1306_CS_PIN              EXT3_PIN_15

  10. #  define SSD1306_SPI_PINMUX_SETTING  EXT3_SPI_SERCOM_MUX_SETTING
  11. #  define SSD1306_SPI_PINMUX_PAD0     EXT3_SPI_SERCOM_PINMUX_PAD0
  12. #  define SSD1306_SPI_PINMUX_PAD1     PINMUX_UNUSED
  13. #  define SSD1306_SPI_PINMUX_PAD2     EXT3_SPI_SERCOM_PINMUX_PAD2
  14. #  define SSD1306_SPI_PINMUX_PAD3     EXT3_SPI_SERCOM_PINMUX_PAD3

  15. // Minimum clock period is 50ns[url=home.php?mod=space&uid=517595]@3.3V[/url] -> max frequency is 20MHz
  16. #define SSD1306_CLOCK_SPEED           1000000UL
  17. #define SSD1306_DISPLAY_CONTRAST_MAX  40
  18. #define SSD1306_DISPLAY_CONTRAST_MIN  30

  19. #endif /* CONF_SSD1306_H_INCLUDED */
运行效果如下:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2404

主题

7001

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部