亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码
標(biāo)題:
STM8L單片機SI4463無線芯片IAR例程 廠家資料 好移植
[打印本頁]
作者:
crossfan
時間:
2019-2-15 14:58
標(biāo)題:
STM8L單片機SI4463無線芯片IAR例程 廠家資料 好移植
STM8L-SI4463 IAR例程 廠家資料 好移植
單片機源程序如下:
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "gpio.h"
#include "uart.h"
#include "oled.h"
#include "function.h"
#include "sensor.h"
#include "rf.h"
//SI4463 RF @STM8L151
void frameProcess( u8 *buf, u8 size )
{
u8 cmd = buf[0];
u8 len = buf[1];
LED_RX=1;
switch ( cmd )
{
case CMD_TEMP_HUM:
if ( rfAck )
{ //收到協(xié)議數(shù)據(jù),立即發(fā)送應(yīng)答
sendBuf[0] = CMD_ACK;
sendBuf[1] = 0;
RFSendData( sendBuf, 2 );
msg( "send reply..." );
}
if ( len == sizeof(float) )
{ //拿到溫濕度數(shù)據(jù),更新顯示
memcpy( &temperature, buf + 2, 2 );
memcpy( &humidity, buf + 4, 2 );
//發(fā)送串口顯示
rf2uart( temperature, humidity);
msg( "get sensor dat" );
}
break;
case CMD_ACK:
//發(fā)送后收到應(yīng)答
msg( "get reply" );
break;
default:
//無線接收轉(zhuǎn)串口透傳
UartSend( buf, size);
msg( "get rf data" );
break;
}
LED_RX=0;
}
int main( void )
{ int len;
asm("sim"); //全局中斷關(guān)閉
GPIOInit(); //IO初始化
Soft_I2C_Int();
GpioFicker(); //上電兩燈閃
UartInit(); //UART初始化
LED_Init(); //OLED屏初始化
getSensor(); //獲取初始溫濕度值
RFInit(); //射頻模塊初始化
RFRxMode(); //設(shè)置RF接收模式
asm("rim"); //全局中斷開啟
msg( "system start" );//顯示開機信息
/*infinite loop begin*/
while(1)
{
OledDisplay(); //OLED屏幕刷新顯示
keyProcess(); //按鍵監(jiān)測處理
timerTask(); //定期更新傳感器讀數(shù)
uart2rf(); //串口轉(zhuǎn)無線透傳
len = RFRevData( revBuf ); //接收無線數(shù)據(jù)
if ( len > 0 )
{
frameProcess( revBuf, len );//對收到的數(shù)據(jù)進行處理
}
if ( rfContinueSend() ) //連續(xù)發(fā)送處理
{
delay_ms( 500 );
}
}/*infinite loop end*/
}
復(fù)制代碼
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "function.h"
#include "oled.h"
#include "uart.h"
#include "gpio.h"
#include "rf.h"
#include "sensor.h"
unsigned short continueSendCnt=0; //連續(xù)發(fā)包數(shù)
unsigned short continueSendIndex=0;
void delay_us(u16 t)
{
u16 i;
for(i=0;i<t;i++)
{
asm("NOP");
}
}
void delay_ms(u16 t)
{
u16 i;
u16 j;
for(i=0;i<t;i++)
for(j=0;j<400;j++);
}
/* ------------------------------------------------------------------------ */
void GpioFicker( void )
{
//上電兩燈閃
LED_TX=1; //兩燈亮
LED_RX=1;
delay_ms(500);
LED_TX=0;
LED_RX=0;
delay_ms(500);
LED_TX=1; //兩燈亮
LED_RX=1;
delay_ms(500);
LED_TX=0;
LED_RX=0;
}
void keyProcess( void )
{
if ( GPIO_ReadInputDataBit( GPIOA, GPIO_Pin_4 ) == 0x00 ) /* S1 C13 */
{
delay_ms( 20 );
if ( GPIO_ReadInputDataBit( GPIOA, GPIO_Pin_4 ) == 0x00 )
{
msg( "clear ...." );
iSend = 0;
iRev = 0;
while ( GPIO_ReadInputDataBit( GPIOA, GPIO_Pin_4 ) == 0x00 )
; /* 等待按鍵釋放 */
}
}
if ( GPIO_ReadInputDataBit( GPIOA, GPIO_Pin_6 ) == 0x00 ) /* S2 A0 */
{
delay_ms( 10 );
if ( GPIO_ReadInputDataBit( GPIOA, GPIO_Pin_6 ) == 0x00 )
{
u8 len = 0;
while ( GPIO_ReadInputDataBit( GPIOA, GPIO_Pin_6 ) == 0x00 )
; /* 等待按鍵釋放 */
sendBuf[0] = CMD_TEMP_HUM; /* cmd: 1發(fā)送傳感器數(shù)據(jù) 2應(yīng)答成功 */
sendBuf[1] = 4;
getSensor();
/* 數(shù)據(jù)長度 */
memcpy( &sendBuf[2], &temperature, 2 );
memcpy( &sendBuf[4], &humidity, 2 );
LedRed( On );
len = RFSendData( sendBuf, 6 );
if ( len > 0 )
msg( "send ok" );
else
msg( "send fail" );
LedRed( Off );
}
}
if ( GPIO_ReadInputDataBit( GPIOA, GPIO_Pin_5 ) == 0x00 )
{
delay_ms( 10 );
if ( GPIO_ReadInputDataBit( GPIOA, GPIO_Pin_5 ) == 0x00 )
{
while ( GPIO_ReadInputDataBit( GPIOA, GPIO_Pin_5 ) == 0x00 )
; /* 等待按鍵釋放 */
continueSendCnt+=50;
}
}
}
char rfContinueSend(void)
{
if(continueSendIndex>=continueSendCnt)return 0;
continueSendIndex++;
LedRed( On );
getSensor();
sendBuf[0] = CMD_TEMP_HUM; /* cmd: 1發(fā)送傳感器數(shù)據(jù) 2應(yīng)答成功 */
sendBuf[1] = 4; /* 數(shù)據(jù)長度 */
memcpy( &sendBuf[2], &temperature, 2 );
memcpy( &sendBuf[4], &humidity, 2 );
RFSendData( sendBuf, 6 );
sprintf( (char *) sendBuf, "AutoSend:%d/%d", continueSendIndex,continueSendCnt );
msg( (char *) sendBuf );
LedRed( Off );
OledDisplay();
return 1;
}
/* ------------------------------------------------------------------------ */
void uart2rf(void)
{
static u8 uart_rx_len_last=0;
u8 i,tmp=0;
if(uart_rx_len_last>0)
{
LED_TX=1;
if(uart_rx_len_last==uart_rx_len)
{
while(uart_rx_len)
{
u8 len=uart_rx_len>32?32:uart_rx_len;
RFSendData(uart_rx_buf+tmp,len);
uart_rx_len-=len;
tmp+=len;
delay_ms( 10 );
}
LED_TX=0;
}
}
uart_rx_len_last=uart_rx_len;
}
void rf2uart(s16 tem,s16 hum)
{
u8 sbuf[64];
sprintf( sbuf, "Tem%.1f Hum%.1f%%\n", tem / 10.0, hum / 10.0 );
UartSend( sbuf, 18);
}
void timerTask(void)
{
static u32 count;
//static u8 flag = 0;
static int lastRevByte=-1;
static u8 delay=1;
if ( ++count > 2 )
{
count = 0;
//收到數(shù)據(jù)5秒內(nèi)顯示收到的數(shù)據(jù)而不是顯示采集到的本地數(shù)據(jù)
if(lastRevByte!=iRev)
{
lastRevByte=iRev;
delay=10;
}else{
if(--delay==0)
{
if(delay==0)delay=5;
getSensor();
}
}
}
}
void debug( const char* fmt, ... )
{
va_list args;
va_start( args, fmt );
vprintf( fmt, args );
va_end( args );
}
/*
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* -------------------- 私有函數(shù)定義 ------------------------------
*/
void msg( char *msg ) /* 如果要顯示中文,OLED點陣字庫必須有相應(yīng)數(shù)據(jù),英文則不需要 */
{
static u8 count=0;
char buf[8];
LED_PXx16MixStr( 0, 3, " " ); /* 16個字母 */
sprintf(buf,"%d:",++count%10);
LED_PXx16MixStr(0,3,buf);
LED_PXx16MixStr( 14, 3, msg );
//debug( msg );
}
void OledDisplay( void )
{
char buf[64] = "";
static char flag=0;
if(!flag)
{
sprintf( buf, "%s + SI7021", rfName );
LED_PXx16MixStr( 0, 0, buf );
flag=1;
}
sprintf( buf, "Tem%.1f Hum%.1f%%", temperature / 10.0, humidity / 10.0 );
LED_PXx16MixStr( 0, 1, buf );
sprintf( buf, "Snd:%d Rev:%d", iSend, iRev );
LED_PXx16MixStr( 0, 2, buf );
}
復(fù)制代碼
所有資料51hei提供下載:
STM8L_4463.7z
(892.6 KB, 下載次數(shù): 43)
2019-2-15 16:43 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
jxchen
時間:
2019-2-17 12:31
感謝~~~~~~~~~~~~
作者:
gdgn_526345
時間:
2019-3-16 11:39
感謝喔!
作者:
hujj
時間:
2019-3-16 18:51
以前用51開發(fā)時買過這種模塊,但一直沒有用起來,這個資料很好,可以參考,謝謝樓主!
歡迎光臨 (http://www.denmoz.com/bbs/)
Powered by Discuz! X3.1