《6(100%开源)蓝牙心率防水运动手环_OLED屏幕显示.docx》由会员分享,可在线阅读,更多相关《6(100%开源)蓝牙心率防水运动手环_OLED屏幕显示.docx(9页珍藏版)》请在第一文库网上搜索。
1、蓝牙心率防水运动手环O1ED屏幕显示疯壳智能穿戴开发系列配套资料:https:/www.fengke.c1ub/GeekMart/su_fkZyGYgrp.jsp配套视频:https:/www.fengke.c1ub/GeekMart/su_fTSgU13y3.jsp1cd屏幕显示1相关简介本次1Cd屏幕显示是采用SSD1306oSSD1306是一个单片CMOSO1ED/P1ED驱动芯片可以驱动有机/聚合发光二级管点阵图形显示系统。有128SegmentS和64COmmOnS组成。该芯片专为共阴极O1ED面板设计。SSD1306中嵌入了对比度控制器、显示RAM和晶振,并因此减少了外部器件和功耗
2、。有256级亮度控制。数据/命令的发送有三种接口可选择:6800/8000串口,I2C接口或SP1接口。我们本次就是使用软件模拟I2C接口控制1CD屏幕。2硬件设计下图是我们的1CD屏幕的接口,这里使用I2C通信,SC1,SDA分别接在P25、P26o图13软件设计关于软件,首先就是要把模拟I2C的两个引脚配置成普通输出IO口,GPIO_ConfigurePin(1CD_12C_PORTzSC1zOUTPUT,PID_GPIO,fa1se);GP1c1COnfigUrePin(1CD2C_P0RT,SDA,OUTPUT,PID_GPIO,fa1se);首先模拟起始信号:当SC1为高电平期间,S
3、DA由高电平跳变到低电平。voidIIC_Start()(GPI0_SetActive(1CDJ2C_P0R1SC1)SC1=high;/De1ay_us(1);GPI0_SetActive(1CD_12C_P0RT,SDA)SDA=high;/De1ay_us(1);GPI0_Set1nactive(1CD_12C_P0RT,SDA)SDA=1ow;/De1ay_us(1);GPIC1SetInaCtiVe(1CD2C_P0RT,SC1)SC1=1ow;/De1ay_us(1);)然后是停止信号:当SC1为高电平期间,SDA由低电平跳变到高电平。voidIIC_Stop()GPI0_Set1
4、nactive(1CD_12C_P0R1SC1)SC1=1ow;/De1ay_us(1);GPIO_Set1nactive(1CD_12C_POR1SDA)SDA=1ow;/De1ay_us(1);GPIO_SetActive(1CD_12C_PORT,SC1)SC1=high;/De1ay_us(1);GPIO_SetActive(1CD_12C_PORT,SDA)SDA=high;/De1ay_us(1);)最后就是数据的传送:12C总线进行数据传送时,时钟信号为高电平期间,数据线上的数据必须保持稳定,只有在时钟线上的信号为低电平期间,数据线上的高电平或低电平状态才允许变化。voidWri
5、te_IIC_Byte(unsignedchar11C_Byte)(unsignedchari;for(i=0;i8;i+)(if(IIC_Byte&0x80)GPI0_SetActive(1CDJ2C_P0RT,SDA)SDA=high;e1seGP1oSetinactive(1CD2C_P0RT,SDA);/SDA=Iow;/De1ay_us(1);GPI0_SetActive(1CD_12C_P0R1SC1);/SC1=high;/De1ay_us(1);GP1O.Set1nactive(1CD_I2C_PORT,SC1);/SC1=Iow;/De1ay_us(1);IIC_Byte=1
6、;)GPI0_SetActive(1CD_12C_P0RT,SDA);/SDA=1;/De1ay_us(1);GPI0_SetActive(1CD_12C_P0RT,SC1);/SC1=1;/De1ay_us(1);GPI0_Set1nactive(1CD_12C_P0RT,SC1)SC1=O;/De1ay_us(1);)上面的函数De1ay_us可以根据datasheet进行更改。我们通过对SSD1306写指令,写数据,控制1CD0Co-Continuationbit1)C-I3ataCOmmandSc1cctianbitACK-Acknow1edgementWritemodeMSB1SBS
7、SDt306S1aveAddressContro1byteSAO-ShvcaddressbitR.M*-Read.WriteSe1ectionbitS-StanConditionP-StopCondition图2voidi2c_eeprom_write_byte_dgh(unsignedcharIIC_Contro1,unsignedcharIIC_Command)(IIC_Start();Write_IIC_Byte(0x78);上图中的S1aveAddressWrite_IIC_Byte(IIC_Contro1);Write_IIC_Byte(IIC_Command);D/C#位置0表示写
8、指令,1表示写数据要写的指令或数据IIC_Stop();)对于1CD,首先是初始化1CDo初始化流程以及指令数据可以数据手册。voidO1edJnit(VOid)(inti;i2c_eeprom_write_byte_dgh(0X00,OxAE);/disp1ayoffi2c_eeprom_write_byte_dgh(0X00,020);/SetMemoryAddressingModei2c_eeprom_write_byte_dgh(0X00,010);/OOzHorizontaIAddressingModejO1zVerticaIAddressingModej1OzPageAddress
9、ingMode(RESET)J11JnvaIidi2c-eeprom-write-byte-dgh(0X00,OxbO);/SetPageStartAddressforPageAddressingMode,0-7i2c_eeprom_write_byte_dgh(0X00,OxcO);/SetCOMOutputScanDirectionC0C8i2c_eeprom_write_byte_dgh(0X00,0x00);i2c_eeprom_write_byte_dgh(0X00,0x12)12i2c_eeprom_write_byte_dgh(0X00,0x40);i2c_eeprom_writ
10、e_byte_dgh(0X00,0x81);i2c-eeprom-write-byte-dgh(0X00z0x7f);i2c_eeprom_write_byte_dgh(0X00,0xa0)a1i2c_eeprom_write_byte_dgh(0X00,0xa6)a6i2c_eeprom_write_byte_dgh(0X00,0xa8);i2c_eeprom_write_byte_dgh(OXOO,O3F)1Fi2c_eeprom_write_byte_dgh(OXOO,0xa4)a4i2c_eeprom_write_byte_dgh(OXOO,Oxd3);i2c_eeprom_write
11、_byte_dgh(OXOO,OxOO);i2c_eeprom_write_byte_dgh(0X00,0xd5);i2c_eeprom_write_byte_dgh(0X00,OxfO);i2c_eeprom_write_byte_dgh(0X00,0xd9);i2c_eeprom_write_byte_dgh(0X00,0x22);i2c_eeprom_write_byte_dgh(0X00,Oxda);i2c_eeprom_write_byte_dgh(0X00,0x12)02i2c_eeprom_write_byte_dgh(0X00,Oxdb);i2c_eeprom_write_by
12、te_dgh(0X00,0x20);i2c_eeprom_write_byte_dgh(0X00,08d);i2c_eeprom_write_byte_dgh(0X00,014);i2c_eeprom_write_byte_dgh(0X00,Oxaf);for(i=0;i=5;i+)(o1ed-c1ean(0z64J);清屏)1CD初始化完成之后,就可以调用显示函数了。4实验现象首先打开SmartSnippetSo图3(I)设置好SmartSniPPetS之后,点击上图中的OPen。点击Connect,连接我们的单片机。点击BrOWSe,找到我们工程的.hex文件。图6点击Burn,完成代码下载。代码下载完成之后,运行代码,就能看到1CD上有显示图案。图片8