資源描述:
《【精品】MK代碼分析》由會(huì)員上傳分享,免費(fèi)在線(xiàn)閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、cli();關(guān)閉總中斷檢測(cè)飛控板版木設(shè)置LED相應(yīng)管腳關(guān)閉看門(mén)狗四通道桿量置零T1MER0初始化,用于產(chǎn)??刂茪鈮焊叨扔?jì)偏置電壓的pwm倍號(hào),控制蜂鳴器鳴叫以及電機(jī)更新頻率。TTMER2初始化,用于向4017芯片輸出pwm信號(hào),從而將1路pwm轉(zhuǎn)換成多路舵機(jī)控制信號(hào)。UART0初始化MK主串口,負(fù)責(zé)與上位機(jī)的信息交互。RC_INTT();設(shè)置ppm信號(hào)輸入引腳,設(shè)置TIMER1的輸入捕獲功能以解碼ppm信號(hào)。ADC_TNTT();初始化AD采樣,采樣信息包括三軸加速度,三軸角速度,氣壓高度,電池電量。12C_IN1T();12C總線(xiàn)初始化,配置I2C以控制電機(jī)
2、。sei()使能全局中斷。PARAMSET_TNTT();設(shè)置參數(shù),將參數(shù)讀入內(nèi)存屮的ParamSeto檢查加速應(yīng)計(jì)是否校準(zhǔn)。檢杳是否開(kāi)啟高度控制,若開(kāi)啟則校準(zhǔn)高度計(jì)偏置。SetNeutral();//NeutralReadingWhile(1){UpdateMotor標(biāo)志是否更新電機(jī)狀態(tài){MotorControl();SendMotorData();}PcAccess標(biāo)志是否有上位機(jī)請(qǐng)求信息I2cTimeout標(biāo)志I2C是否超時(shí)需報(bào)錯(cuò)S10_DEBUG標(biāo)志是否在串口調(diào)試{Transmit.TxD3t8();ProcessRxData();}檢測(cè)電池電量。主函
3、數(shù)屮的關(guān)鍵過(guò)程:voidMotorControl(void)通過(guò)控制率確定電機(jī)控制量voidSendMotorData(void)發(fā)送控制量給電機(jī)voidTransmitTxData(void)負(fù)責(zé)根據(jù)串口接收的指令要求發(fā)送相應(yīng)數(shù)據(jù)voidProcessRxData(void)處理串口接收到的數(shù)據(jù),給各種事件標(biāo)/忐置位串口協(xié)議Protocol?Theprotocolisbasedonindividualserialdataframesthatareorganizedasshowninthefollowingtable?Start-BytAddresID~Byt
4、nData-BytesCRC-ByteCRC-ByteStop-BytesByteecoded12e,岸'『+'V','DAddr'etcz/modified-base64〃variablevariableCommands?TheCommandsbasedonthedataframesabovearelistedhereThestructsusedbelowaredefinedinuart?h?Forimplementationdetails,seeuart.c.Addressesaredefinedasfollows:#defineFC_ADDRESS1(b
5、)#defineNC_ADDRESS2(c)#defineMK3MAG_ADDRESS3(d)#defineBL_CTRL_ADDRESS5(f)CommonCommandsDescriptionIDReceivedAddres丁“DataIDsAddressSentDataLabelsoftheanalogvaluesintheDebugDataStruet(see'd')aAnyAddru8IndexofAnalogChannel,ASlaveAddru8Index,char[16]labeltextExternControl'bAnyAddrExtern
6、ControlStructSlaveAddrunsignedchar,echoofExternControl.FrameasconfirmationRequestdisplay'hAnyAddru8RemoteKey,u8AutoScndlntcrva1,HSlaveAddrchar[80]DisplayTextRequestdisplay,1AnyAddru8Menultcm,LSlaveAddru8MenuItem,u8MaxMenuItem,char[80]DisplayTextVersionRequestVAnyAddrnone,vSlaveAddrV
7、ersionInfoStructDebugRequest'dAnyAddru8AutoSendlnterva1.Valueismultipliedby10inreceiverandthenusedasmilliseconds.Subsciptionneedstoberenewedevery4s.,DSlaveAddrDebugDataStructReset,RAnyAddrnone————GetExtcrnalControlgAnyAddrnone,GSlaveAddrExtcrnControlStrcutFlight-CtrlDescriptionRecei
8、vedbyFCAddreIDDataI