日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]//代碼僅僅是配置使能串口和相應(yīng)的中斷處理函數(shù),具體功能需要自己定義//IAR 7.1#include "stm32_uart.h"uint8_t card_ture=0;uint16_t add_count=0;uint8_t Key_Data[1]={0};uint8_t Media_Flag=0;uint8_t card_cod

//代碼僅僅是配置使能串口和相應(yīng)的中斷處理函數(shù),具體功能需要自己定義

//IAR 7.1

#include "stm32_uart.h"

uint8_t card_ture=0;
uint16_t add_count=0;
uint8_t Key_Data[1]={0};
uint8_t Media_Flag=0;

uint8_t card_code[4]; //[5:1]save the card SN, [0]valid or invalid
uint8_t Temp_Card_Num[4];
uint8_t cardcode_rx_complete = 0;

uint32_t uart_config_record_map[4] = {
0,
UART_CONFIG_UART_MEMORY_ADDR,
FIRMWARE_VERSION_MEMORY_ADDR,
SCHEME_SPECIFIC_MEMORY_ADDR
};

UartConfig_TypeDef the_uart_config;

void stm32_uart_init(uint8_t uart_port, uint32_t BaudRate)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

/*Fill the structure of uart init*/
if(uart_port == UART2)
{
/*Fill the structure of uart init*/
USART_InitStructure.USART_BaudRate = BaudRate;
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;
/*Enable priph clock*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);


/*Config gpio as uart pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/*Config gpio as uart pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/*Init uart*/
USART_Init(USART2, &USART_InitStructure);
/*Enable uart*/
/*Clear flags*/
USART_ClearFlag(USART2, USART_FLAG_TC);

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2, ENABLE);
}
else if(uart_port == UART1)
{
/*Enable priph clock*/

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);

/*Fill the structure of uart init*/
USART_InitStructure.USART_BaudRate = BaudRate;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
if(the_uart_config.checksum==Parity_No)
{
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //USART_WordLength_8b
USART_InitStructure.USART_Parity = USART_Parity_No; //USART_Parity_No
}
else if(the_uart_config.checksum==Parity_Odd)
{
USART_InitStructure.USART_WordLength = USART_WordLength_9b; //USART_WordLength_9b
USART_InitStructure.USART_Parity = USART_Parity_Odd; //USART_Parity_Odd
}
else if(the_uart_config.checksum==Parity_Even)
{
USART_InitStructure.USART_WordLength = USART_WordLength_9b; //USART_WordLength_9b
USART_InitStructure.USART_Parity = USART_Parity_Even; //USART_Parity_Even
}
else
{

}
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

/*Config gpio as uart pin */
GPIO_InitStructure.GPIO_Pin = UART1_TX;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/*Init uart*/
USART_Init(USART1, &USART_InitStructure);
/*Enable uart*/
//USART_Cmd(USART1, ENABLE);
/*Clear flags*/
USART_ClearFlag(USART1, USART_FLAG_TC);
#if 0
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//USART_ITConfig(USART1, USART_IT_RXNE | USART_IT_TXE, ENABLE);
#endif
USART_Cmd(USART1, ENABLE);
}
}


static void stm32_uart_senddatas(uint8_t uart_port, const uint8_t* data, uint16_t len)
{
uint16_t count;
if(uart_port == UART1)
{
for(count = 0; count < len; count++)
{
USART_SendData(USART1, data[count]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}
}
else if(uart_port == UART2)
{
for(count = 0; count < len; count++)
{
USART_SendData(USART2, data[count]);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
}
}
}

static uint8_t* uart1_tx_buffer;
static uint8_t uart1_tx_buffer_len;
static uint8_t uart1_tx_buffer_index = 0;
void stm32_uart_pro_poweron(ProComm_TypeDef comm)
{
USART_ClearFlag(USART1,USART_FLAG_TC); //清除標(biāo)志位 否則第一位數(shù)據(jù)丟失
switch(comm)

{

}
//USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
//USART_Cmd(USART1, ENABLE);
}

void stm32_uart2_senddata(uint8_t uart_port, const uint8_t* data, uint16_t len)
{
USART_ClearFlag(USART2,USART_FLAG_TC); //清除標(biāo)志位 否則第一位數(shù)據(jù)丟失
stm32_uart_senddatas(uart_port, data,len);
}

void USART1_IRQHandler(void)
{

if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
{
USART_ClearITPendingBit(USART1, USART_IT_TXE);
/* Write one byte to the transmit data register */
USART_SendData(USART1, uart1_tx_buffer[uart1_tx_buffer_index++]);

if(uart1_tx_buffer_index == uart1_tx_buffer_len)
{
/* Disable the USARTz Transmit interrupt */
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
uart1_tx_buffer_index = 0;
}
}
}
/*
void USART2_IRQHandler(void)
{
static uint8_t index = 1;
static uint8_t checksum = 0;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
card_code[index] = USART_ReceiveData(USART2);
if(index < 5)
{
checksum ^= card_code[index++];
}
else
{
if(checksum == card_code[5])
{

}
else
{
}
cardcode_rx_complete = 1;
checksum = 0;
}
}
}
*/

void USART2_IRQHandler(void)
{
uint8_t index=0;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
Key_Data[index] = USART_ReceiveData(USART2);
switch(Key_Data[0])
{

}
}
//if(USART_GetITStatus(USART2, USART_IT_TXE) != RESET)
//{
// USART_ClearITPendingBit(USART2, USART_IT_TXE);
//}
}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

單片機(jī)將是下述內(nèi)容的主要介紹對象,通過這篇文章,小編希望大家可以對它的相關(guān)情況以及信息有所認(rèn)識和了解,詳細(xì)內(nèi)容如下。

關(guān)鍵字: 單片機(jī) 中斷 boot

在嵌入式系統(tǒng)的開發(fā)中,中斷機(jī)制扮演著至關(guān)重要的角色。它允許系統(tǒng)在執(zhí)行正常程序流程時(shí),響應(yīng)外部或內(nèi)部事件,從而確保系統(tǒng)能夠及時(shí)響應(yīng)并處理緊急事件。本文將深入探討嵌入式系統(tǒng)中中斷的概念、如何在系統(tǒng)中設(shè)置和處理多個(gè)中斷的優(yōu)先級...

關(guān)鍵字: 嵌入式系統(tǒng) 中斷

中斷機(jī)制在單片機(jī)及嵌入式系統(tǒng)中是重中之重,我們必須深入理解。首先我們要明白一點(diǎn):CPU執(zhí)行指令代碼,并非一直順序地逐條執(zhí)行,而是可能突然跳到某段代碼上去的。因?yàn)檫@段代碼的優(yōu)先級更高,或者說它更加緊迫,CPU必須暫時(shí)放下手...

關(guān)鍵字: 中斷 單片機(jī) 嵌入式系統(tǒng)

PIC單片機(jī)是基于RISC系統(tǒng)結(jié)構(gòu)的單片機(jī),最初的設(shè)計(jì)是支持PDP(編程數(shù)據(jù)處理器)計(jì)算機(jī)。大量的操作可以用來控制外圍設(shè)備。PIC單片機(jī)比微控制器具有更快的程序執(zhí)行能力。它是由微芯片技術(shù)公司于1889年發(fā)明的,是一種8位...

關(guān)鍵字: PIC單片機(jī) 定時(shí)器 中斷

STC單片機(jī)是一款增強(qiáng)型51單片機(jī),完全兼容MCS-51,還增加了新的功能,比如新增兩級中斷優(yōu)先級,多一個(gè)外中斷,內(nèi)置EEPROM,硬件看門狗,具有掉電模式,512B內(nèi)存等。還支持ISP下載,不用編程器,只要一個(gè)MAX2...

關(guān)鍵字: 單片機(jī) 看門狗 中斷

什么是PIC中斷程序呢?形象的生活比喻就比如你現(xiàn)在這在看我的文章,突然你的朋友喊你一起去烤地瓜,這時(shí)候你就中斷了看文章和朋友烤地瓜去了,烤完地瓜之后你又回來看文章??镜毓线@件事就好比中斷程序,他中斷了你看文章這件事。在程...

關(guān)鍵字: PIC 中斷 標(biāo)志位

MCS—51系列單片機(jī)內(nèi)部只需兩個(gè)外部接中斷連源輸入端,當(dāng)外部接連源多于兩個(gè)時(shí),就必須進(jìn)行拓寬,下面介紹幾種簡略的拓寬辦法:

關(guān)鍵字: 單片機(jī) 軟件 中斷

最近在瀏覽星球主題的時(shí)候,發(fā)現(xiàn)一位球友打卡中斷了,就去關(guān)心了一下他(瞧我這該死的責(zé)任心??),結(jié)果被他反手就問了下面這個(gè)問題。

關(guān)鍵字: 中斷 Spring Boot 實(shí)戰(zhàn)項(xiàng)目

實(shí)質(zhì)上是加一的計(jì)數(shù)器。外部脈沖讓他不斷加一,當(dāng)計(jì)數(shù)器溢出時(shí),計(jì)數(shù)器的溢出相應(yīng)的中斷標(biāo)志位置1,并向CPU發(fā)出中斷請求。如果定時(shí)器/計(jì)數(shù)器工作為定時(shí)模式,則表示時(shí)間以到;如果工作于計(jì)數(shù)模式,則表示計(jì)數(shù)器、則表示計(jì)數(shù)值已滿。

關(guān)鍵字: 周期 中斷

中斷的分類和區(qū)別

關(guān)鍵字: 輪詢 中斷
關(guān)閉