点亮OLED 软件控制滚屏 原来用51板(12M)做的 滚的很快 为什么换了430(8m)后就明显慢了好多 我换了430的晶振(16M) 赶紧几乎没快起来 为什么呢?
我的板子的测试程序如下(可以点亮OLED):
#include "main.h"
#include "zimo.h"
#define EN_H P4OUT|=BIT1
#define EN_L P4OUT&=~BIT1
#define WR_H P5OUT |= BIT0
#define WR_L P5OUT &= ~BIT0
#define RD_H P5OUT |= BIT1
#define RD_L P5OUT &= ~BIT1
#define RES_H P5OUT |= BIT2
#define RES_L P5OUT &= ~BIT2
#define DC_H P5OUT |= BIT3
#define DC_L P5OUT &= ~BIT3
#define CS_H P5OUT |= BIT4
#define CS_L P5OUT &= ~BIT4
unsigned long cc;
unsigned char bai,shi,ge,adtime,shez=0,sf=0,mode=2,mm,one;
unsigned long cc,adint,fen=0,ov,jclose=0;
float bb,addata;
unsigned char data_buf1[30],count1=0,data_len1,bz1=0,sbdz[2],kzqdz[2],bh,senddata[20];
unsigned long ADC0 ;
/*8M晶振初始*******************************************************************/
void init_clock8m()
{
uchar i;
WDTCTL = WDTPW + WDTHOLD; // 关看门狗
BCSCTL1 &= ~XT2OFF; // 打开XT2
do{
IFG1 &= ~OFIFG; // 时钟稳定
for (i = 0xff; i > 0; i--);
}
while ((IFG1 & OFIFG));
BCSCTL2 |= SELM_1+SELS; // MCLK=SMCLK=XT2
}
/******************************************************************************/
/*延时程序*********************************************************************/
void delay(unsigned int t)
{ unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++);
}
/******************************************************************************/
/*OLEDIO初始化*****************************************************************/
void oledioinit(void)
{
P4SEL=0X00;
P4DIR=0XFF;
P4OUT=0XFF;
P5SEL=0X00;
P5DIR=0XFF;
P5OUT=0XFF;
}
/******************************************************************************/
/*写指令到OLED显示屏***********************************************************/
void WriteCommand(unsigned com)
{
CS_H;
DC_L;
WR_L;
RD_H;
CS_L;
P4OUT=com;
CS_H;
}
/******************************************************************************/
/*写数据到oled显示屏***********************************************************/
void WriteData(unsigned dat)
{
CS_H;
DC_H;
WR_L;
RD_H;
CS_L;
P4OUT=dat;
CS_H;
}
/******************************************************************************/
/*总线初始化*******************************************************************/
void esbusini(void)
{
unsigned char i=100;
while(--i)delay(100);//延时5uS以上
RES_H;
RES_L;
while(--i)delay(100);//延时5uS以上
RES_H;
}
/******************************************************************************/
/*显示初始化*******************************************************************/
void ini_dis(void)
{
unsigned char i,j;
for(i=0;i<8;i++)
{
WriteCommand (0xb0+i);
WriteCommand (0x02);
WriteCommand (0x10);
for(j=0;j<128;j++)
WriteData(0x00);
}
}
/******************************************************************************/
/*oled显示的准备工作***********************************************************/
void ini_oled(void)
{
esbusini();
WriteCommand(0x00);
WriteCommand(0x10);
WriteCommand(0x40);
WriteCommand(0x81);
WriteCommand(0x2f);
WriteCommand(0xA1);
WriteCommand(0xA4);
WriteCommand(0XA6);
WriteCommand(0xA8);
WriteCommand(0x3f);
WriteCommand(0xAD);
WriteCommand(0x8A);
WriteCommand(0xAE);
WriteCommand(0xD3);
WriteCommand(0x00);
WriteCommand(0xD5);
WriteCommand(0x20);
WriteCommand(0xD8);
WriteCommand(0x00);
WriteCommand(0xDA);
WriteCommand(0x12);
WriteCommand(0xDB);
WriteCommand(0x00);
WriteCommand(0xD9);
WriteCommand(0x22);
WriteCommand(0xc0);
ini_dis();
}
/******************************************************************************/
/*显示X,Y坐标处的一个字符*****************************************************/
void disc(unsigned char X,unsigned char Y,unsigned char * c)
{
unsigned char n;
WriteCommand (0xb7-(Y<<1));
if(X%2)
WriteCommand (0x08);
else
WriteCommand (0x00);
WriteCommand (0x10+(X>>1));
for(n=0;n<=15;n+=2)
WriteData(*(c+n));
WriteCommand (0xb7-(Y<<1)-1);
if(X%2)
WriteCommand (0x08);
else
WriteCommand (0x00);
WriteCommand (0x10+(X>>1));
for(n=1;n<=15;n+=2)
WriteData(*(c+n));
}
void diss(unsigned char X,unsigned char Y,unsigned char * h)
{
unsigned char n;
WriteCommand (0xb7-(Y<<1));
if(X%2)
WriteCommand (0x08);
else
WriteCommand (0x00);
WriteCommand (0x10+(X>>1));
for(n=0;n<=31;n+=2)
WriteData(*(h+n));
WriteCommand (0xb7-(Y<<1)-1);
if(X%2)
WriteCommand (0x08);
else
WriteCommand (0x00);
WriteCommand (0x10+(X>>1));
for(n=1;n<=31;n+=2)
WriteData(*(h+n));
}
void dish(unsigned char X,unsigned char Y,unsigned char * h)
{
unsigned char n;
WriteCommand (0xb7-(Y<<1));
if(X%2)
WriteCommand (0x04);
else
WriteCommand (0x00);
WriteCommand (0x10+(X>>1));
for(n=0;n<=31;n+=2)
WriteData(*(h+n));
WriteCommand (0xb7-(Y<<1)-1);
if(X%2)
WriteCommand (0x04);
else
WriteCommand (0x00);
WriteCommand (0x10+(X>>1));
for(n=1;n<=31;n+=2)
WriteData(*(h+n));
}
void dispro(unsigned char X,unsigned char Y,unsigned char * h)
{
unsigned int n;
WriteCommand (0xb7-(Y<<1));
WriteCommand (0x04);
WriteCommand (0x10+(X>>1));
for(n=0;n<=255;n+=2)
WriteData(*(h+n));
WriteCommand (0xb7-(Y<<1)-1);
WriteCommand (0x04);
WriteCommand (0x10+(X>>1));
for(n=1;n<=255;n+=2)
WriteData(*(h+n));
}
void dispro8(unsigned char X,unsigned char Y,unsigned const char * h) //dish 全字
{
unsigned int n;
WriteCommand (0xb7-(Y<<1));
WriteCommand (0x08);
WriteCommand (0x10+(X>>1));
for(n=0;n<=255;n+=2)
WriteData(*(h+n));
WriteCommand (0xb7-(Y<<1)-1);
WriteCommand (0x08);
WriteCommand (0x10+(X>>1));
for(n=1;n<=255;n+=2)
WriteData(*(h+n));
}
void disn(unsigned char X,unsigned char Y,unsigned char n)
{
unsigned char m;
WriteCommand (0xb7-(Y<<1));
if(X%2)
WriteCommand (0x08);
else
WriteCommand (0x00);
WriteCommand (0x10+(X>>1));
for(m=0;m<=15;m+=2)
WriteData(*(num[n]+m));
WriteCommand (0xb7-(Y<<1)-1);
if(X%2)
WriteCommand (0x08);
else
WriteCommand (0x00);
WriteCommand (0x10+(X>>1));
for(m=1;m<=15;m+=2)
WriteData(*(num[n]+m));
}
/******************************************************************************/
void disgd(unsigned char X,unsigned char Y,unsigned const char *yxs,unsigned const char *hxs,unsigned j)
{
unsigned int i;
WriteCommand (0xb7-(Y<<1));
WriteCommand (0x00);
WriteCommand (0x10+(X>>1));
for(i=j;i<=255;i+=2)
WriteData(*(yxs+i));
for(i=0;i<j;i+=2)
WriteData(*(hxs+i));
WriteCommand (0xb7-(Y<<1)-1);
WriteCommand (0x00);
WriteCommand (0x10+(X>>1));
for(i=(j+1);i<=255;i+=2)
WriteData(*(yxs+i));
for(i=1;i<j;i+=2)
WriteData(*(hxs+i));
}
/*主函数***********************************************************************/
void main(void)
{
uint j;
_DINT(); //关总中断
init_clock8m();
delay(1000);//等待设备上电完成
delay(1000);//等待设备上电完成
oledioinit();
P5OUT&=~BIT5;
ini_oled();
WriteCommand(0xAD); // Set DC-DC
WriteCommand(0x8B); // 8B=ON, 8A=Off
WriteCommand(0xaf); //open display
while(1)
{
dispro8(1,0,delhang);
dispro8(1,1,tu2);
dispro8(1,2,tu3);
dispro8(1,3,delhang);
delay(5000);
delay(5000);
delay(5000);
for(j=0;j<256;j+=40)
{
disgd(1,0,delhang,qsrmm,j);
disgd(1,1,tu2,delhang,j);
disgd(1,2,tu3,delhang,j);
disgd(1,3,delhang,tgqd,j);
}
while(1);
}
}
/******************************************************************************/
付原理图:
(原文件名:1.JPG)
原理图原件:
点击此处下载 ourdev_675313UET3P5.zip(文件大小:62K) (原文件名:ylt.zip)
原理图功能实现都没问题,但因为这是个低功耗产品,这板子目前实现起来有问题,呵呵
|