打印
[Atmel]

用ASF跑SAMD21程序(30) SPILED

[复制链接]
798|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
首先,建立ASF工程,然后选SAMD21开发板。然后加入OLED模块:



然后加入以下代码:

#include <asf.h>

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

        system_init();
        delay_init();

        // Initialize SPI and SSD1306 controller
        ssd1306_init();

        // set addresses at beginning of display
        ssd1306_set_page_address(0);
        ssd1306_set_column_address(0);

        // fill display with lines
        for (page_address = 0; page_address <= 8; page_address++) {
                ssd1306_set_page_address(page_address);
                for (column_address = 0; column_address < 128; column_address++) {
                        ssd1306_set_column_address(column_address);
                        /* fill every other pixel in the display. This will produce
                        horizontal lines on the display. */
                        ssd1306_write_data(0x0f);
                }
        }

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

#ifndef CONF_SSD1306_H_INCLUDED
#define CONF_SSD1306_H_INCLUDED

#include <board.h>

// Interface configuration for SAM D21 Xplained Pro
#  define SSD1306_SPI                 EXT3_SPI_MODULE
#  define CONFIG_SSD1306_FRAMEBUFFER

#  define SSD1306_DC_PIN              EXT3_PIN_5
#  define SSD1306_RES_PIN             EXT3_PIN_10
#  define SSD1306_CS_PIN              EXT3_PIN_15

#  define SSD1306_SPI_PINMUX_SETTING  EXT3_SPI_SERCOM_MUX_SETTING
#  define SSD1306_SPI_PINMUX_PAD0     EXT3_SPI_SERCOM_PINMUX_PAD0
#  define SSD1306_SPI_PINMUX_PAD1     PINMUX_UNUSED
#  define SSD1306_SPI_PINMUX_PAD2     EXT3_SPI_SERCOM_PINMUX_PAD2
#  define SSD1306_SPI_PINMUX_PAD3     EXT3_SPI_SERCOM_PINMUX_PAD3

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

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


相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2398

主题

6950

帖子

67

粉丝