金牌会员
- 积分
- 1387
- 威望
- 709
- 贡献
- 354
- 兑换币
- 388
- 注册时间
- 2013-9-12
- 在线时间
- 162 小时
- 毕业学校
- 广东石油化工学院
|
单片机是MC9X12XS,我用的是内置SPI,OLED供电要3.2V,我就用个小电池给OLED供电,电脑电源给单片机供电,是用单片机内置SPI和OLED进行通信的,下面程序很简单,我就想随便弄亮屏幕就好了,可是一直是黑的,大神可以帮我看看程序吗
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define DO PORTA_PA0
#define RST PORTA_PA1
#define bz SPI0SR_SPTEF /*发送完成标志位,=1时发送完成*/
unsigned char zhong[]= {64,48,44,235,40,40,0,248,8,8,255,8,8,248,0,0,
1,1,1,255,65,33,0,1,1,1,255,1,1,1,0,0};/*"钟",0*/
void SPI0set()
{
SPI0CR1=0x50;
SPI0BR=0X77;
}
void write_data(unsigned char dat)
{
DO=1;/*输入的是数据*/
SPI0DR=dat;
while(!bz); /*等待发送完成*/
}
void write_order(unsigned char dat)
{
DO=0;/*输入的是命令*/
SPI0DR=dat;
while(!bz); /*等待发送完成*/
}
void OLEDset()
{
int i;
RST=0;
for(i=50;i>1;i--);
RST=1;
write_order(0XAE);/*关闭显示屏*/
write_order(0X81);/*设置分辨率前要输入的命令*/
write_order(0X7F);/*分辨率为95*/
write_order(0XA4);/*屏幕显示RAM里面的内容,如果0XA5则不显示里面内容*/
write_order(0XA6);/*在RAM里面为1时该点亮,0灭,0XA7则相反*/
write_order(0X20);/*设定寻址方式前输入的指令*/
write_order(0X02);/*设定寻址方式为页寻址*/
write_order(0X40);/*屏幕从RAM的第一行开始扫描*/
write_order(0XA0);/*RAM的第一列扫描到屏幕的SEG0*/
write_order(0XA8);/*设定有多少个MUX前的指令*/
write_order(0X3F);/*有64个MUX*/
write_order(0XC0);/*从com0扫描到com64*/
write_order(0xda);
write_order(0X01);/*不使能行的左右倒置。com口配置可以不按顺序*/
write_order(0XAF);
}
void setxy(unsigned char x,unsigned char y)
{
write_order(0XB0+x);/*x页*/
write_order(((y&0xf0)>>4)|0x10); /*y列*/
write_order((y&0x0f)|0x01);
}
void main(void)
{
int i;
DDRA_DDRA0=1;
DDRA_DDRA1=1;
MODRR=0X10;
SPI0set();
OLEDset();
while(1)
{
setxy(0,0);
for(i=0;i<=15;i++)
{
write_data(zhong[i]);
}
setxy(1,0);
for(i=0;i<=15;i++)
{
write_data(zhong[i+16]);
}
}
}
弄了好久,那个OLED一点反应都没啊:'( |
|