版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
單片機(jī)溫濕度控制藍(lán)牙傳輸系統(tǒng)設(shè)計(jì)DesignofBluetoothTransmissionSystemforTemperatureandHumidityControlofSingleChipMicrocomputer年月目錄15612摘要 頁(yè)參考文獻(xiàn)[1]曾非一.嵌入式軟件開發(fā)技術(shù)研究—MPC860目標(biāo)機(jī)底層軟件的實(shí)現(xiàn)[D].電子科技大學(xué),2014.[2]孫寶元、楊寶清.傳感器及其應(yīng)用手冊(cè).北京.[3]
鄭人杰.
計(jì)算機(jī)軟件測(cè)試技術(shù).
北京:
清華大學(xué)出版社,
1992.
[4]任強(qiáng).傳感器選用原則.計(jì)量工作.2004.[5]李全利.單片機(jī)原理及應(yīng)用技術(shù).北京:高等教育出版社.2009.30~46.[6]
鄭人杰.
計(jì)算機(jī)軟件測(cè)試技術(shù).
北京:
清華大學(xué)出版社,
1992.
[7]
胡漢才.
單片機(jī)原理及系統(tǒng)設(shè)計(jì).
北京:清華大學(xué)出版社,
2002.
[8]
Silicon
Storage
Technology
Inc,
SST39VF800A
Datasheet.2001
.[9]張俊謨.單片機(jī)中級(jí)教程原理與應(yīng)用.北京航空航天大學(xué)出版社.2002.[10]
趙負(fù)圖,傳感器集成電路手冊(cè),第一版,化學(xué)工業(yè)出版社,2004,590~591
.[11]
馬建國(guó).電子系統(tǒng)設(shè)計(jì).北京:高等教育出版社,2004.1.
[12]
譚浩強(qiáng).C程序設(shè)計(jì)(第三版).北京:清華大學(xué)出版社,2005.7
.[13]
霍孟友.單片機(jī)原理與應(yīng)用[M
].北京:機(jī)械工業(yè)出版社,2004.
[14]
何立民,單片機(jī)應(yīng)用系統(tǒng)設(shè)計(jì),北京:航天航空大學(xué)出版社,2~5,46~50.
[15]
李廣弟,單片機(jī)基礎(chǔ),北京:北京航空航天大學(xué)出版社,2001,56~64.
[16]
何希才,新型實(shí)用電子電路400例,電子工業(yè)出版社,2000年,60~65.
[17]
Wolf
W,
孫玉芳等譯.
嵌入式計(jì)算系統(tǒng)設(shè)計(jì)原理.
北京:
機(jī)械工業(yè)出版社,
2002.
[18]
Integrated
Silicon
Solution
Inc.
IS61LVI2816
Datasheet.2002.
[19]
熊媛.傳感器技術(shù)在自動(dòng)控制系統(tǒng)中的應(yīng)用及發(fā)展展望[J].工業(yè)設(shè)計(jì),2016,10(8):12-15.[20]
[楊振江,蔡德芳·新型集成電路使用指南與典型應(yīng)用[M]·西安:西安電子科技大學(xué)出版社1998.10[21]
盧本,王君.材料成形過程的測(cè)量與控制[M].上海:機(jī)械工業(yè)出版社,2005.[22]
方琳.基于ARM的智能家居系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)[D].南京郵電大學(xué),2015.[23]
蔚承英,陳勇剛,楊利平等.基于GPRS和嵌入式計(jì)算機(jī)的遠(yuǎn)程監(jiān)控系統(tǒng)研究[J].安防科技,2016,2(12):18-20.[24]
楊希.無(wú)線傳感器網(wǎng)絡(luò)協(xié)議棧與定位技術(shù)的研究與實(shí)現(xiàn)[D].東南大學(xué),2012.[25]
楊曉芬.基于無(wú)線傳感器網(wǎng)絡(luò)的博物館環(huán)境監(jiān)測(cè)系統(tǒng)[J].電子世界,2016,19(10):75-78.[26]
XiaojingX,KunhuiL.ResearchonKeyTechnologiesofspeechrecognition.computerengineeringandApplication,2006,42(11):66-69.附錄1原理圖附錄2源程序#include"stm32f10x.h"#include"bsp_dht11.h"#include"bsp_usart1.h"#include"stm32f10x_it.h"#include"bsp_led.h"DHT11_Data_TypeDefDHT11_Data;uint8_tdata,data1;voidbuzzer_di(void);voiddelay(uint32_ti){ while(i--);}voidRelay(){ if(data>DHT11_Data.humi_int) { LED1_OFF; buzzer_di(); } else { LED1_ON; } if(data1>DHT11_Data.temp_int) { LED2_OFF; buzzer_di(); } else { LED2_ON; } }voidbuzzer_di(){ GPIO_SetBits(GPIOB,GPIO_Pin_11); delay(0xffff); GPIO_ResetBits(GPIOB,GPIO_Pin_11);}/*********************************************ENDOFFILE**********************/intmain(void){ USART1_Config(); NVIC_Configuration(); LED_GPIO_Config(); BUZZER_GPIO_Config(); /*初始化DTT11的引腳*/ DHT11_GPIO_Config(); while(1) { /*調(diào)用Read_DHT11讀取溫濕度,若成功則輸出該信息*/ if(Read_DHT11(&DHT11_Data)==SUCCESS) { Usart_SendByte(USART1,DHT11_Data.humi_int); Usart_SendByte(USART1,DHT11_Data.temp_int); Relay(); delay(0xffffff); } else { printf("ReadDHT11ERROR!\r\n"); } delay(0xffffff); }}#include"bsp_dht11.h"voiddelay_us(u32time){u32i=8*time;while(i--);}voiddelay_ms(u32nTimer){ u32i=1000*nTimer; delay_us(i);}/**函數(shù)名:DHT11_GPIO_Config*描述:配置DHT11用到的I/O口*輸入:無(wú)*輸出:無(wú)*/voidDHT11_GPIO_Config(void){ /*定義一個(gè)GPIO_InitTypeDef類型的結(jié)構(gòu)體*/ GPIO_InitTypeDefGPIO_InitStructure; /*開啟DHT11_PORT的外設(shè)時(shí)鐘*/ RCC_APB2PeriphClockCmd(DHT11_CLK,ENABLE); /*選擇要控制的DHT11_PORT引腳*/ GPIO_InitStructure.GPIO_Pin=DHT11_PIN; /*設(shè)置引腳模式為通用推挽輸出*/ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; /*設(shè)置引腳速率為50MHz*/ GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; /*調(diào)用庫(kù)函數(shù),初始化DHT11_PORT*/ GPIO_Init(DHT11_PORT,&GPIO_InitStructure); /*拉高GPIOB10 */ GPIO_SetBits(DHT11_PORT,GPIO_Pin_10); }/**函數(shù)名:DHT11_Mode_IPU*描述:使DHT11-DATA引腳變?yōu)樯侠斎肽J?輸入:無(wú)*輸出:無(wú)*/staticvoidDHT11_Mode_IPU(void){ GPIO_InitTypeDefGPIO_InitStructure; /*選擇要控制的DHT11_PORT引腳*/ GPIO_InitStructure.GPIO_Pin=DHT11_PIN; /*設(shè)置引腳模式為浮空輸入模式*/ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; /*調(diào)用庫(kù)函數(shù),初始化DHT11_PORT*/ GPIO_Init(DHT11_PORT,&GPIO_InitStructure); }/**函數(shù)名:DHT11_Mode_Out_PP*描述:使DHT11-DATA引腳變?yōu)橥仆燧敵瞿J?輸入:無(wú)*輸出:無(wú)*/staticvoidDHT11_Mode_Out_PP(void){ GPIO_InitTypeDefGPIO_InitStructure; /*選擇要控制的DHT11_PORT引腳*/ GPIO_InitStructure.GPIO_Pin=DHT11_PIN; /*設(shè)置引腳模式為通用推挽輸出*/ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; /*設(shè)置引腳速率為50MHz*/ GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; /*調(diào)用庫(kù)函數(shù),初始化DHT11_PORT*/ GPIO_Init(DHT11_PORT,&GPIO_InitStructure); }/**從DHT11讀取一個(gè)字節(jié),MSB先行*/staticuint8_tRead_Byte(void){ uint8_ti,temp=0; for(i=0;i<8;i++) { /*每bit以50us低電平標(biāo)置開始,輪詢直到從機(jī)發(fā)出的50us低電平結(jié)束*/ while(DHT11_DATA_IN()==Bit_RESET); /*DHT11以26~28us的高電平表示“0”,以70us高電平表示“1”, *通過檢測(cè)xus后的電平即可區(qū)別這兩個(gè)狀,x即下面的延時(shí) */ delay_us(40);//延時(shí)xus這個(gè)延時(shí)需要大于數(shù)據(jù)0持續(xù)的時(shí)間即可 if(DHT11_DATA_IN()==Bit_SET)/*xus后仍為高電平表示數(shù)據(jù)“1”*/ { /*等待數(shù)據(jù)1的高電平結(jié)束*/ while(DHT11_DATA_IN()==Bit_SET); temp|=(uint8_t)(0x01<<(7-i));//把第7-i位置1,MSB先行 } else //xus后為低電平表示數(shù)據(jù)“0” { temp&=(uint8_t)~(0x01<<(7-i));//把第7-i位置0,MSB先行 } } returntemp;}/**一次完整的數(shù)據(jù)傳輸為40bit,高位先出*8bit濕度整數(shù)+8bit濕度小數(shù)+8bit溫度整數(shù)+8bit溫度小數(shù)+8bit校驗(yàn)和*/uint8_tRead_DHT11(DHT11_Data_TypeDef*DHT11_Data){ /*輸出模式*/ DHT11_Mode_Out_PP(); /*主機(jī)拉低*/ DHT11_DATA_OUT(LOW); /*延時(shí)18ms*/ delay_ms(18); /*總線拉高主機(jī)延時(shí)30us*/ DHT11_DATA_OUT(HIGH); delay_us(30);//延時(shí)30us /*主機(jī)設(shè)為輸入判斷從機(jī)響應(yīng)信號(hào)*/ DHT11_Mode_IPU(); /*判斷從機(jī)是否有低電平響應(yīng)信號(hào)如不響應(yīng)則跳出,響應(yīng)則向下運(yùn)行*/ if(DHT11_DATA_IN()==Bit_RESET) { /*輪詢直到從機(jī)發(fā)出的80us低電平響應(yīng)信號(hào)結(jié)束*/ while(DHT11_DATA_IN()==Bit_RESET); /*輪詢直到從機(jī)發(fā)出的80us高電平標(biāo)置信號(hào)結(jié)束*/ while(DHT11_DATA_IN()==Bit_SET); /*開始接收數(shù)據(jù)*/ DHT11_Data->humi_int=Read_Byte(); DHT11_Data->humi_deci=Read_Byte(); DHT11_Data->temp_int=Read_Byte(); DHT11_Data->temp_deci=Read_Byte(); DHT11_Data->check_sum=Read_Byte(); /*讀取結(jié)束,引腳改為輸出模式*/ DHT11_Mode_Out_PP(); /*主機(jī)拉高*/ DHT11_DATA_OUT(HIGH); /*檢查讀取的數(shù)據(jù)是否正確*/ if(DHT11_Data->check_sum==DHT11_Data->humi_int+DHT11_Data->humi_deci+DHT11_Data->temp_int+DHT11_Data->temp_deci) returnSUCCESS; else returnERROR; } else { returnERROR; }}/*************************************ENDOFFILE******************************/#ifndef__DHT11_H#define __DHT11_H#include"stm32f10x.h"#defineHIGH1#defineLOW0#defineDHT11_CLKRCC_APB2Periph_GPIOB#defineDHT11_PINGPIO_Pin_10#defineDHT11_PORT GPIOB//帶參宏,可以像內(nèi)聯(lián)函數(shù)一樣使用,輸出高電平或低電平#defineDHT11_DATA_OUT(a) if(a) \ GPIO_SetBits(GPIOB,GPIO_Pin_10);\ else \ GPIO_ResetBits(GPIOB,GPIO_Pin_10)//讀取引腳的電平#defineDHT11_DATA_IN() GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_10)typedefstruct{ uint8_thumi_int; //濕度的整數(shù)部分 uint8_thumi_deci; //濕度的小數(shù)部分 uint8_ttemp_int; //溫度的整數(shù)部分 uint8_ttemp_deci; //溫度的小數(shù)部分 uint8_tcheck_sum; //校驗(yàn)和 }DHT11_Data_TypeDef;voidDHT11_GPIO_Config(void);staticvoidDHT11_Mode_IPU(void);staticvoidDHT11_Mode_Out_PP(void);uint8_tRead_DHT11(DHT11_Data_TypeDef*DHT11_Data);staticuint8_tRead_Byte(void);#endif/*__DHT11_H*//*********************************************************************************@filebsp_usart1.c*@authorfire*@versionV1.0*@date2013-xx-xx*@brief重現(xiàn)c庫(kù)printf函數(shù)到usart端口*******************************************************************************@attention**實(shí)驗(yàn)平臺(tái):野火ISO-MINISTM32開發(fā)板*論壇:*淘寶:********************************************************************************/#include"bsp_usart1.h"#include"misc.h"/***@briefUSART1GPIO配置,工作模式配置。1152008-N-1*@param無(wú)*@retval無(wú)*/voidUSART1_Config(void){ GPIO_InitTypeDefGPIO_InitStructure; USART_InitTypeDefUSART_InitStructure; /*configUSART1clock*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA,ENABLE); /*USART1GPIOconfig*/ /*ConfigureUSART1Tx(PA.09)asalternatefunctionpush-pull*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); /*ConfigureUSART1Rx(PA.10)asinputfloating*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA,&GPIO_InitStructure); /*USART1modeconfig*/ USART_InitStructure.USART_BaudRate=38400; USART_InitStructure.USART_WordLength=USART_WordLength_8b; USART_InitStructure.USART_StopBits=USART_StopBits_1; USART_InitStructure.USART_Parity=USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx; USART_Init(USART1,&USART_InitStructure); /*使能串口1接收中斷*/ USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); USART_Cmd(USART1,ENABLE);}voidNVIC_Configuration(void){ NVIC_InitTypeDefNVIC_InitStructure; /*ConfiguretheNVICPreemptionPriorityBits*/ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); /*EnabletheUSARTyInterrupt*/ NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure);}voidUsart_SendByte(USART_TypeDef*pUSARTx,uint8_tch){ /*發(fā)送一個(gè)字節(jié)數(shù)據(jù)到USART*/ USART_SendData(pUSARTx,ch); /*等待發(fā)送數(shù)據(jù)寄存器為空*/ while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TXE)==RESET); }///重定向c庫(kù)函數(shù)printf到USART1intfputc(intch,FILE*f){ /*發(fā)送一個(gè)字節(jié)數(shù)據(jù)到USART1*/ USART_SendData(USART1,(uint8_t)ch); /*等待發(fā)送完畢*/ while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET); return(ch);}///重定向c庫(kù)函數(shù)scanf到USART1intfgetc(FILE*f){ /*等待串口1輸入數(shù)據(jù)*/ while(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET); return(int)USART_ReceiveData(USART1);}/*********************************************ENDOFFILE**********************/#ifndef__USART1_H#define __USART1_H#include"stm32f10x.h"#include<stdio.h>voidUSART1_Config(void);voidUsart_SendByte(USART_TypeDef*pUSARTx,uint8_tch);voidNVIC_Configuration(void);//intfputc(intch,FILE*f);//voidUSART1_printf(USART_TypeDef*USARTx,uint8_t*Data,...);#endif/*__USART1_H*//*********************************************************************************@filebsp_led.c*@authorfire*@versionV1.0*@date2013-xx-xx*@briefled應(yīng)用函數(shù)接口*************************************************************************************************************************************************************/#include"bsp_led.h"/***@brief初始化控制LED的IO*@param無(wú)*@retval無(wú)*/voidLED_GPIO_Config(void){ /*定義一個(gè)GPIO_InitTypeDef類型的結(jié)構(gòu)體*/ GPIO_InitTypeDefGPIO_InitStructure; /*開啟LED的外設(shè)時(shí)鐘*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); /*選擇要控制的GPIOB引腳*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0; /*設(shè)置引腳模式為通用推挽輸出*/ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD; /*設(shè)置引腳速率為50MHz*/ GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; /*調(diào)用庫(kù)函數(shù),初始化GPIOB0*/ GPIO_Init(GPIOB,&GPIO_InitStructure); /*選擇要控制的引腳*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1; GPIO_Init(GPIOB,&GPIO_InitStructure); /*關(guān)閉所有l(wèi)ed燈 */ GPIO_SetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1); }voidBUZZER_GPIO_Config(void){ /*定義一個(gè)GPIO_InitTypeDef類型的結(jié)構(gòu)體*/ GPIO_InitTypeDefGPIO_InitStructure; /*開啟LED的外設(shè)時(shí)鐘*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); /*選擇要控制的GPIOB引腳*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11; /*設(shè)置引腳模式為通用推挽輸出*/ GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; /*設(shè)置引腳速率為50MHz*/ GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; /*調(diào)用庫(kù)函數(shù),初始化GPIOB0*/ GPIO_Init(GPIOB,&GPIO_InitStructure); /*關(guān)閉所有l(wèi)ed燈 */ GPIO_ResetBits(GPIOB,GPIO_Pin_11); }/*********************************************ENDOFFILE**********************/#ifndef__LED_H#define __LED_H#include"stm32f10x.h"/**themacrodefinitiontotriggertheledonoroff*1-off*0-on*/#defineON0#defineOFF1/*帶參宏,可以像內(nèi)聯(lián)函數(shù)一樣使用*/#defineLED1(a) if(a) \ GPIO_SetBits(GPIOB,GPIO_Pin_0);\ else \ GPIO_ResetBits(GPIOB,GPIO_Pin_0)#defineLED2(a) if(a) \ GPIO_SetBits(GPIOB,GPIO_Pin_1);\ else \ GPIO_ResetBits(GPIOB,GPIO_Pin_1)#defineLED3(a) if(a) \ GPIO_SetBits(GPIOB,GPIO_Pin_11);\ else \ GPIO_ResetBits(GPIOB,GPIO_Pin_11)/*直接操作寄存器的方法控制IO*/#define digitalHi(p,i) {p->BSRR=i;} //設(shè)置為高電平 #definedigitalLo(p,i) {p->BRR=i;} //輸出低電平#definedigitalToggle(p,i) {p->ODR^=i;} //輸出反轉(zhuǎn)狀態(tài)/*定義控制IO的宏*/#defineLED1_TOGGLE digitalToggle(GPIOB,GPIO_Pin_0)#defineLED1_OFF digitalHi(GPIOB,GPIO_Pin_0)#defineLED1_ON digitalLo(GPIOB,GPIO_Pin_0)#defineLED2_TOGGLE digitalToggle(GPIOB,GPIO_Pin_1)#defineLED2_OFF digitalHi(GPIOB,GPIO_Pin_1)#defineLED2_ON digitalLo(GPIOB,GPIO_Pin_1)#defineLED3_TOGGLE digitalToggle(GPIOB,GPIO_Pin_11)#defineLED3_OFF digitalHi(GPIOB,GPIO_Pin_11)#defineLED3_ON digitalLo(GPIOB,GPIO_Pin_11)voidLED_GPIO_Config(void);voidBUZZER_GPIO_Config(void);#endif/*__LED_H*/voidUSART1_IRQHandler(void){ if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET) { data=getchar(); data1=getchar(); } }voidKEY1_IRQHandler(void){ Key_Delay(10000);//確保是否產(chǎn)生了EXTILine中斷 if(EXTI_GetITStatus(KEY1_INT_EXTI_LINE)!=RESET) { //LED1取反 humi=humi+1;//清除中斷標(biāo)志位 EXTI_ClearITPendingBit(KEY1_INT_EXTI_LINE); }}voidKEY2_IRQHandler(void){ Key_Delay(10000);//確保是否產(chǎn)生了EXTILine中斷 if(EXTI_GetITStatus(KEY2_INT_EXTI_LINE)!=RESET) { //LED2取反 temp=temp+1;//清除中斷標(biāo)志位 EXTI_ClearITPendingBit(KEY2_INT_EXTI_LINE); }}voidUSART1_IRQHandler(void){ if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET) { data=getchar(); data1=getchar(); }}/*************************************************************************************Copyright(c),2014,HelTecAutomaticTechnologyco.,LTD.*Allrightsreserved.**Http:*Email:cn.heltec@*WebShop:**Filename:OLED_I2C.c*Project:HelTec.uvprij*Processor:STM32F103C8T6*Compiler:MDKfoARM**Author:小林*Version:1.00*Date:2014.4.8*Email:hello14blog@*Modification:none**Description:128*64點(diǎn)陣的OLED顯示屏驅(qū)動(dòng)文件,僅適用于惠特自動(dòng)化()的SD1306驅(qū)動(dòng)IIC通信方式顯示屏**Others:none;**FunctionList:* 1.voidI2C_Configuration(void)--配置CPU的硬件I2C*2.voidI2C_WriteByte(uint8_taddr,uint8_tdata)--向寄存器地址寫一個(gè)byte的數(shù)據(jù)*3.voidWriteCmd(unsignedcharI2C_Command)--寫命令*4.voidWriteDat(unsignedcharI2C_Data)--寫數(shù)據(jù)*5.voidOLED_Init(void)--OLED屏初始化*6.voidOLED_SetPos(unsignedcharx,unsignedchary)--設(shè)置起始點(diǎn)坐標(biāo)*7.voidOLED_Fill(unsignedcharfill_Data)--全屏填充*8.voidOLED_CLS(void)--清屏*9.voidOLED_ON(void)--喚醒*10.voidOLED_OFF(void)--睡眠*11.voidOLED_ShowStr(unsignedcharx,unsignedchary,unsignedcharch[],unsignedcharTextSize)--顯示字符串(字體大小有6*8和8*16兩種)*12.voidOLED_ShowCN(unsignedcharx,unsignedchary,unsignedcharN)--顯示中文(中文需要先取模,然后放到codetab.h中)*13.voidOLED_DrawBMP(unsignedcharx0,unsignedchary0,unsignedcharx1,unsignedchary1,unsignedcharBMP[])--BMP圖片**History:none;**************************************************************************************/#include"stm32f10x_i2c.h"#include"OLED_I2C.h"#include"delay.h"#include"codetab.h"voidI2C_Configuration(void){ I2C_InitTypeDefI2C_InitStructure; GPIO_InitTypeDefGPIO_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); /*STM32F103C8T6芯片的硬件I2C:PB6--SCL;PB7--SDA*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_OD;//I2C必須開漏輸出 GPIO_Init(GPIOB,&GPIO_InitStructure); I2C_DeInit(I2C1);//使用I2C1 I2C_InitStructure.I2C_Mode=I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle=I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1=0x30;//主機(jī)的I2C地址,隨便寫的 I2C_InitStructure.I2C_Ack=I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress=I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed=400000;//400K I2C_Cmd(I2C1,ENABLE); I2C_Init(I2C1,&I2C_InitStructure);}voidI2C_WriteByte(uint8_taddr,uint8_tdata){while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)); I2C_GenerateSTART(I2C1,ENABLE);//開啟I2C1 while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT));/*EV5,主模式*/ I2C_Send7bitAddress(I2C1,OLED_ADDRESS,I2C_Direction_Transmitter);//器件地址--默認(rèn)0x78 while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); I2C_SendData(I2C1,addr);//寄存器地址 while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)); I2C_SendData(I2C1,data);//發(fā)送數(shù)據(jù) while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)); I2C_GenerateSTOP(I2C1,ENABLE);//關(guān)閉I2C1總線}voidWriteCmd(unsignedcharI2C_Command)//寫命令{ I2C_WriteByte(0x00,I2C_Command);}voidWriteDat(unsignedcharI2C_Data)//寫數(shù)據(jù){ I2C_WriteByte(0x40,I2C_Data);}voidOLED_Init(void){ DelayMs(100);//這里的延時(shí)很重要 WriteCmd(0xAE);//displayoff WriteCmd(0x20); //SetMemoryAddressingMode WriteCmd(0x10); //00,HorizontalAddressingMode;01,VerticalAddressingMode;10,PageAddressingMode(RESET);11,Invalid WriteCmd(0xb0); //SetPageStartAddressforPageAddressingMode,0-7 WriteCmd(0xc8); //SetCOMOutputScanDirection WriteCmd(0x00);//setlowcolumnaddress WriteCmd(0x10);//sethighcolumnaddress WriteCmd(0x40);//--setstartlineaddress WriteCmd(0x81);//--setcontrastcontrolregister WriteCmd(0xff);//亮度調(diào)節(jié)0x00~0xff WriteCmd(0xa1);//--setsegmentre-map0to127 WriteCmd(0xa6);//--setnormaldisplay WriteCmd(0xa8);//--setmultiplexratio(1to64) WriteCmd(0x3F);// WriteCmd(0xa4);//0xa4,OutputfollowsRAMcontent;0xa5,OutputignoresRAMcontent WriteCmd(0xd3);//-setdisplayoffset WriteCmd(0x00);//-notoffset WriteCmd(0xd5);//--setdisplayclockdivideratio/oscillatorfrequency WriteCmd(0xf0);//--setdivideratio WriteCmd(0xd9);//--setpre-chargeperiod WriteCmd(0x22);// WriteCmd(0xda);//--setcompinshardwareconfiguration WriteCmd(0x12); WriteCmd(0xdb);//--setvcomh WriteCmd(0x20);//0x20,0.77xVcc WriteCmd(0x8d);//--setDC-DCenable WriteCmd(0x14);// WriteCmd(0xaf);//--turnonoledpanel}voidOLED_SetPos(unsignedcharx,unsignedchary)//設(shè)置起始點(diǎn)坐標(biāo){ WriteCmd(0xb0+y); WriteCmd(((x&0xf0)>>4)|0x10); WriteCmd((x&0x0f)|0x01);}voidOLED_Fill(unsignedcharfill_Data)//全屏填充{ unsignedcharm,n; for(m=0;m<8;m++) { WriteCmd(0xb0+m); //page1 WriteCmd(0x00); //lowcolumnstartaddress WriteCmd(0x10); //highcolumnstartaddress for(n=0;n<128;n++) { WriteDat(fill_Data); } }}voidOLED_CLS(void)//清屏{ OLED_Fill(0x00);}////Prototype:voidOLED_ON(void)//Calls://Parameters:none//Description:將OLED從休眠中喚醒//voidOLED_ON(void){ WriteCmd(0X8D);//設(shè)置電荷泵 WriteCmd(0X14);//開啟電荷泵 WriteCmd(0XAF);//OLED喚醒}////Prototype:voidOLED_OFF(void)//Calls://Parameters:none//Description:讓OLED休眠--休眠模式下,OLED功耗不到10uA//voidOLED_OFF(void){ WriteCmd(0X8D);//設(shè)置電荷泵 WriteCmd(0X10);//關(guān)閉電荷泵 WriteCmd(0XAE);//OLED休眠}////Prototype:voidOLED_ShowChar(unsignedcharx,unsignedchary,unsignedcharch[],unsignedcharTextSize)//Calls://Parameters:x,y--起始點(diǎn)坐標(biāo)(x:0~127,y:0~7);ch[]--要顯示的字符串;TextSize--字符大小(1:6*8;2:8*16)//Description:顯示codetab.h中的ASCII字符,有6*8和8*16可選擇//voidOLED_ShowStr(unsignedcharx,unsignedchary,unsignedcharch[],unsignedcharTextSize){ unsignedcharc=0,i=0,j=0; switch(TextSize) { case1: { while(ch[j]!='\0') { c=ch[j]-32; if(x>126) { x=0; y++; } OLED_SetPos(x,y); for(i=0;i<6;i++) WriteDat(F6x8[c][i]); x+=6; j++; } }break; case2: { while(ch[j]!='\0') { c=ch[j]-32; if(x>120) { x=0; y++; } OLED_SetPos(x,y); for(i=0;i<8;i++) WriteDat(F8X16[c*16+i]); OLED_SetPos(x,y+1); for(i=0;i<8;i++) WriteDat(F8X16[c*16+i+8]); x+=8; j++; } }break; }}////Prototype:voidOLED_ShowCN(unsignedcharx,unsignedchary,unsignedcharN)//Calls://Parameters:x,y--起始點(diǎn)坐標(biāo)(x:0~127,y:0~7);N:漢字在codetab.h中的索引//Description:顯示codetab.h中的漢字,16*16點(diǎn)陣//voidOLED_ShowCN(unsignedcharx,unsignedchary,unsignedcharN){ unsignedcharwm=0; unsignedintadder=32*N; OLED_SetPos(x,y); for(wm=0;wm<16;wm++) { WriteDat(F16x16[adder]); adder+=1; } OLED_SetPos(x,y+1); for(wm=0;wm<16;wm++) { WriteDat(F16x16[adder]); adder+=1; }}////Prototype:voidOLED_DrawBMP(unsignedcharx0,unsignedchary0,unsignedcharx1,unsignedchary1,unsignedcharBMP[]);//Calls://Parameters:x0,y0--起始點(diǎn)坐標(biāo)(x0:0~127,y0:0~7);x1,y1--起點(diǎn)對(duì)角線(結(jié)束點(diǎn))的坐標(biāo)(x1:1~128,y1:1~8)//Description:顯示BMP位圖//voidOLED_DrawBMP(unsignedcharx0,unsignedchary0,unsignedcharx1,unsignedchary1,unsignedcharBMP[]){ unsignedintj=0; unsignedcharx,y;if(y1%8==0) y=y1/8;else y=y1/8+1; for(y=y0;y<y1;y++) { OLED_SetPos(x0,y);for(x=x0;x<x1;x++) { WriteDat(BMP[j++]); } }}/*************************************************************************************Copyright(c),2015,HelTecAutomaticTechnologyco.,LTD.*Allrightsreserved.**Http:*Email:cn.heltec@*WebShop:**Filename:OLED.h*Project:OLED*Processor:STC89C52*Compiler:KeilC51Compiler**Author:AaronLee*Version:1.00*Date:2014.3.24*Email:hello14blog@*Modification:none**Description:*1.128*64點(diǎn)整OLED模塊功能演示程序的字表,僅適用所售產(chǎn)品;*2.字表由打包資料中的“取字軟件”計(jì)算得出;*3.取字方式--共陰、列行式、逆向輸出**Others:none;**FunctionList:none;**History:none;**************************************************************************************//***************************16*16的點(diǎn)陣字體取模方式:共陰——列行式——逆向輸出*********/unsignedcharF16x16[]={ 0x00,0x00,0xC0,0xE0,0x30,0x10,0x08,0x08,0x08,0x08,0x08,0x18,0x30,0xE0,0xC0,0x00, 0x00,0x00,0x07,0x0F,0x18,0x10,0x20,0x20,0x20,0x20,0x20,0x10,0x18,0x0F,0x07,0x00,//00, 0x00,0x00,0x00,0x10,0x10,0x10,0x10,0xF0,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x3F,0x3F,0x20,0x20,0x20,0x20,0x00,0x00,0x00,//11, 0x00,0x00,0x60,0x50,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x98,0xF0,0x70,0x00,0x00, 0x00,0x00,0x20,0x30,0x28,0x28,0x24,0x24,0x22,0x22,0x21,0x20,0x30,0x18,0x00,0x00,//22, 0x00,0x00,0x30,0x30,0x08,0x08,0x88,0x88,0x88,0x88,0x58,0x70,0x30,0x00,0x00,0x00, 0x00,0x00,0x18,0x18,0x20,0x20,0x20,0x20,0x20,0x20,0x31,0x11,0x1F,0x0E,0x00,0x00,//33, 0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x10,0xF0,0xF8,0xF8,0x00,0x00,0x00,0x00, 0x00,0x04,0x06,0x05,0x05,0x04,0x24,0x24,0x24,0x3F,0x3F,0x3F,0x24,0x24,0x24,0x00,//44, 0x00,0x00,0x00,0xC0,0x38,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x08,0x08,0x00,0x00, 0x00,0x00,0x18,0x29,0x21,0x20,0x20,0x20,0x20,0x20,0x30,0x11,0x1F,0x0E,0x00,0x00,//55, 0x00,0x00,0x80,0xE0,0x30,0x10,0x98,0x88,0x88,0x88,0x88,0x88,0x98,0x10,0x00,0x00, 0x00,0x00,0x07,0x0F,0x19,0x31,0x20,0x20,0x20,0x20,0x20,0x20,0x11,0x1F,0x0E,0x00,//66, 0x00,0x00,0x30,0x18,0x08,0x08,0x08,0x08,0x08,0x88,0x48,0x28,0x18,0x08,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x3E,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//77, 0x00,0x00,0x70,0x70,0xD8,0x88,0x88,0x08,0x08,0x08,0x08,0x98,0x70,0x70,0x00,0x00, 0x00,0x0C,0x1E,0x12,0x21,0x21,0x20,0x21,0x21,0x21,0x23,0x12,0x1E,0x0C,0x00,0x00,//88, 0x00,0xE0,0xF0,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x18,0x10,0xF0,0xC0,0x00,0x00, 0x00,0x00,0x11,0x33,0x22,0x22,0x22,0x22,0x22,0x32,0x11,0x1D,0x0F,0x03,0x00,0x00,//99, 0x40,0x40,0x42,0xCC,0x00,0x40,0xA0,0x9E,0x82,0x82,0x82,0x9E,0xA0,0x20,0x20,0x00, 0x00,0x00,0x00,0x3F,0x90,0x88,0x40,0x43,0x2C,0x10,0x28,0x46,0x41,0x80,0x80,0x00,//設(shè)10, 0x10,0x0C,0x44,0x44,0x44,0x44,0x45,0xC6,0x44,0x44,0x44,0x44,0x44,0x14,0x0C,0x00, 0x80,0x40,0x20,0x1E,0x20,0x40,0x40,0x7F,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,//定11, 0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00, 0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,//溫12, 0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00, 0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,//度13, 0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00, 0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00,//濕14, 0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00, 0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,//度15, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//:16, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//.17, 0xF0,0xF8,0x08,0x08,0x08,0xF8,0xF0,0x00,0x80,0x40,0x20,0x18,0x08,0x00,0x00,0x00, 0x00,0x01,0x01,0x21,0x11,0x09,0x04,0x03,0x1F,0x1E,0x21,0x21,0x21,0x3F,0x1E,0x00,//%18, 0x00,0x40,0x42,0x44,0x58,0x40,0x40,0x7F,0x40,0x40,0x50,0x48,0xC6,0x00,0x00,0x00, 0x00,0x40,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00,//當(dāng)19, 0x08,0x08,0xE8,0x29,0x2E,0x28,0xE8,0x08,0x08,0xC8,0x0C,0x0B,0xE8,0x08,0x08,0x00, 0x00,0x00,0xFF,0x09,0x49,0x89,0x7F,0x00,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,0x00,//前20, 0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00, 0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00,//℃21,};/************************************6*8的點(diǎn)陣************************************/constunsignedcharF6x8[][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 0x0
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024學(xué)校維修合同書
- 2024年度網(wǎng)站域名合作契約
- 新建住宅購(gòu)買合同樣本
- 藥品銷售代理合同范例
- 高中生宿舍管理規(guī)定范本
- 建筑機(jī)械租賃合同簡(jiǎn)易格式
- 2024年資產(chǎn)抵債協(xié)議書
- 房屋房基流轉(zhuǎn)協(xié)議書-合同范本
- 制造企業(yè)員工合同樣本
- 產(chǎn)品加工合同典范
- 第16講 國(guó)家出路的探索與挽救民族危亡的斗爭(zhēng) 課件高三統(tǒng)編版(2019)必修中外歷史綱要上一輪復(fù)習(xí)
- 機(jī)器學(xué)習(xí) 課件 第10、11章 人工神經(jīng)網(wǎng)絡(luò)、強(qiáng)化學(xué)習(xí)
- 北京市人民大學(xué)附屬中學(xué)2025屆高二生物第一學(xué)期期末學(xué)業(yè)水平測(cè)試試題含解析
- 書籍小兵張嘎課件
- 氫氣中鹵化物、甲酸的測(cè)定 離子色譜法-編制說(shuō)明
- 2024秋期國(guó)家開放大學(xué)??啤稒C(jī)械制圖》一平臺(tái)在線形考(形成性任務(wù)四)試題及答案
- 2024年經(jīng)濟(jì)師考試-中級(jí)經(jīng)濟(jì)師考試近5年真題集錦(頻考類試題)帶答案
- 2024年黑龍江哈爾濱市通河縣所屬事業(yè)單位招聘74人(第二批)易考易錯(cuò)模擬試題(共500題)試卷后附參考答案
- 私募基金管理人-廉潔從業(yè)管理準(zhǔn)則
- 房地產(chǎn)估價(jià)機(jī)構(gòu)內(nèi)部管理制度
- 藝術(shù)哲學(xué):美是如何誕生的學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
評(píng)論
0/150
提交評(píng)論