设置为下降沿捕获中断和更新中断,更新时间设置为104us,代码如下:
u8 MONI_BZW=0;
void HTCFG_CAP_IRQHandler(void)
{
bool update_flag = FALSE;//标记定时器是否发生了更新事件中断
/* store and clear all interrupt flags */
u32 status = HTCFG_CAP_PORT->INTSR;//获取当前中断标志的状态
u32 cnt = HTCFG_CAP_PORT->CNTR; //读取定时器的计数器值
HTCFG_CAP_PORT->INTSR = ~status;//清除中断标志
if (status & TM_INT_UEV)//检查更新事件中断标志是否被置位
{
UART_MONI(); //模拟UART接收中断函数
UART_MONI_F(); //模拟UART发送中断函数
}
//处理通道捕获中断
if (status & HTCFG_CAP_CCR)
{
if(MONI_BZW == 0 && GPIO_ReadInBit(HTCFG_WAKE_GPIO_PORT, HTCFG_WAKE_GPIO_PIN) == RESET)
{
MONI_BZW=1;//开始位
}
}
}
u8 read_du[256];
u8 write_xie[256];
u8 read_1=0;
u8 ji_shi=0;
u8 ji_shu=0;
u8 FA_BZW=0;
u8 fa=0;
u8 buff=0;
void UART_MONI(void)//只能接收十六进制
{
if(MONI_BZW == 1)
{
ji_shu++;
if(GPIO_ReadInBit(HTCFG_WAKE_GPIO_PORT, HTCFG_WAKE_GPIO_PIN) == SET)
{
read_1 |= (1 << (ji_shu-2));
}
else if(GPIO_ReadInBit(HTCFG_WAKE_GPIO_PORT, HTCFG_WAKE_GPIO_PIN) == RESET)
{
read_1 &= ~(1 << (ji_shu-2));
}
if(ji_shu >=9 && ji_shu <240)
{
MONI_BZW=0;
read_du[ji_shi++]=read_1;
ji_shu=0;
}
}
}
void UART_MONI_F(void)//只能十六进制发送
{
if(FA_BZW >= 1)
{
fa++;
switch(fa)
{
case 1:
GPIO_ClearOutBits(HT_GPIOA, GPIO_PIN_3);
break;
case 10:
GPIO_SetOutBits(HT_GPIOA, GPIO_PIN_3);
fa=0;
FA_BZW--;//标志位--,即要发送数据的个数
buff++;//发送数据的顺序
break;
default:
if(write_xie[buff] & 0x01)
{
GPIO_SetOutBits(HT_GPIOA, GPIO_PIN_3);
}
else
{
GPIO_ClearOutBits(HT_GPIOA, GPIO_PIN_3);
}
write_xie[buff] >>= 1;
break;
}
}
}
void UART_MONI_BAOZHUANG_F(u8 data)//发送一个字符
{
if(FA_BZW == 0)
{
FA_BZW=1;
write_xie[FA_BZW]=data;
}
}
void UART_MONI_BAOZHUANG_send(u8 *data, u8 len)//发送多个字符
{
if(FA_BZW == 0 )
{
while(len--)
{
buff=0;
write_xie[FA_BZW++]= *data++;
}
}
}
|
|