#include "iostm8s105c6.h"
#include "intrinsics.h"
void UART_Init(void)
{
UART2_CR1=0x00;
UART2_CR3=0x00;
UART2_BRR2=0x00;
UART2_BRR2=0x0d;
UART2_CR2=0x24;
}
unsigned char c;
void main()
{
PB_DDR |= 0xFF;
PB_CR1 |= 0xFF;
PB_ODR |= 0xFF; //LED连接的IO口初始化
PD_DDR = 0x20; //TXD设置为OD输出
PD_CR1 = 0x40; //RXD设置为上拉输入
PD_CR2 = 0x00;
UART_Init();
asm("rim");
TIM2_PSCR|=0X01;
TIM2_ARRH=0X03;
TIM2_ARRL=0XE8;
TIM2_CNTRH=0X03;
TIM2_CNTRL=0XE8;
TIM2_CR1|=0X8C;
TIM2_IER|=(1<<0);
TIM2_CR1|=(1<<0);
while(1)
{
while ((UART2_SR & 0x20)==0x00);//Loop until the UART1 Receive Data Register is not empty
c = UART2_DR;
}
}
#pragma vector=UART2_R_RXNE_vector
__interrupt void UART2_RX(void)
{
c = UART2_DR; // 接收到数据了
while(!UART2_SR_TXE);
}
#pragma vector=15 //TIM2的外部中断向量号是13,加上两个不可屏蔽中断是15
__interrupt void TIM2_IRQ(void)
{
if(c=='a')
{
PB_ODR=0Xfe;
}
else
{
PB_ODR=0xf1;
}
TIM2_SR1&=~(1<<0);
}
以上就是程序,要实现的功能是通过手机的串口通讯助手发送数据到蓝牙模块,然后蓝牙模块传到stm8里面,可经过测试,数据传不到stm8里面,各位看官有知道问题的么,我上面的代码是不是有问题? |