#include<iostm8s105c6.h>
#include <stdio.h>
#include"OLED.h"
#include"oledfont.h"
#include"8x16.h"
#include"ds1302.h"
#include<math.h>
//D0
#define SCLK_Set() PC_ODR_bit.ODR6 = 1
#define SCLK_Reset() PC_ODR_bit.ODR6 = 0
//D1
#define SDIN_Set() PC_ODR_bit.ODR5 = 1
#define SDIN_Reset() PC_ODR_bit.ODR5 = 0
#define RES_Set() PC_ODR_bit.ODR4 = 1
#define RES_Reset() PC_ODR_bit.ODR4 = 0
#define DC_Set() PC_ODR_bit.ODR3 = 1
#define DC_Reset() PC_ODR_bit.ODR3 = 0
#define CS_Set() PC_ODR_bit.ODR2 = 1
#define CS_Reset() PC_ODR_bit.ODR2 = 0
unsigned char gui_disp_buf[X_WIDTH * Y_WIDTH / 8]={ //取的字模
0x20,0x30,0xAC,0x63,0x32,0x00,0xFC,0xA4,0xA5,0xA6,0xA4,0xA4,0xA4,0xBC,0x00,0x00,
0x00,0x08,0x06,0x82,0xFA,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x9A,0x96,0x02,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x3F,0xC2,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,0xF0,0x1C,0x07,0xE2,0x24,0x24,0x24,0xE4,0x04,0x04,0xFC,0x04,0x04,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x80,0x80,0xBE,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xBE,0x80,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x10,0x11,0x09,0x49,0x21,0x1C,0x03,0x7F,0x04,0x3F,0x04,0x3F,0x44,0x7F,0x00,0x00,
0x00,0x04,0x04,0x04,0x05,0x04,0x04,0x04,0x04,0x04,0x46,0x84,0x60,0x1F,0x00,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x01,0x06,0x0C,0x18,0x30,0x60,0x20,0x00,
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7F,0x00,0x00,0x07,0x02,0x02,0x02,0x07,0x20,0x40,0x3F,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x40,0x40,0x44,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,0x00,
0x00,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
0x40,0x20,0x10,0x0C,0xE3,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0x02,0x00,0x00,
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0x11,0x11,0x11,0x11,0x11,0xFF,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x00,
0x42,0x22,0x1B,0x02,0x02,0x0A,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3F,0x00,0x00,
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x01,0x01,0x01,0x21,0x41,0x3F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,
0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,0x00,0x30,0x28,0x24,0x22,0x21,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,0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x08,0x4A,0x4A,0xFE,0x4A,0x4A,0x7E,0x00,
0x09,0x4A,0x4C,0xF8,0x4C,0x4B,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,
0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,0x08,0x04,0x7F,0x22,0x22,0x22,0x7E,0x00,
0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x00,0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
/***********************************************************************
函数: Put_Pixel
功能:在液晶屏上打印一个像素
参数说明: 坐标(x,y)(以左上角为坐标原点)x取值0~127。y的取值0~64
flag = 0 将此点清零
= 1 将此点显示
= 2 将此点取反
***********************************************************************/
void Put_Pixel(unsigned char x , unsigned char y , unsigned char flag)
{
if((x < 128) && (y < 64))
{
switch(flag)
{
case 1://置1
gui_disp_buf[(x)+ 128 * ( y / 8)] |= ( 1 << (y % 8));
break;
case 0://清零
gui_disp_buf[(x)+ 128 * ( y / 8)] &= ~( 1 << (y % 8));
break;
case 2://取反
gui_disp_buf[(x)+ 128 * ( y / 8)] ^= ( 1 << (y % 8));
break;
}
}
}
//??
void Clc_Lcd(unsigned char flag)
{
unsigned int i ;
if(flag)
for(i=0;i<1024;i++)
gui_disp_buf[i]=1;
else
for(i=0;i<1024;i++)
gui_disp_buf[i]=0;
}
/***********************************************************************
画一条 (x1,y1) 到 (x2,y2) 的直线
flag = 1; 画点
flag = 0; 清点
***********************************************************************/
void Draw_Line(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned char flag)
{
int dy ;
int dx ;
int stepx, stepy, fraction;
dy = y2 - y1;
dx = x2 - x1;
if (dy < 0)
{
dy = -dy;
stepy = -1;
}
else
{
stepy = 1;
}
if (dx < 0)
{
dx = -dx;
stepx = -1;
}
else
{
stepx = 1;
}
dy <<= 1;
dx <<= 1;
Put_Pixel(x1,y1,flag);
if (dx > dy)
{
fraction = dy - (dx >> 1);
while (x1 != x2)
{
if (fraction >= 0)
{
y1 += stepy;
fraction -= dx;
}
x1 += stepx;
fraction += dy;
Put_Pixel(x1,y1,flag);
}
}
else
{
fraction = dx - (dy >> 1);
while (y1 != y2)
{
if (fraction >= 0)
{
x1 += stepx;
fraction -= dy;
}
y1 += stepy;
fraction += dx;
Put_Pixel(x1,y1,flag);
}
}
}
/****************************************************************************
* 相关的GUI接口函数
****************************************************************************/
/****************************************************************************
* 名称:GUI_FillSCR()
* 功能:全屏填充。直接使用数据填充显示缓冲区。
* 入口参数:dat 填充的数据(对于黑白色LCM,为0的点灭,为1的点显示)
* 出口参数:无
****************************************************************************/
void GUI_FillSCR(unsigned char dat)
{
// LCD_FillAll(dat);
}
unsigned char const DCB_HEX_TAB[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
/****************************************************************************
* 名称:GUI_Point()
* 功能:在指定位置上画点。
* 入口参数: x 指定点所在列的位置
* y 指定点所在行的位置
* color 显示颜色(对于黑白色LCM,为0时灭,为1时显示)
* 出口参数:返回值为1时表示操作成功,为0时表示操作失败。(操作失败原因是指定地址超出有
* 效范围)
* 说明:用户根据LCM的实际情况编写此函数。对于单色,只有一个位有效,则要使用左移的方法
* 实现point_dat = (point_dat&MASK_TAB [i]) | (color<<n),其它位数的一样
* 处理。
****************************************************************************/
unsigned char GUI_Point(unsigned char x, unsigned char y, unsigned char color)
{
Put_Pixel(x,y,color);
//刷新显示
//LCD_UpdatePoint(x, y);
//LCD_UpdateAll();
return(1);
}
/****************************************************************************
* 名称:GUI_HLine()
* 功能:画水平线。
* 入口参数:
x0 水平线起点所在列的位置
y0 水平线起点所在行的位置
x1 水平线终点所在列的位置
color 显示颜色(对于黑白色LCM,为0时灭,为1时显示)
* 出口参数:无
* 说明:操作失败原因是指定地址超出缓冲区范围。
****************************************************************************/
void GUI_HLine(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char color)
{
Draw_Line(x0, y0, x1, y0, color);
//LCD_UpdateAll();
}
/****************************************************************************
* 名称:GUI_RLine()
* 功能:画垂直线。
* 入口参数:
x0 垂直线起点所在列的位置
y0 垂直线起点所在行的位置
y1 垂直线终点所在行的位置
color 显示颜色(对于黑白色LCM,为0时灭,为1时显示)
* 出口参数:无
* 说明:操作失败原因是指定地址超出缓冲区范围。
****************************************************************************/
void GUI_RLine(unsigned char x0, unsigned char y0, unsigned char y1, unsigned char color)
{
Draw_Line(x0,y0,x0,y1,color);
}
/***********************************************************************
以x,y为圆心,以radius为半径画贺
(flag=1画点,flag=0清点)
***********************************************************************/
void glcd_circle(int x, int y, int radius, unsigned char flag)
{
int xc = 0;
int yc ;
int p ;
yc=radius;
p = 3 - (radius<<1);
while (xc <= yc)
{
Put_Pixel(x + xc, y + yc, flag);
Put_Pixel(x + xc, y - yc, flag);
Put_Pixel(x - xc, y + yc, flag);
Put_Pixel(x - xc, y - yc, flag);
Put_Pixel(x + yc, y + xc, flag);
Put_Pixel(x + yc, y - xc, flag);
Put_Pixel(x - yc, y + xc, flag);
Put_Pixel(x - yc, y - xc, flag);
if (p < 0)
p += (xc++ << 2) + 6;
else
p += ((xc++ - yc--)<<2) + 10;
}
}
//画矩形
void glcd_box(int x1, int y1, int x2, int y2, unsigned char flag)
{
Draw_Line(x1,y1,x2,y1,flag); // up
Draw_Line(x1,y2,x2,y2,flag); // down
Draw_Line(x2,y1,x2,y2,flag); // right
Draw_Line(x1,y1,x1,y2,flag); // left
}
//***********************************************************************
//以x,y点为原点,以degree为角度,画一条从内径到外径之间的线段
//(flag=1画点,flag=0清点)
//***********************************************************************
void glcd_degree_line(int x, int y, int degree, int inner_radius, int outer_radius, unsigned char flag)
{
int fx,fy,tx,ty;
fx = x + (int)(inner_radius * sin(degree * 3.14 / 180)); // ???????????????
fy = y - (int)(inner_radius * cos(degree * 3.14 / 180));
tx = x + (int)(outer_radius * sin(degree * 3.14 / 180));
ty = y - (int)(outer_radius * cos(degree * 3.14 / 180));
Draw_Line(fx,fy,tx,ty,flag);
}
//画上函数线段的包括线
void glcd_degree_line_bold(int x, int y, int degree, int inner_radius, int outer_radius, unsigned char flag)
{
int fx,fy,tx,ty;
fx = x + (int)(inner_radius * sin(degree * 3.14 / 180)); // ???????????????
fy = y - (int)(inner_radius * cos(degree * 3.14 / 180));
tx = x + (int)(outer_radius * sin(degree * 3.14 / 180));
ty = y - (int)(outer_radius * cos(degree * 3.14 / 180));
Draw_Line(fx,fy,tx,ty,flag);
Draw_Line(fx+1,fy+1,tx+1,ty+1,flag);
Draw_Line(fx-1,fy-1,tx-1,ty-1,flag);
}
//?????
void Lcd_Puts_8x6(unsigned char x,unsigned char y,char *str,unsigned char flag)
{
unsigned char i;
for(i = 0; *str !='\0' ;i++)
{
if(x + i*8>120)
{
if(y > 40)
{
Clc_Lcd(0);
y = x = i = 0;
}
else
{
y += 6;
x = i= 0;
}
}
if(*str=='\n')
{
if(x != 0)
{
y += 6;
x = i= 0;}
str++;
}
Lcd_Putc_8x6(x+i*8,y,*str++,flag);
}
}
//????
int Lcd_Putc_8x6(unsigned char x,unsigned char y, char C,unsigned char flag)
{
unsigned char i,j,tmp;
for(i = 0 ; i < 6 ; i++)
{
tmp = font6x8[C-' '][i]; // 字库表;
for(j = 0; j<8; j++)
{
if((tmp >> j ) & 0x01)
{
Put_Pixel(x + i, y+j , flag);
}
}
}
return C;
}
// 单个 字符;
int Lcd_Putc_8x16(unsigned char x,unsigned char y,char C,unsigned char flag)
{
unsigned char i, j, tmp;
for(i = 0;i < 16; i++)
{
tmp = font8x16[C-' '][i]; // 字库表;
for(j = 0;j < 8 ;j++)
{
if((tmp << j ) & 0x80)
{
Put_Pixel(x + j, y+i , flag);
}
}
}
return C;
}
// 电池图标;
int Lcd_Putc_Bat_8x16(unsigned char x,unsigned char y,char c, unsigned char flag)
{
unsigned char i, j, tmp;
for(i = 0; i<16; i++)
{
// tmp = font8x16[C-' '][i]; // 字库表;
tmp = BAT8x16[c][i] ; // 字库表;
// for(j = 0; j<8 ;j++)
// {
// if((tmp << j ) & 0x80)
// {
// Put_Pixel(x + j, y+i , flag);
// }
// }
for(j = 0; j<8; j++)
{
if((tmp >> j ) & 0x01)
{
Put_Pixel(x+i, y+j , flag);
}
}
}
return c;
}
// PLAY 图标;
int Lcd_Putc_PLAY_8x16(unsigned char x,unsigned char y,char c, unsigned char flag)
{
unsigned char i, j, tmp;
for(i = 0; i<8; i++)
{
tmp = PLAY_8x16[c][i] ; // 字库表;
for(j = 0; j<8; j++)
{
if((tmp >> j ) & 0x01)
{
Put_Pixel(x+i, y+j , flag);
}
}
}
return c;
}
// PLAY 图标;
//字符串
void Lcd_Puts_8x16(unsigned char x,unsigned char y,char *str,unsigned char flag)
{
unsigned char i;
for(i = 0; *str != '\0'; i++)
{
if(x + i * 8 > 120)
{
if(y > 40)
{
Clc_Lcd(0);
y = x = i = 0;
}
else
{
y += 16;
x = i= 0;
}
}
if(*str=='\n')
{
if(x != 0)
{
y += 16;
x = i= 0;}
str++;
}
Lcd_Putc_8x16(x+i*8, y, *str++, flag);
}
}
//加载16x16的汉字
void LcdDispHz16(unsigned int x0, unsigned int y0, unsigned char ForeColor, unsigned char we)
{
unsigned int j , x;
char hzbuf0[16]/*,temp[2]*/;
char hzbuf1[16]/*,temp[2]*/;
unsigned char buffer;
for (j = 0; j < 16; j++)
{
hzbuf0[j] = ymd[we][j];
}
for(j = 0; j < 16 ; j++)
{
buffer = hzbuf0[j];
for(x = 0; x < 8 ; x++)
{
if(buffer & 0x01)
{
Put_Pixel(x0 + j , y0 + x, 1);
}
else
{
Put_Pixel(x0 + j , y0 + x, 0);
}
buffer >>= 1;
}
}
for (j = 0; j < 16; j++)
{
hzbuf1[j] = ymd[we + 1][j];
}
for(j = 0; j < 16 ; j++)
{
buffer = hzbuf1[j];
for(x = 0; x < 8 ; x++)
{
if(buffer & 0x01)
{
Put_Pixel(x0 + j , y0 + x + 8, 1);
}
else
{
Put_Pixel(x0 + j , y0 + x + 8, 0);
}
buffer >>= 1;
}
}
}
//void Delay_Nms(unsigned int ms)
//{
// unsigned int x , y;
// for(x = ms ; x > 0; x--)
// for(y = 3000; y > 0; y--);
//}
void OLED_Port_Init()
{
//OLED D0
PE_DDR_bit.DDR0 = 1; //PE->0 OUTPUT
PE_CR1_bit.C10 = 1; //
PE_CR2_bit.C20 = 1; //
//OLED D1
PC_DDR_bit.DDR4 = 1; //PC->4 OUTPUT
PC_CR1_bit.C14 = 1; //
PC_CR2_bit.C24 = 1; //
//OLED RES
PG_DDR_bit.DDR1 = 1; //PG->1 OUTPUT
PG_CR1_bit.C11 = 1; //
PG_CR2_bit.C21 = 1; //
//OLED DC
PG_DDR_bit.DDR0 = 1; //PG->0 OUTPUT
PG_CR1_bit.C10 = 1; //
PG_CR2_bit.C20 = 1; //
}
void SPIWrite(unsigned char data)
{
unsigned char i;
//SCLK_Set();
for(i = 0 ; i < 8 ; i++)
{
SCLK_Reset();
if(data & 0x80)
{
SDIN_Set();
}
else
{
SDIN_Reset();
}
SCLK_Set();
data <<= 1;
}
}
void OLED_WriteCommond(unsigned char commond)
{
unsigned char i;
DC_Reset(); //dc = 1
CS_Reset(); //cs = 0
// Delay_Nms(10);
// SPIWrite(commond);
for(i = 0 ; i < 8 ; i++)
{
SCLK_Reset();
if(commond & 0x80)
{
SDIN_Set();
}
else
{
SDIN_Reset();
}
SCLK_Set();
commond <<= 1;
}
CS_Set(); //
DC_Set(); //dc = 1
}
void OLED_WriteData(unsigned char dat)
{
DC_Set(); //dc = 0
CS_Reset();
SPIWrite(dat);
CS_Set();
DC_Set(); //dc = 1
}
void OLED_Set_Pos(unsigned char x, unsigned char y)
{
OLED_WriteCommond(0xb0 + y);//OLED_WR_Byte(0xb0+y,OLED_CMD);
OLED_WriteCommond(((x & 0xf0)>> 4) | 0x10);//OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
OLED_WriteCommond((x&0x0f)|0x01);//OLED_WR_Byte((x&0x0f)|0x01,OLED_CMD);
}
//开启OLED显示
void OLED_Display_On(void)
{
OLED_WriteCommond(0x8d);//OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令
OLED_WriteCommond(0x14);//OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON
OLED_WriteCommond(0xaf);//OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON
}
//关闭OLED显示
void OLED_Display_Off(void)
{
OLED_WriteCommond(0x8d); //OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令
OLED_WriteCommond(0x10); //OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF
OLED_WriteCommond(0xae); //OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF
}
void OLED_Clear(void)
{
unsigned char i , n;
for(i = 0; i < 8 ;i++)
{
OLED_WriteCommond(0xb0 + i); //OLED_WR_Byte (0xb0+i,OLED_CMD); //设置页地址(0~7)
OLED_WriteCommond(0x00); //OLED_WR_Byte (0x00,OLED_CMD); //设置显示位置—列低地址
OLED_WriteCommond(0x10); //OLED_WR_Byte (0x10,OLED_CMD); //设置显示位置—列高地址
for(n = 0; n < 128 ; n++)
OLED_WriteData(0x00);
}
}
//开机界面;
void OLED_Show_Startup(void)
{
// 文字 描述;
OLED_ShowString(10, 0, "WELCOME TO");
OLED_ShowString(10, 2, "EWOODPECKER");
OLED_ShowString(10, 4, "WORLD !");
Delay_Nms(1000);
OLED_Clear();
// 猎人;
OLED_DrawBMP(0 , 0 , 128 , 8 , BMP_Shooting);
Delay_Nms(1000);
OLED_Clear();
// 实心字 + 图;
OLED_DrawBMP(0 , 0 , 128 , 8 , BMP_DuckHunting);
Delay_Nms(1000);
OLED_Clear();
// OLED_DrawBMP(0 , 3, 16, 5, PLAY);
//
// OLED_ShowString(50,3,"abcdefg");
// Delay_Nms(10000);
// OLED_Clear();
//
// OLED_DrawBMP(111 , 0, 127, 1, BAT_100);
// Delay_Nms(5000);
// OLED_Clear();
//
// OLED_DrawBMP(111 , 0, 127, 1, BAT_80);
// Delay_Nms(5000);
// OLED_Clear();
//
// OLED_DrawBMP(111 , 0, 127, 1, BAT_50);
// Delay_Nms(5000);
// OLED_Clear();
//
// OLED_DrawBMP(111 , 0, 127, 1, BAT_30);
// Delay_Nms(5000);
// OLED_Clear();
//
// OLED_DrawBMP(111 , 0, 127, 1, BAT_0);
// Delay_Nms(5000);
// OLED_Clear();
//
// OLED_DrawBMP(111 , 0, 127, 1, BAT_charge);
// Delay_Nms(5000);
// OLED_Clear();
}
void GUI_ClearSCR() //清屏
{
unsigned int i;
for(i = 0; i < (X_WIDTH * Y_WIDTH / 8) ; i++)
{
gui_disp_buf[i] = 0x00;
}
}
void OLED_DrawWindow(void)
{
unsigned int j;
unsigned char i , n;
j = 0;
for(i = 0; i < 8 ;i++)
{
OLED_WriteCommond(0xb0 + i); //OLED_WR_Byte (0xb0+i,OLED_CMD); //设置页地址(0~7)
OLED_WriteCommond(0x00); //OLED_WR_Byte (0x00,OLED_CMD); //设置显示位置—列低地址
OLED_WriteCommond(0x10); //OLED_WR_Byte (0x10,OLED_CMD); //设置显示位置—列高地址
for(n = 0; n < 128 ; n++)
OLED_WriteData(gui_disp_buf[j++]);
}
}
//在指定位置显示一个字符,包括部分字符
//x:0~127
//y:0~63
//mode:0,反白显示;1,正常显示
//size:选择字体 16/12
void OLED_ShowChar_backup(unsigned char x , unsigned char y , unsigned char chr)
{
unsigned char c = 0 , i = 0;
c = chr-' ';//得到偏移后的值
if(x > Max_Column - 1)
{
x = 0;
y = y + 2;
}
if(SIZE == 16)
{
OLED_Set_Pos(x,y);
for(i=0; i<8; i++)
OLED_WriteData(F8X16[c * 16 + i]);
OLED_Set_Pos(x , y + 1);
for(i = 0;i < 8; i++)
OLED_WriteData(F8X16[c*16 + i + 8]);
}
else
{
OLED_Set_Pos(x,y+1);
for(i=0;i<6;i++)
OLED_WriteData(F6x8[c][i]);
}
}
void OLED_ShowChar(unsigned char x , unsigned char y , unsigned char chr)
{
unsigned char c = 0 , i = 0;
c = chr-' ';//得到偏移后的值
if(x > Max_Column - 1)
{
x = 0;
y = y + 2;
}
OLED_Set_Pos(x,y+1);
for(i=0; i<6; i++)
OLED_WriteData(F6x8[c][i]);
}
//m^n函数
unsigned int oled_pow(unsigned char m , unsigned char n)
{
unsigned int result = 1;
while(n--)result*=m;
return result;
}
//显示2个数字
//x,y :起点坐标
//len :数字的位数
//size:字体大小
//mode:模式 0,填充模式;1,叠加模式
//num:数值(0~4294967295);
void OLED_ShowNum(unsigned char x,unsigned char y , unsigned int num , unsigned char len , unsigned char size2)
{
unsigned char t , temp;
unsigned char enshow = 0;
for(t = 0; t < len; t++)
{
temp = (num / oled_pow(10 , len - t - 1)) % 10;
if(enshow == 0 && t <(len - 1))
{
if(temp == 0)
{
OLED_ShowChar(x + (size2 / 2) * t, y, ' ');
continue;
}
else
enshow = 1;
}
OLED_ShowChar( x + ( size2 / 2 ) * t, y, temp +'0');
}
}
//显示一个字符号串
void OLED_ShowString(unsigned char x , unsigned char y , unsigned char *chr)
{
unsigned char j = 0;
while(chr[j] != '\0')
{
OLED_ShowChar(x , y , chr[j]);
x += 8;
if(x > 120)
{
x = 0;
y += 2;
}
j++;
}
}
//显示汉字
void OLED_ShowCHinese(unsigned char x , unsigned char y , unsigned char no)
{
unsigned char t,adder=0;
OLED_Set_Pos(x,y);
for(t = 0 ;t < 16; t++)
{
OLED_WriteData(Hzk[2 * no][t]);
adder += 1;
}
OLED_Set_Pos(x , y + 1);
for(t = 0 ; t < 16; t++)
{
OLED_WriteData(Hzk[2*no+1][t]);
adder += 1;
}
}
//显示 16 X 32 0-9数字
void OLED_ShowNum16X32(unsigned char x , unsigned char y , unsigned char no)
{
unsigned char t, adder = 0;
OLED_Set_Pos(x,y);
for(t = 0 ;t < 16; t++)
{
OLED_WriteData( Num16x32[4 * no][t]);
adder += 1;
}
OLED_Set_Pos(x , y + 1);
for(t = 0 ; t < 16; t++)
{
OLED_WriteData(Num16x32[4*no + 1][t]);
adder += 1;
}
OLED_Set_Pos(x,y + 2);
for(t = 0 ;t < 16; t++)
{
OLED_WriteData(Num16x32[4 * no + 2][t]);
adder += 1;
}
OLED_Set_Pos(x , y + 3);
for(t = 0 ; t < 16; t++)
{
OLED_WriteData(Num16x32[4*no + 3][t]);
adder += 1;
}
}
//显示 32 X 32 特殊符号
void OLED_ShowNum32X32(unsigned char x , unsigned char y , unsigned char no)
{
unsigned char t,adder = 0;
OLED_Set_Pos(x,y);
for(t = 0 ;t < 32; t++)
{
OLED_WriteData( Num32x32[4 * no][t]);
adder += 1;
}
OLED_Set_Pos(x , y + 1);
for(t = 0 ; t < 32; t++)
{
OLED_WriteData(Num32x32[4*no + 1][t]);
adder += 1;
}
OLED_Set_Pos(x,y + 2);
for(t = 0 ;t < 32; t++)
{
OLED_WriteData(Num32x32[4 * no + 2][t]);
adder += 1;
}
OLED_Set_Pos(x , y + 3);
for(t = 0 ; t < 32; t++)
{
OLED_WriteData(Num32x32[4*no + 3][t]);
adder += 1;
}
}
/***********功能描述:显示显示BMP图片 128 ×64 起始点坐标(x,y), x 的范围 0~127, y 为页的范围 0~7 *****************/
//void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
//{
// unsigned int j=0;
// unsigned char x,y;
//
// if(y1 %8 == 0) y = y1 / 8;
// else y = y1/8 + 1;
// for(y=y0;y<y1;y++)
// {
// OLED_Set_Pos(x0,y);
// for(x = x0; x < x1 ; x++)
// {
// OLED_WriteData(BMP[j++]);
// }
// }
//}
void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1, const unsigned char BMP[])
{
unsigned int j=0;
unsigned char x,y;
if(y1 % 8 == 0)
{
y = y1 / 8;
}
else
{
y = y1 / 8 + 1;
}
for(y=y0; y<y1; y++)
{
OLED_Set_Pos(x0,y);
for(x = x0; x < x1; x++)
{
OLED_WriteData(BMP[j++]);
}
}
}
void OLED_Reset()
{
RES_Set();
Delay_Nms(100);
RES_Reset();
Delay_Nms(100);
RES_Set();
// Delay_Nms(1000);
OLED_WriteCommond(0xae);
OLED_WriteCommond(0x00);
OLED_WriteCommond(0x10);
OLED_WriteCommond(0x40);
OLED_WriteCommond(0x81);
OLED_WriteCommond(0xcf);
OLED_WriteCommond(0xa1);
OLED_WriteCommond(0xc8);
OLED_WriteCommond(0xa6);
OLED_WriteCommond(0xa8);
OLED_WriteCommond(0x3f);
OLED_WriteCommond(0xd3);
OLED_WriteCommond(0x00);
OLED_WriteCommond(0xd5);
OLED_WriteCommond(0x80);
OLED_WriteCommond(0xd9);
OLED_WriteCommond(0xf1);
OLED_WriteCommond(0xda);
OLED_WriteCommond(0x12);
OLED_WriteCommond(0xdb);
OLED_WriteCommond(0x40);
OLED_WriteCommond(0x20);
OLED_WriteCommond(0x02);
OLED_WriteCommond(0x8d);
OLED_WriteCommond(0x14);
OLED_WriteCommond(0xa4);
OLED_WriteCommond(0xa6);
OLED_WriteCommond(0xaf);
OLED_Clear();
OLED_Set_Pos(0 , 0);
//OLED_Display_On();
//OLED_ShowString(0 , 0 , "OLED Test!!");
}
联系人:客服在线
手机:全工:13903011251
电话:李R:13530006400
邮箱:729986191@qq.com
地址: GUANGDONG PROVINCE