首页资源分类嵌入式系统 > 树莓派B+点亮LCD

树莓派B+点亮LCD

已有 445005个资源

下载专区

上传者其他资源

    文档信息举报收藏

    标    签:树莓派B+

    分    享:

    文档简介

    树莓派B+点亮LCD的源代码。

    文档预览

    // Example program for bcm2835 library // Shows how to interface with SPI to transfer a number of bytes to and from an SPI device // // After installing bcm2835, you can build this // with something like: // gcc -o oled rpi_oled.c -l bcm2835 // sudo ./oled #include #include #define OLED_DC RPI_BPLUS_GPIO_J8_16 #define OLED_RST RPI_BPLUS_GPIO_J8_18 //************************************************ void OLED_initial(); void bcm2835spi_init(); void spi_writecommand(uint8_t cmd); void spi_writedata(uint8_t data); void fill(uint8_t dat1,uint8_t dat2); void pane(); void pictrue(); //************************************************ uint8_t codeshow[]= { /*-- 宽度 x 高度=128x64 ---此代码是显示 Topwin_OLED 及电话号码字*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x60,0x10,0x10,0x10,0xF0,0x10,0x10,0x10,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x80,0x40,0x20,0x10,0x10,0x10,0x20,0x40,0x80,0x00,0x00,0x10,0xF0,0x10,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x10,0xF0,0x10,0x10,0x10,0x10,0x10,0x30,0x40,0x00,0x00,0x10,0xF0,0x10,0x10, 0x10,0x10,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, 0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x04,0x02,0x02,0x02,0x02,0x04,0xF8,0x00,0x00,0x00,0x02,0xFE, 0x04,0x02,0x02,0x02,0x02,0x04,0xF8,0x00,0x02,0x0E,0xF2,0x00,0xF2,0x0E,0xF2,0x00,0xFA,0x0E,0x02, 0x00,0x00,0x00,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0xFE,0x04,0x02,0x02,0x02,0x02, 0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x80,0x00,0x00, 0x00,0x00,0x00,0x80,0x7F,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00, 0xFF,0x04,0x04,0x04,0x04,0x1F,0x00,0x80,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0xC0,0x3F, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x02,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0x02,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x10,0x1F,0x11,0x02,0x02,0x02,0x02, 0x01,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02, 0x03,0x02,0x02,0x00,0x00,0x00,0x00,0x02,0x03,0x02,0x00,0x00,0x00,0x02,0x03,0x02,0x00,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x02,0x01,0x00,0x00, 0x00,0x00,0x02,0x03,0x02,0x02,0x02,0x02,0x02,0x03,0x00,0x00,0x00,0x02,0x03,0x02,0x02,0x02,0x02, 0x02,0x03,0x00,0x00,0x00,0x02,0x03,0x02,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x41,0x7F,0x41, 0x03,0x00,0x00,0x38,0x54,0x54,0x58,0x00,0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00,0x44,0x00,0x00, 0x7C,0x82,0x82,0x7C,0x00,0x00,0x02,0xF2,0x0E,0x02,0x00,0x00,0x4E,0x8A,0x8A,0x72,0x00,0x00,0x4E, 0x8A,0x8A,0x72,0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x6C,0x92,0x92,0x6C,0x00,0x00,0x44,0x92, 0x92,0x6C,0x00,0x00,0x6C,0x92,0x92,0x6C,0x00,0x30,0x28,0x24,0xFF,0x20,0x00,0x00,0x0C,0x92,0x92, 0x7C,0x00,0x00,0x02,0xF2,0x0E,0x02,0x00,0x7C,0x92,0x92,0x92,0x60,0x00,0x00,0x7C,0x82,0x82,0x7C, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xF8,0x48,0xE8,0x18,0x00,0x40,0xA0,0xA0, 0xC0,0x00,0x00,0x20,0x60,0xA0,0x60,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0xE0,0x10,0x10,0xE0,0x00, 0x00,0x10,0x90,0x70,0x10,0x00,0x00,0x70,0x50,0x50,0x90,0x00,0x00,0x70,0x50,0x50,0x90,0x00,0x40, 0x40,0x40,0x40,0x40,0x00,0x00,0x60,0x90,0x90,0x60,0x00,0x00,0x20,0x90,0x90,0x60,0x00,0x00,0x60, 0x90,0x90,0x60,0x00,0x80,0x40,0x20,0xF8,0x00,0x00,0x00,0x60,0x90,0x90,0xE0,0x00,0x80,0x40,0x20, 0xF8,0x00,0x00,0x00,0x60,0x90,0x90,0xE0,0x00,0x00,0x20,0x10,0x90,0x60,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x02,0x00,0x00,0x00,0x01,0x02,0x02,0x03,0x02,0x00,0x02,0x03, 0x02,0x03,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x03,0x04,0x04,0x03,0x00,0x00,0x00,0x07,0x00,0x00, 0x00,0x00,0x02,0x04,0x04,0x03,0x00,0x00,0x02,0x04,0x04,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x03,0x04,0x04,0x03,0x00,0x00,0x02,0x04,0x04,0x03,0x00,0x00,0x03,0x04,0x04,0x03,0x00,0x01, 0x01,0x01,0x07,0x01,0x00,0x00,0x00,0x04,0x04,0x03,0x00,0x01,0x01,0x01,0x07,0x01,0x00,0x00,0x00, 0x04,0x04,0x03,0x00,0x00,0x06,0x05,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; int main(int argc, char **argv) { char buf[10], buf1[4]; int RTSflag, count = 0; if (!bcm2835_init()) { printf("BCM2835 init fail."); return 1; } bcm2835_gpio_fsel(OLED_DC, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_fsel(OLED_RST, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_write(OLED_RST, LOW); bcm2835_delay(1); bcm2835_gpio_write(OLED_RST, HIGH); bcm2835_delay(10); bcm2835spi_init(); OLED_initial(); while(1) { fill(0xff,0x00); bcm2835_delay(500); fill(0x55,0x55); bcm2835_delay(500); fill(0x55,0xaa); bcm2835_delay(500); pane(); bcm2835_delay(500); pictrue(); bcm2835_delay(1000); } bcm2835_spi_end(); bcm2835_close(); return 0; } void bcm2835spi_init() { bcm2835_spi_begin(); bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default bcm2835_spi_setDataMode(BCM2835_SPI_MODE3); // The default bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_128); // The default bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default } //************************************************** void OLED_initial() { spi_writecommand(0xAE); /*set display off*/ spi_writecommand(0x02); /*set lower column start address*/ spi_writecommand(0x10); /*set higher column start address*/ spi_writecommand(0x40); /*set display start line*/ spi_writecommand(0x2E); /*deactivate scroll spi_writecommand(0x81); /*set contrast control*/ spi_writecommand(0x32); /*contrast value*/ spi_writecommand(0x82); spi_writecommand(0x80); spi_writecommand(0xA1); /*set segment remap */ spi_writecommand(0xA6); /*set normal display*/ spi_writecommand(0xA8); /*set multiplex ratio*/ spi_writecommand(0x3f); /*1/64*/ spi_writecommand(0xAD); /*master configuration*/ spi_writecommand(0x8E); /*external vcc supply*/ spi_writecommand(0xc8); /*set com scan direction*/ spi_writecommand(0xd3); /*set display offset */ spi_writecommand(0x40); spi_writecommand(0xD5); /*set display clock divide/oscillator frequency*/ spi_writecommand(0xf0); spi_writecommand(0xD8); /*set area color mode off*/ spi_writecommand(0x05); spi_writecommand(0xD9); spi_writecommand(0xF1); spi_writecommand(0xda); /*set com pin configuartion*/ spi_writecommand(0x12); spi_writecommand(0xAF); /*set display on*/ } void fill(uint8_t dat1,uint8_t dat2) { uint8_t x,y; for(y=0;y<8;y++) { spi_writecommand(0xb0+y); /*set page start address*/ spi_writecommand(0x02); spi_writecommand(0x10); for(x=0;x<66;x++) { spi_writedata(dat1); spi_writedata(dat2); } } } void pane() { uint8_t x, y; /* page0 */ spi_writecommand(0x02); spi_writecommand(0x10); spi_writecommand(0xb0); spi_writedata(0xff); for(x=0;x<126;x++) { spi_writedata(0x01); } spi_writedata(0xff); /* page1--6 */ for(y=1;y<7;y++) { spi_writecommand(0x02); spi_writecommand(0x10); spi_writecommand(0xb0+y); spi_writedata(0xff); for(x=0;x<126;x++) { spi_writedata(0x00); } spi_writedata(0xff); } /* page7 */ spi_writecommand(0x02); spi_writecommand(0x10); spi_writecommand(0xb7); spi_writedata(0xff); for(x=0;x<126;x++) { spi_writedata(0x80); } spi_writedata(0xff); } void pictrue() { uint8_t x, y; uint16_t i=0; for(y=0;y<8;y++) { spi_writecommand(0xb0+y); spi_writecommand(0x02); spi_writecommand(0x10); for(x=0;x<128;x++) { spi_writedata(codeshow[i++]); } } } //*************************************** void spi_writecommand(uint8_t cmd) { bcm2835_gpio_write(OLED_DC, LOW); bcm2835_spi_transfer(cmd); } //*************************************** void spi_writedata(uint8_t data) { bcm2835_gpio_write(OLED_DC, HIGH); bcm2835_spi_transfer(data); }

    Top_arrow
    回到顶部
    EEWORLD下载中心所有资源均来自网友分享,如有侵权,请发送举报邮件到客服邮箱bbs_service@eeworld.com.cn 或通过站内短信息或QQ:273568022联系管理员 高员外,我们会尽快处理。