您现在所在的是:

单片机论坛

回帖:2个,阅读:1321 [上一页] [1] [下一页]
-693
jirun168
文章数:1
年度积分:-871
历史总积分:-693
注册时间:2016/2/26
发站内信
发表于:2016/6/3 15:50:46
#0楼
12832oled显示屏+51程序,自己做的一个小程序和大家分享

附件 IMG_20151010_104241.jpg

//*********************************************
#include <reg52.h>

#define DBL P0
#define SWITCH_TIME 4000 //默认2s

unsigned char a;
unsigned int pic;
bit delayflag=0;
//*********************************************
void Initial(void);
void Write_Command(unsigned char RegisterName);
void Write_Data(unsigned char RegisterValue);
void fill(unsigned char dat1,unsigned char dat2);
void Delay(unsigned int count);
void pane();
void showpic();
void pictrue();
//************************************************
sbit CS =P2^4;
sbit DC =P2^7;
sbit W_R =P2^6;
sbit R_D =P2^5;
sbit RES =P2^3;

sbit SCLK = P0^0; // Serial Clock Input
sbit SDIN = P0^1; // Serial Data Input

sbit key_stop = P1^0;//按键,按下为0暂停循环,松开为1循环跑动
sbit key_mod = P1^1;//并串模式切换按键,为0串行模式,为1为并行模式,仅在程序开机时判断

bit mod_flag = 1;

//********************************************
void uDelay(unsigned char l)
{
while(l--);
}

void Delay(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<114;j++);
}

unsigned char code show[]=
{
/*-- 宽度x 高度=128x32 --*/
//吉润电子
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x48,0x48,0x48,0x48,0x48,0x7E,0x48,0x48,0x48,0x48,0x48,0x08,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x6C,0x0C,0x00,
0xF6,0x06,0x20,0x24,0xE4,0x24,0x24,0x04,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x90,0x90,0x90,0x90,0xFE,0x90,0x90,0x90,
0x90,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
0x82,0x82,0x82,0x82,0x82,0xE2,0xF2,0xBA,0x9E,0x8E,0x82,0x80,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,0x7E,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x1E,0x07,0x00,
0x7F,0x00,0x08,0x09,0x0F,0x09,0x48,0x40,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x7F,0x64,0x44,0x44,
0x44,0x47,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x40,0x40,0x7F,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,
//TEL:13530309438
0x00,0x01,0x7F,0x01,0x01,0x00,0x00,0x00,0x00,0x7F,0x49,0x49,0x41,0x00,0x00,0x00,
0x00,0x7F,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x00,0x00,
0x00,0x42,0x7F,0x40,0x00,0x00,0x00,0x00,0x00,0x22,0x49,0x49,0x36,0x00,0x00,0x00,
0x00,0x4F,0x49,0x49,0x31,0x00,0x00,0x00,0x00,0x22,0x49,0x49,0x36,0x00,0x00,0x00,
0x00,0x3E,0x41,0x41,0x3E,0x00,0x00,0x00,0x00,0x22,0x49,0x49,0x36,0x00,0x00,0x00,
0x00,0x3E,0x41,0x41,0x3E,0x00,0x00,0x00,0x00,0x26,0x49,0x49,0x3E,0x00,0x00,0x00,
0x00,0x38,0x26,0x7F,0x20,0x00,0x00,0x00,0x00,0x22,0x49,0x49,0x36,0x00,0x00,0x00,
0x00,0x36,0x49,0x49,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 //QQ:1903025895
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0xA2,0xC2,0xFC,0x00,0x00,0x00,
0x00,0x7C,0xA2,0xC2,0xFC,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x00,
0x00,0x84,0xFE,0x80,0x00,0x00,0x00,0x00,0x00,0x4C,0x92,0x92,0x7C,0x00,0x00,0x00,
0x00,0x7C,0x82,0x82,0x7C,0x00,0x00,0x00,0x00,0x44,0x92,0x92,0x6C,0x00,0x00,0x00,
0x00,0x7C,0x82,0x82,0x7C,0x00,0x00,0x00,0x00,0xC4,0xA2,0x92,0x8C,0x00,0x00,0x00,
0x00,0x9E,0x92,0x92,0x62,0x00,0x00,0x00,0x00,0x6C,0x92,0x92,0x6C,0x00,0x00,0x00,
0x00,0x4C,0x92,0x92,0x7C,0x00,0x00,0x00,0x00,0x9E,0x92,0x92,0x62,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

// 8-bit 80XX Parallel
void Write_Command_Para(unsigned char RegisterName)
{
CS=0;
DC=0;
DBL=RegisterName;
W_R=0;
W_R=1;
CS=1;
}
//**************************************
void Write_Data_Para(unsigned char RegisterValue)
{
CS=0;
DC=1;
DBL= (unsigned char)RegisterValue;
W_R=0;
W_R=1;
CS=1;
}

// 4-wire SPI
void Write_Command_SPI(unsigned char Data)
{
unsigned char i;

CS=0;
DC=0;
for (i=0; i<8; i++)
{
SCLK=0;
SDIN=(Data&0x80)>>7;
Data = Data << 1;
// uDelay(1);
SCLK=1;
// uDelay(1);
}
// SCLK=0;
DC=1;
CS=1;
}


void Write_Data_SPI(unsigned char Data)
{
unsigned char i;

CS=0;
DC=1;
for (i=0; i<8; i++)
{
SCLK=0;
SDIN=(Data&0x80)>>7;
Data = Data << 1;
// uDelay(1);
SCLK=1;
// uDelay(1);
}
// SCLK=0;
DC=1;
CS=1;
}

void Write_Command(unsigned char RegisterName)
{
if(mod_flag == 1)
{
Write_Command_Para(RegisterName);
}
else
{
Write_Command_SPI(RegisterName);
}
}
//**************************************
void Write_Data(unsigned char RegisterValue)
{
if(mod_flag == 1)
{
Write_Data_Para(RegisterValue);
}
else
{
Write_Data_SPI(RegisterValue);
}
}

//**************************************************
void Initial(void)
{
//unsigned int x,y;
Write_Command(0xae); /* set display off */
Write_Command(0x00); /* set lower column start address */
Write_Command(0x10); /* set higher column start address */
Write_Command(0x40); /* set display start line */
Write_Command(0x2E);
Write_Command(0x81); /* set contrast control */
Write_Command(0x32);
Write_Command(0x82);
Write_Command(0x80);
Write_Command(0xa1); /* set segment remap */
Write_Command(0xa6); /* set normal display */
Write_Command(0xa8); /* set multiplex ratio */
Write_Command(0x3f); /* 1/64 */
Write_Command(0xad); /* master configuration */
Write_Command(0x8e); /* external vcc supply */
Write_Command(0xc8); /* set com scan direction */
Write_Command(0xd3); /* set display offset */
Write_Command(0x40);
Write_Command(0xd5); /* set display clock divide/oscillator frequency */
Write_Command(0xf0);
Write_Command(0xD8); /*set area color mode off */
Write_Command(0x05);
Write_Command(0xD9);
Write_Command(0xF1);
Write_Command(0xda); /* set com pin configuartion */
Write_Command(0x12);
Write_Command(0x91);
Write_Command(0x3F);
Write_Command(0x3F);
Write_Command(0x3F);
Write_Command(0x3F);
Write_Command(0xaf); /* set display on */
}

void fill(unsigned char dat1,unsigned char dat2)
{
unsigned char x,y;
for(y=0;y<8;y++)
{
Write_Command(0xb0+y);
Write_Command(0x00);
Write_Command(0x10);
for(x=0;x<132;x++)
{
Write_Data(dat1);
Write_Data(dat2);
}
}
Delay(1);
}
void pane()
{
unsigned char x;//,y
unsigned int j;
/* page 1 */
Write_Command(0x04);
Write_Command(0x10);
Write_Command(0xb4);
Write_Data(0xff);
for(x=0;x<126;x++)
{
Write_Data(0x01);
}
Write_Data(0xff);
/* page 2--3 */
for(j=5;j<7;j++)
{
Write_Command(0x04);
Write_Command(0x10);
Write_Command(0xb0+j);
Write_Data(0xff);
for(x=0;x<126;x++)
{
Write_Data(0x00);
}
Write_Data(0xff);
}
/* page 4 */
Write_Command(0x04);
Write_Command(0x10);
Write_Command(0xb7);
Write_Data(0xff);
for(x=0;x<126;x++)
{
Write_Data(0x80);
}
Write_Data(0xff);
Delay(1);
}
void pictrue()
{
unsigned char x,y;
unsigned int i=0;
Write_Command(0x04);
Write_Command(0x10);
for(y=4;y<8;y++)
{
Write_Command(0xb0+y);
Write_Command(0x04);
Write_Command(0x10);
for(x=0;x<128;x++)
{
Write_Data(show[i++]);
}
}
}
//***************************************
void main(void)
{
key_stop = 1;
key_mod = 1;
Delay(5);
RES=0;
Delay(10);
RES=1;
Delay(10);
if(key_mod == 0) mod_flag = 0;//串行模式
if(key_mod == 1) mod_flag = 1;//并行模式
Initial();
while(1)
{
fill(0xff,0x00); Delay(SWITCH_TIME);
while(key_stop == 0);
fill(0x55,0x55); Delay(SWITCH_TIME);
while(key_stop == 0);
fill(0x55,0xaa); Delay(SWITCH_TIME);
while(key_stop == 0);
pane(); Delay(SWITCH_TIME);
while(key_stop == 0);
pictrue();Delay(SWITCH_TIME);
while(key_stop == 0);
}
}








附件:
[本地下载]


[此贴子已经被作者于2016/6/3 15:57:16编辑过]
4678
anriqing111
文章数:927
年度积分:50
历史总积分:4678
注册时间:2012/10/2
发站内信
发表于:2016/6/3 21:17:58
#1楼
单片机程序不好学呀。
7938
文章数:1877
年度积分:125
历史总积分:7938
注册时间:2008/12/26
发站内信
发表于:2016/6/3 22:47:44
#2楼
这个  玩过  不过现在看程序 有点吃力了
开心了就笑,不开心就过会再笑

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

93.6006