基于STM32的DS1302时钟模块驱动程序(详细)

目录

1.项目概述

2.DS1032的数据手册解析

   2.1 DS1302的引脚介绍

   2.2 DS1302的通讯协议及时序

   2.3 DS1302的相关寄存器

3.程序代码及其注释

4.结果演示

5.附录:7针0.96寸OLED屏驱动代码(SPI驱动)


1.项目概述 

本程序采用的主控芯片为STM32F103RCT6,通过主控芯片驱动DS1302时钟模块,并将其实时时间显示在7针0.96寸OLED屏上。使用STM32的普通IO口模拟DS1302的通信时序,使用STM32的SPI外设驱动OLED屏。下面从DS1302的数据手册开始完成整个项目。

基于STM32的DS1302时钟模块驱动程序(详细)_第1张图片

2.DS1302数据手册解析

2.1DS1302引脚介绍

基于STM32的DS1302时钟模块驱动程序(详细)_第2张图片

VCC1,VCC2是电源引脚,VCC1是主供电引脚,VCC2接备用电池,当主供电电源电量不足或者断电时,备用电池会通过VCC2及时供电,保证时钟模块在主供电引脚断电后任然会正常计时。GND是地引脚。X1,X2是有关晶振的引脚,不做深究。

CE引脚是输入引脚,在单片机从DS1302读取数据或者向其写入数据时,CE引脚必须配置为高电平。在芯片内部连接有40K下拉电阻。I/O引脚充当双向数据引脚,即数据的发送和接收都在这条线上完成。SCLK是同步时钟引脚,控制I/O引脚上数据的接收和发送。

2.2 DS1302的通讯协议及时序

基于STM32的DS1302时钟模块驱动程序(详细)_第3张图片

指令字节启动每次的数据传输,上图说明了指令字节的构造。①位7必须为逻辑1,位7为逻辑0时指令会失效。②我们使用的不是RAM当中的寄存器及数据,故位6应该为逻辑0。③位1到位5为寄存器地址。④位0为逻辑0时表明要往指定寄存器里面写数据,为逻辑1时要从指定寄存器里面读出数据。指令字节的传输总是从位0(LSB)开始传输。

基于STM32的DS1302时钟模块驱动程序(详细)_第4张图片

上图是ds1302通信时序图。

1.CE和时钟控制。

将CE置高将开启数据传输,CE输入提供俩个功能,首先CE开启了通信数据进入移位寄存器的通路,其次CE提供了一个可以终止单个字节或者多个字节的数据传输。

对于ds1302接收数据来说,每当时钟的上升沿时采集由单片机发送的数据位;对于ds1302发送数据来说,每当时钟的下降沿时便向外发送一位数据。如果CE置低,所有数据传输被终止I/O端口变为高阻态。需要注意的是,当CE被从0置为1时,时钟线必须为逻辑0。

2.向ds1302指定寄存器写一字节数据

先将CE拉高开启数据传输通道,之后通过16个时钟周期,在每个时钟上升沿由低位到高位地传输数据位,前8个时钟周期传输写指令字节,后八个时钟周期传输要写入寄存器的内容字节,最后将时钟线、CE拉低,完成数据传输。

3.从ds1302指定寄存器读一字节数据

先将CE拉高开启数据传输通道,之后在前8个时钟周期的每个上升沿由低位到高位传输读指令字节,从第8个时钟周期的下降沿开始,在每个时钟周期的下降沿ds1302由低位到高位地传输指定寄存器的内容字节,内容字节传输完毕后,最后将时钟线、CE拉低,完成数据读取。

4.这显然不是SPI通讯或者IIC通讯,固要拿STM32的GPIO端口模拟通信。

2.3DS1302的相关寄存器

基于STM32的DS1302时钟模块驱动程序(详细)_第5张图片

第一列指读取相应寄存器的读指令字节,第二列指写相应寄存器的写指令字节。时间和日历可以通过读取相对应的寄存器的值得到,同时时间和日历还可以通过向对应的寄存器写数据来设置或初始化。时间和日历寄存器内容的存储形式为BCD码。

秒寄存器:bit3-bit0为秒的个位,bit4-bit6为秒的十位,均为BCD码存储形式。bit7CH(the clock halt flag)即时钟停止标志位,bit7置1时,时钟振荡器停止,不再计时;置0时,时钟振荡器起振,开始计时。

分寄存器:bit3-bit0为分的个位,bit4-bit6为分的十位。

时寄存器:bit7为高选择12小时制,为低则选择24小时制。若24小时制,bit3-bit0为小时的个位,bit5-4为小时的十位。若12小时制,bit3-bit0为小时的个位,bit4为小时的十位,bit5为高则为PM,为低则为AM。

日期寄存器:bit3-bit0为日期的个位,bit5-bit4为日期的十位。

月寄存器:bit3-bit0为月的个位,bit4为月的十位。

星期寄存器:bit2-bit0即为星期几。

年寄存器:bit3-bit0为年的个位,bit5-bit4为年的十位。

写保护寄存器:当bit7为高时,会打开写保护,阻止向任何其它寄存器写数据;当bit7为低时,会关闭写保护,这时便可以向其它寄存器写数据。因此当我们想要配置寄存器时先要关闭写保护,写好之后再打开写保护,防止误操作。   

涓流充电寄存器:涓流充电在DS1302上电不做配置时是自动关闭的,不做深究。

3.程序代码及其注释

ds1302.h

#ifndef __ds1302_H 
#define __ds1302_H  

#include "sys.h" 

#define CE_L GPIO_ResetBits(GPIOC,GPIO_Pin_11)//拉低使能位
#define CE_H GPIO_SetBits(GPIOC,GPIO_Pin_11)//拉高使能位
#define SCLK_L GPIO_ResetBits(GPIOC,GPIO_Pin_12)//拉低时钟线
#define SCLK_H  GPIO_SetBits(GPIOC,GPIO_Pin_12)//拉高时钟线
#define DATA_L  GPIO_ResetBits(GPIOC,GPIO_Pin_10)//拉低数据线
#define DATA_H  GPIO_SetBits(GPIOC,GPIO_Pin_10)//拉高数据线

struct TIMEData
{
	u16 year;
	u8  month;
	u8  day;
	u8  hour;
	u8  minute;
	u8  second;
	u8  week;
};//创建TIMEData结构体方便存储时间日期数据
extern struct TIMEData TimeData;//全局变量
void ds1302_gpio_init();//ds1302端口初始化
void ds1302_write_onebyte(u8 data);//向ds1302发送一字节数据
void ds1302_wirte_rig(u8 address,u8 data);//向指定寄存器写一字节数据
u8 ds1302_read_rig(u8 address);//从指定寄存器读一字节数据
void ds1032_init();//ds1302初始化函数
void ds1032_DATAOUT_init();//IO端口配置为输出
void ds1032_DATAINPUT_init();//IO端口配置为输入
void ds1032_read_time();//从ds1302读取实时时间(BCD码)
void ds1032_read_realTime();//将BCD码转化为十进制数据

#endif

ds1302.c

#include "ds1302.h"
#include "sys.h"
#include "delay.h"

struct TIMEData TimeData;
u8 read_time[7];

void ds1302_gpio_init()//CE,SCLK端口初始化
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //PC.11  CE
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化GPIOC.11
GPIO_ResetBits(GPIOC,GPIO_Pin_11); 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //PC.12  SCLK
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化GPIOC.12
GPIO_ResetBits(GPIOC,GPIO_Pin_12); 
}

void ds1032_DATAOUT_init()//配置双向I/O端口为输出态
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PC.10  DATA
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化GPIOC.10
GPIO_ResetBits(GPIOC,GPIO_Pin_10);
}

void ds1032_DATAINPUT_init()//配置双向I/O端口为输入态
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PC.10 DATA
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化GPIOC.10
}


void ds1302_write_onebyte(u8 data)//向DS1302发送一字节数据
{
ds1032_DATAOUT_init();
u8 count=0;
SCLK_L;
for(count=0;count<8;count++)
	{	SCLK_L;
		if(data&0x01)
		{DATA_H;}
		else{DATA_L;}//先准备好数据再发送
		SCLK_H;//拉高时钟线,发送数据
		data>>=1;
	}
}

void ds1302_wirte_rig(u8 address,u8 data)//向指定寄存器地址发送数据
{
u8 temp1=address;
u8 temp2=data;
CE_L;SCLK_L;delay_us(1);
CE_H;delay_us(2);
ds1302_write_onebyte(temp1);
ds1302_write_onebyte(temp2);
CE_L;SCLK_L;delay_us(2);
}

u8 ds1302_read_rig(u8 address)//从指定地址读取一字节数据
{
u8 temp3=address;
u8 count=0;
u8 return_data=0x00;
CE_L;SCLK_L;delay_us(3);
CE_H;delay_us(3);
ds1302_write_onebyte(temp3);
ds1032_DATAINPUT_init();//配置I/O口为输入
delay_us(2);
for(count=0;count<8;count++)
	{
	delay_us(2);//使电平持续一段时间
	return_data>>=1;
	SCLK_H;delay_us(4);//使高电平持续一段时间
	SCLK_L;delay_us(14);//延时14us后再去读取电压,更加准确
	if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_10))
	{return_data=return_data|0x80;}
	
	}
delay_us(2);
CE_L;DATA_L;
return return_data;
}

void ds1032_init()
{
ds1302_wirte_rig(0x8e,0x00);//关闭写保护
ds1302_wirte_rig(0x80,0x37);//seconds37秒
ds1302_wirte_rig(0x82,0x58);//minutes58分
ds1302_wirte_rig(0x84,0x23);//hours23时
ds1302_wirte_rig(0x86,0x30);//date30日
ds1302_wirte_rig(0x88,0x09);//months9月
ds1302_wirte_rig(0x8a,0x07);//days星期日
ds1302_wirte_rig(0x8c,0x20);//year2020年
ds1302_wirte_rig(0x8e,0x80);//关闭写保护
}

void ds1032_read_time()
{
read_time[0]=ds1302_read_rig(0x81);//读秒
read_time[1]=ds1302_read_rig(0x83);//读分
read_time[2]=ds1302_read_rig(0x85);//读时
read_time[3]=ds1302_read_rig(0x87);//读日
read_time[4]=ds1302_read_rig(0x89);//读月
read_time[5]=ds1302_read_rig(0x8B);//读星期
read_time[6]=ds1302_read_rig(0x8D);//读年
}

void ds1032_read_realTime()
{
ds1032_read_time();  //BCD码转换为10进制
TimeData.second=(read_time[0]>>4)*10+(read_time[0]&0x0f);
TimeData.minute=((read_time[1]>>4)&(0x07))*10+(read_time[1]&0x0f);
TimeData.hour=(read_time[2]>>4)*10+(read_time[2]&0x0f);
TimeData.day=(read_time[3]>>4)*10+(read_time[3]&0x0f);
TimeData.month=(read_time[4]>>4)*10+(read_time[4]&0x0f);
TimeData.week=read_time[5];
TimeData.year=(read_time[6]>>4)*10+(read_time[6]&0x0f)+2000;
}

main.c

#include "delay.h"
#include "led.h"
#include "sys.h"
#include "ds1302.h"
#include "oled.h"
int main(void)
{
u8 min=0;
delay_init();                   //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //中断分组  
LED_Init();//LED灯初始化
      
ds1302_gpio_init();delay_ms(5); //初始化ds1302端口
ds1032_init();delay_ms(5);      //ds1302初始化
ds1032_read_realTime();         //读取实时数据
min=TimeData.minute;            //记录此时分钟值

OLED_Init();			//初始化OLED  
OLED_Clear();                   //清屏OLED
delay_ms(5);

//在OLED屏上显示实时时刻
OLED_ShowString(65,4,":");
OLED_ShowNum(80,4,TimeData.minute,2,16);
OLED_ShowNum(40,4,TimeData.hour,2,16);		
OLED_ShowNum(25,2,TimeData.year,4,16);
OLED_ShowNum(75,2,TimeData.month,2,16);
OLED_ShowNum(105,2,TimeData.day,2,16);
OLED_ShowString(60,2,"-");
OLED_ShowString(95,2,"-");
	
while(1) 	
{
ds1032_read_realTime();    //读取此时时刻
if(min==TimeData.minute)//判断分钟数是否有更新
{delay_ms(5);//没有更新便延时5ms
}
else{min=TimeData.minute;//分钟数有更新,则将变量min更新
//分钟数更新了使OLED屏更新显示
OLED_Clear();
OLED_ShowNum(80,4,TimeData.minute,2,16);
OLED_ShowNum(40,4,TimeData.hour,2,16);
OLED_ShowString(65,4,":");
OLED_ShowNum(25,2,TimeData.year,4,16);
OLED_ShowNum(75,2,TimeData.month,2,16);
OLED_ShowNum(105,2,TimeData.day,2,16);
OLED_ShowString(95,2,"-");	
OLED_ShowString(60,2,"-");
}
LED0=!LED0;
delay_ms(500);
delay_ms(500);//闪烁灯
} }

4.结果演示

基于STM32的DS1302时钟模块驱动程序(详细)_第6张图片

基于STM32的DS1302时钟模块驱动程序(详细)_第7张图片

5.附录:7针0.96寸OLED屏驱动代码(SPI驱动)

oled.c

#include "oled.h"
#include "stdlib.h"
#include "oledfont.h"    
#include "delay.h"
#include "stm32f10x_spi.h"
//OLED的显存
//存放格式如下.
//[0]0 1 2 3 ... 127 
//[1]0 1 2 3 ... 127 
//[2]0 1 2 3 ... 127 
//[3]0 1 2 3 ... 127 
//[4]0 1 2 3 ... 127 
//[5]0 1 2 3 ... 127 
//[6]0 1 2 3 ... 127 
//[7]0 1 2 3 ... 127       


//向SSD1106写入一个字节。
//dat:要写入的数据/命令
//cmd:数据/命令标志 0,表示命令;1,表示数据;
void OLED_WR_Byte(u8 dat,u8 cmd)
{      
 if(cmd)
   OLED_DC_Set();
 else 
   OLED_DC_Clr();    
 OLED_CS_Clr();
 SPI_I2S_SendData(SPI1,dat);
while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_BSY)!=RESET); 
 OLED_CS_Set();
 OLED_DC_Set();      
} 


 void OLED_Set_Pos(unsigned char x, unsigned char y) 
{ 
 OLED_WR_Byte(0xb0+y,OLED_CMD);
 OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
 OLED_WR_Byte((x&0x0f)|0x01,OLED_CMD); 
}      
//开启OLED显示    
void OLED_Display_On(void)
{
 OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
 OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
 OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
}
//关闭OLED显示     
void OLED_Display_Off(void)
{
 OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
 OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
 OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
}         
//清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!   
void OLED_Clear(void)  
{  
 u8 i,n;      
 for(i=0;i<8;i++)  
 {  
  OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
  OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
  OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址   
  for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA); 
 } //更新显示
}

//在指定位置显示一个字符,包括部分字符
//x:0~127
//y:0~63
//mode:0,反白显示;1,正常显示     
//size:选择字体 16/12 
void OLED_ShowChar(u8 x,u8 y,u8 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_WR_Byte(F8X16[c*16+i],OLED_DATA);
   OLED_Set_Pos(x,y+1);
   for(i=0;i<8;i++)
   OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
   }
   else { 
    OLED_Set_Pos(x,y+1);
    for(i=0;i<6;i++)
    OLED_WR_Byte(F6x8[c][i],OLED_DATA);   
   }
}
//m^n函数
u32 oled_pow(u8 m,u8 n)
{
 u32 result=1;  
 while(n--)result*=m;    
 return result;
}      
//显示2个数字
//x,y :起点坐标  
//len :数字的位数
//size:字体大小
//mode:模式 0,填充模式;1,叠加模式
//num:数值(0~4294967295);      
void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size)
{          
 u8 t,temp;
 u8 enshow=0;         
 for(t=0;t120){x=0;y+=2;}
   j++;
 }
}
//显示汉字
void OLED_ShowCHinese(u8 x,u8 y,u8 no)
{             
 u8 t,adder=0;
 OLED_Set_Pos(x,y); 
    for(t=0;t<16;t++)
  {
    OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
    adder+=1;
     } 
  OLED_Set_Pos(x,y+1); 
    for(t=0;t<16;t++)
   { 
    OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
    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

 oled.h

#ifndef __OLED_H
#define __OLED_H       
#include "sys.h"
#include "stdlib.h"      

#define SIZE 16
#define XLevelL  0x00
#define XLevelH  0x10
#define Max_Column 128
#define Max_Row  64
#define Brightness 0xFF 
#define X_WIDTH  128
#define Y_WIDTH  64    

//-----------------OLED端口定义----------------          

#define OLED_RST_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_10)//RES
#define OLED_RST_Set() GPIO_SetBits(GPIOB,GPIO_Pin_10)

#define OLED_DC_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_9)//DC
#define OLED_DC_Set() GPIO_SetBits(GPIOB,GPIO_Pin_9)       

#define OLED_CS_Clr()  GPIO_ResetBits(GPIOB,GPIO_Pin_8)//CS
#define OLED_CS_Set()  GPIO_SetBits(GPIOB,GPIO_Pin_8)

#define OLED_CMD  0 //写命令
#define OLED_DATA 1 //写数据

//OLED控制用函数
void SetupSPI();
void OLED_WR_Byte(u8 dat,u8 cmd);     
void OLED_Display_On(void);
void OLED_Display_Off(void);                    
void OLED_Init(void);
void OLED_Clear(void);
void OLED_DrawPoint(u8 x,u8 y,u8 t);
void OLED_Fill(u8 x1,u8 y1,u8 x2,u8 y2,u8 dot);
void OLED_ShowChar(u8 x,u8 y,u8 chr);
void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size);
void OLED_ShowString(u8 x,u8 y, u8 *p);  
void OLED_Set_Pos(unsigned char x, unsigned char y);
void OLED_ShowCHinese(u8 x,u8 y,u8 no);
void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[]);
#endif  

oledfont.h

#ifndef __OLEDFONT_H
#define __OLEDFONT_H     
//常用ASCII表
//偏移量32
//ASCII字符集
//偏移量32
//大小:12*6
/************************************6*8的点阵************************************/
const unsigned char F6x8[][6] =  
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
};
/****************************************8*16的点阵************************************/
const unsigned char F8X16[]=   
{
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
  0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
  0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
  0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
  0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
  0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
  0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
  0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
  0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
  0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
  0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
  0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
  0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
  0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
  0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
  0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
  0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
  0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
  0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
  0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
  0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
  0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
  0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
  0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
  0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
  0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
  0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
  0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
  0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
  0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
  0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
  0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
  0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
  0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
  0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
  0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
  0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
  0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
  0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
  0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
  0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
  0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
  0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
  0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
  0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
  0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
  0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
  0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
  0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
  0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
  0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
  0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
  0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
  0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
  0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
  0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
  0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
  0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
  0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
  0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
  0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
  0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
  0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
  0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
  0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
  0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
  0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
  0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
  0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
  0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
  0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
  0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
  0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
  0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};

char Hzk[][32]={
{0x20,0x24,0x24,0x24,0xFE,0x23,0x22,0x20,0x20,0xFF,0x20,0x22,0x2C,0xA0,0x20,0x00},
{0x00,0x08,0x48,0x84,0x7F,0x02,0x41,0x40,0x20,0x13,0x0C,0x14,0x22,0x41,0xF8,0x00},/*"我",0*/
{0x80,0x64,0x2C,0x34,0x24,0x24,0xEC,0x32,0x22,0x22,0x32,0x2E,0x23,0xA2,0x60,0x00},
{0x00,0x41,0x21,0x91,0x89,0x87,0x4D,0x55,0x25,0x25,0x55,0x4D,0x81,0x80,0x80,0x00},/*"爱",1*/
{0x00,0x80,0x60,0xF8,0x07,0x40,0x20,0x18,0x0F,0x08,0xC8,0x08,0x08,0x28,0x18,0x00},
{0x01,0x00,0x00,0xFF,0x00,0x10,0x0C,0x03,0x40,0x80,0x7F,0x00,0x01,0x06,0x18,0x00},/*"你",2*/
{0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00},
{0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00},/*"中",3*/
{0x00,0xFE,0x02,0x12,0x92,0x92,0x92,0xF2,0x92,0x92,0x92,0x12,0x02,0xFE,0x00,0x00},
{0x00,0xFF,0x40,0x48,0x48,0x48,0x48,0x4F,0x48,0x4A,0x4C,0x48,0x40,0xFF,0x00,0x00},/*"国",4*/
};

#endif

 

你可能感兴趣的:(基于STM32的DS1302时钟模块驱动程序(详细))