#ifndefone_wire_cfg_h
#define
one_wire_cfg_h
//#include
"complier_lib.h"
#ifdef
use_mcu_stm32
#include
"delay_task.h"
#include
"gpio_task.h"
#endif
//---定義結構體
typedef
struct _onewire_handlertype onewire_handlertype;
//---定義指標結構體
typedef
struct _onewire_handlertype *ponewire_handlertype;
//---定義
struct _onewire_handlertype
;//---函式定義
uint8_t onewire_init
(onewire_handlertype *onewirehandlertype,
void(*
msgdelay)(uint32_t delay))
;uint8_t onewire_deinit
(onewire_handlertype *onewirehandlertype)
;uint8_t onewire_start
(onewire_handlertype *onewirehandlertype)
;uint8_t onewire_writebit
(onewire_handlertype *onewirehandlertype, uint8_t bitval)
;uint8_t onewire_readbit
(onewire_handlertype *onewirehandlertype)
;uint8_t onewire_writebyte
(onewire_handlertype *onewirehandlertype, uint8_t val)
;uint8_t onewire_readbyte
(onewire_handlertype *onewirehandlertype);//
#endif
/*one_wire_cfg_h */
#include"one_wire_cfg.h"
/////函 數:
//功 能:
//輸入引數:
//輸出引數:
//說 明:
//uint8_t onewire_init
(onewire_handlertype *onewirehandlertype,
void(*msgdelay)(uint32_t delay))
//---使能埠時鐘
gpiotask_clock(onewirehandlertype->msgport,
1); ll_gpio_inittypedef gpio_initstruct;
//---gpio的初始化
gpio_initstruct.pin = onewirehandlertype->msgbit;
//---對應的gpio的引腳
gpio_initstruct.mode =
ll_gpio_mode_output
;//---配置狀態為輸出模式
gpio_initstruct.speed =
ll_gpio_speed_freq_very_high
;//---gpio的速度
gpio_initstruct.outputtype =
ll_gpio_output_opendrain
;//---輸出模式---開漏輸出
gpio_initstruct.pull =
ll_gpio_pull_up
;//---上拉使能
//---初始化埠
ll_gpio_init(onewirehandlertype->msgport,
&gpio_initstruct);
#endif
gpio_out_1(onewirehandlertype->msgport, onewirehandlertype->msgbit);
//---延時函式
if (msgdelay!=
null)
//---訊息函式
onewirehandlertype->
msgtask
=null
;return
ok_0;}
/////函 數:
//功 能:
//輸入引數:
//輸出引數:
//說 明:
//uint8_t onewire_deinit
(onewire_handlertype *onewirehandlertype)
/////函 數:
//功 能:
//輸入引數:
//輸出引數:
//說 明:
//uint8_t onewire_start
(onewire_handlertype *onewirehandlertype)
//---輸出高電平
gpio_out_1(onewirehandlertype->msgport, onewirehandlertype->msgbit);
//15us~60us之間
if (onewirehandlertype->msgdelay !=
null
)
_return =
gpio_get_state(onewirehandlertype->msgport, onewirehandlertype->msgbit);
//60us~240us
if (onewirehandlertype->msgdelay !=
null
)
return _return;
}///
//函 數:
//功 能:
//輸入引數:
//輸出引數:
//說 明:
//uint8_t onewire_writebit
(onewire_handlertype *onewirehandlertype, uint8_t bitval)
//---傳送資料
if (bitval)
//=60us
if (onewirehandlertype->msgdelay !=
null
)
//---釋放匯流排
gpio_out_1(onewirehandlertype->msgport, onewirehandlertype->msgbit);
//=4
if (onewirehandlertype->msgdelay !=
null)
return0;
}///
//函 數:
//功 能:
//輸入引數:
//輸出引數:
//說 明:
//uint8_t onewire_readbit
(onewire_handlertype *onewirehandlertype)
//---釋放匯流排
gpio_out_1(onewirehandlertype->msgport, onewirehandlertype->msgbit);
//=14
if (onewirehandlertype->msgdelay !=
null)
//---讀取資料
if (gpio_get_state(onewirehandlertype->msgport, onewirehandlertype->msgbit))
//=40
if (onewirehandlertype->msgdelay !=
null)
//---釋放匯流排
gpio_out_1(onewirehandlertype->msgport, onewirehandlertype->msgbit);
return _return;
}///
//函 數:
//功 能:
//輸入引數:
//輸出引數:
//說 明:
//uint8_t onewire_writebyte
(onewire_handlertype *onewirehandlertype, uint8_t val)
return
ok_0;}
/////函 數:
//功 能:
//輸入引數:
//輸出引數:
//說 明:
//uint8_t onewire_readbyte
(onewire_handlertype *onewirehandlertype)
//=5
if (onewirehandlertype->msgdelay !=
null)
return _return;
}
STM32串列埠協議
目前我總結了兩種串列埠通訊時用到的串列埠協議程式。均學習的原子哥的。一 定義某個字元為一次接收資料完成,如 n r。二 定義兩個字元接收時間間隔,如10ms。超過即為第二次接收。一 程式示意 二 程式示意 include delay.h include usart2.h include stdarg...
STM32 紅外NEC協議筆記
學習nec協議,我認為只分為兩部分 1 學習nec協議的解碼,也就是對紅外置收頭接收到訊號後產生的電平訊號進行解讀 2 學習nec協議的編碼,當了解到nec原理之後,自己就可以嘗試著編寫模擬nec紅外訊號,來加深對nec的理解。原理 1 傳送原理 nec協議為傳送38khz的紅外載波來控制資料的傳輸...
STM32之SPI匯流排協議
spi匯流排協議是一種序列外圍裝置介面,是motorola公司推出的一種三線同步序列接 術,spi是一種高速的 全雙工 同步的通訊匯流排,並且在晶元上的物理介面只需要占用4根線,節約了晶元的管腳。spi是乙個環形匯流排結構,由sck cs mosi miso構成,時序也很簡單,主要是在sck的控制下...