这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 开源硬件 » 【跟二叔玩bananapi】之八:老邓的SPI-OLED

共1条 1/1 1 跳转至

【跟二叔玩bananapi】之八:老邓的SPI-OLED

助工
2015-01-05 22:40:08     打赏
老邓的OLED,包装相当给力,专业电商,给力!http://www.52pi.net


里三层外三层,照了一张For BPI忘了传了,
反正大家都照了,就不补了,


使用wiringPi库
要加载请用gpio load spi命令
效果如下,显示的是一个叫1024的图片


下边是程序52pi.c,附件中有程序和1024文件

#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <stdio.h>  
#include <stdlib.h>  
#include <stdint.h>
#include <string.h>
#include <time.h>

unsigned char initcode[] = {
    0xAE, 0xA8, 0x3F, 0xD3, 0x00, 0x40, 0xA1, 0xC8,
	0xA6, 0xD5, 0x80, 0xDA, 0x12, 0x81, 0x00, 0xB0,
	0xA4, 0xDB, 0x40, 0x20, 0x00, 0x00, 0x10, 0x8D,
	0x14, 0x2E, 0xA6, 0xAF 
};

unsigned char poscode[] = {
	0x20, 0x00, 0xB0, 0x00, 0x10
};

#define BUFFER_SIZE 1024
unsigned char buffer[BUFFER_SIZE];
unsigned char buffer_temp[BUFFER_SIZE];

void oled_begin();
void oled_test();

int main(void)
{
	FILE *fphzk;
	time_t now;
	struct tm *timenow;

	wiringPiSetup();
	fphzk=fopen("1024","rb");
	fread(buffer,1,BUFFER_SIZE,fphzk);
	fclose(fphzk);

	oled_begin();

	time(&now);   
	timenow = localtime(&now);    
	printf("Start time is %s/n",asctime(timenow));  

	oled_test();

	time(&now);   
	timenow = localtime(&now);    
	printf("End time is %s/n",asctime(timenow));  

	return 0;
}

void oled_begin()
{		
	pinMode (5, OUTPUT) ;
	pinMode (6, OUTPUT) ;
	wiringPiSPISetup(0, 32*1000*1000);
	digitalWrite(6,  LOW) ;
	delay(50);
	digitalWrite(6,  HIGH) ;
	digitalWrite(5, LOW);
	wiringPiSPIDataRW(0, initcode, 28);
}

void oled_test()
{ 
	int i,j,k;
	unsigned char temp;

	for(k=0;k<10000;k++)
	{
		digitalWrite(5, LOW);
		wiringPiSPIDataRW(0, poscode, 5);
		memcpy(buffer_temp, buffer, BUFFER_SIZE);				
		digitalWrite(5, HIGH);
		wiringPiSPIDataRW(0, buffer_temp, 1024);

		for(i=0;i<BUFFER_SIZE;i+=128)
		{
			for(j=0;j<((i<256)?2:1);j++)
			{
				temp=buffer[i];
				memcpy(&buffer[i], &buffer[i+1], 127);			
				buffer[i+127]=temp;
			}
		}
		delay(10);
	}
}

 

编译请用命令gcc -Wall -o 52pi 52pi.c -lwiringPi
运行./52pi


相当富有动感,每秒能刷多少帧?自己测试吧
程序包下载2s.rar


共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]