<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM8L101F3P6查詢發(fā)送中斷接收

          STM8L101F3P6查詢發(fā)送中斷接收

          作者: 時(shí)間:2016-11-09 來(lái)源:網(wǎng)絡(luò) 收藏
          /******************************Copyright (c)***********************************/ /* */ /* 老李電子工作 */ /* */ /*------------------------------File Info-------------------------------------*/ /* File name: main.c */ /* Last modified Date: 2014-06-23 */ /* Last Version: 1.0 */ /* Descriptions: STM8L103F3P6,內(nèi)部時(shí)鐘,16MHz,串口查詢發(fā)送中斷接收。 */ /* 本程序模擬一小段協(xié)議的解析,接收到報(bào)文0xc2,0x01,0x7b后*/ /* 返回報(bào)文0xd2,0x64,0x21 */ /* 查詢發(fā)送,中斷接收 */ /* */ /* 硬件連接: */ /* TX----PC3 */ /* RX----PC2 */ /* */ /*----------------------------------------------------------------------------*/ /* Created by: Li Xiang */ /* Created date: 2014-06-19 */ /* Version: 1.0 */ /* Descriptions: 無(wú) */ /* */ /******************************************************************************/ /* Includes ------------------------------------------------------------------*/ #include "stm8l10x.h" #include "stm8l10x_usart.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define POWER_BD GPIO_Pin_0 #define POWER_BT GPIO_Pin_1 #define MSEL GPIO_Pin_2 #define NRESET GPIO_Pin_3 #define BD_NRESET GPIO_Pin_4 #define RESETB GPIO_Pin_5 #define SCL2 GPIO_Pin_6 #define SDA2 GPIO_Pin_7 #define SDA GPIO_Pin_0 #define SCL GPIO_Pin_1 #define SCREEN_CTRL GPIO_Pin_4 #define POWER_WIFI GPIO_Pin_0 /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ uint8_t RXBUF[64]; uint8_t rxcounter=0; uint8_t rxflag=0; /* Private function prototypes -----------------------------------------------*/ static void BoardInit(void); static void CLK_Init(void); static void GPIO_Init_my(void); static void USART_Config(void); void USART_SendByte(uint8_t data); void USART_SendString(uint8_t* Data,uint16_t len); void Delay_ms(uint32_t nCount); /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Function name: main */ /* Descriptions: 主函數(shù) */ /* input parameters: 無(wú) */ /* output parameters: 無(wú) */ /* Returned value: 無(wú) */ /******************************************************************************/ void main(void) { uint8_t i=0; BoardInit(); enableInterrupts(); while (1){ if(rxflag==1){ switch(RXBUF[0]){ case 0xc1: break; case 0xc2: if( RXBUF[1]==0x01 && RXBUF[2]==0x7b ){ for(i=0;i<64;i++){ RXBUF[i]=0; } rxcounter=0; rxflag=0; USART_SendByte(0xD2); USART_SendByte(0x64); USART_SendByte(0x21); } break; case 0xc3: break; } } } } /******************************************************************************/ /* Function name: BoardInit */ /* Descriptions: 主函數(shù) */ /* input parameters: 無(wú) */ /* output parameters: 無(wú) */ /* Returned value: 無(wú) */ /******************************************************************************/ static void BoardInit(void) { CLK_Init(); GPIO_Init_my(); USART_Config(); } /******************************************************************************/ /* Function name: CLK_Init */ /* Descriptions: 時(shí)鐘初始化函數(shù) */ /* input parameters: 無(wú) */ /* output parameters: 無(wú) */ /* Returned value: 無(wú) */ /******************************************************************************/ static void CLK_Init(void) { CLK_DeInit(); CLK_MasterPrescalerConfig(CLK_MasterPrescaler_HSIDiv1); } /******************************************************************************/ /* Function name: GPIO_Init_my */ /* Descriptions: IO初始化函數(shù) */ /* input parameters: 無(wú) */ /* output parameters: 無(wú) */ /* Returned value: 無(wú) */ /******************************************************************************/ static void GPIO_Init_my(void) { GPIO_Init(GPIOA,GPIO_Pin_2|GPIO_Pin_3,GPIO_Mode_Out_PP_Low_Slow); //懸空未用 GPIO_Init(GPIOB,POWER_BD,GPIO_Mode_Out_PP_Low_Slow); //默認(rèn)斷電 GPIO_Init(GPIOB,POWER_BT,GPIO_Mode_Out_PP_Low_Slow); //取消未用 GPIO_Init(GPIOB,MSEL,GPIO_Mode_Out_PP_Low_Slow); //取消未用,Wifi模式選擇 GPIO_Init(GPIOB,NRESET,GPIO_Mode_Out_PP_Low_Slow); //取消未用,Wifi復(fù)位 GPIO_Init(GPIOB,BD_NRESET,GPIO_Mode_Out_PP_Low_Slow); //北斗復(fù)位信號(hào),默認(rèn)復(fù)位狀態(tài) GPIO_Init(GPIOB,RESETB,GPIO_Mode_Out_PP_Low_Slow); //取消未用,藍(lán)牙復(fù)位 GPIO_Init(GPIOB,SDA2|SCL2,GPIO_Mode_Out_OD_HiZ_Slow); //電池電量用 GPIO_Init(GPIOC,SDA|SCL,GPIO_Mode_Out_OD_HiZ_Slow); //溫度傳感器 GPIO_Init(GPIOC,GPIO_Pin_2,GPIO_Mode_In_PU_No_IT); //串口接收 GPIO_Init(GPIOC,GPIO_Pin_3,GPIO_Mode_Out_PP_High_Slow); //串口發(fā)送 GPIO_Init(GPIOD,GPIO_Pin_All,GPIO_Mode_Out_PP_Low_Slow); //取消未用,Wifi供電 } /******************************************************************************/ /* Function name: USART_Config */ /* Descriptions: 串口初始化函數(shù) */ /* input parameters: 無(wú) */ /* output parameters: 無(wú) */ /* Returned value: 無(wú) */ /******************************************************************************/ static void USART_Config(void) { CLK_PeripheralClockConfig(CLK_Peripheral_USART, ENABLE); USART_DeInit(); USART_Init((uint32_t)9600, USART_WordLength_8D, USART_StopBits_1, USART_Parity_No, (USART_Mode_TypeDef)(USART_Mode_Rx | USART_Mode_Tx)); USART_Cmd(ENABLE); USART_ITConfig(USART_IT_TXE,DISABLE);//關(guān)閉串口發(fā)送中斷 USART_ITConfig(USART_IT_TC,DISABLE);//關(guān)閉串口發(fā)送完中斷 USART_ITConfig(USART_IT_RXNE,ENABLE);//打開(kāi)串口接收中斷 } /******************************************************************************/ /* Function name: UART1_SendByte */ /* Descriptions: 發(fā)送單字節(jié) */ /* input parameters: data:待發(fā)送數(shù)據(jù) */ /* output parameters: 無(wú) */ /* Returned value: 無(wú) */ /******************************************************************************/ void USART_SendByte(uint8_t data) { USART_SendData8((unsigned char)data); /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART_FLAG_TXE) == RESET); } /******************************************************************************/ /* Function name: UART1_SendString */ /* Descriptions: 發(fā)送字符串 */ /* input parameters: 無(wú) */ /* output parameters: 無(wú) */ /* Returned value: 無(wú) */ /******************************************************************************/ void USART_SendString(uint8_t* Data,uint16_t len) { uint16_t i=0; for(;id assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %drn", file, line) */ /* Infinite loop */ while (1) { } } #endif /*********************************END OF FILE**********************************/

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();