#include "iostm8s105s6.h"
#define uchar unsigned char
#define uint unsigned int
void CLK_init()
{
CLK_CKDIVR=0x08;//内部16M/2=8M
}
void UART_init()
{
UART2_BRR2=0x01;//设置波特率9600
UART2_BRR1=0X34;//8M/9600=0X341;
UART2_CR2=0X2C;//接收中断使能,接收使能,发送使能
}
void UART2_txd(uchar dat)
{
while(!UART2_SR_TC);
UART2_DR=dat;//发送数据
}
void main()
{
PD_DDR=0X08;
PD_CR1=0X08;
PD_CR2=0X00;
CLK_init();
UART_init();
enableInterrupts();
UART2_txd(0x55);
UART2_txd(0xaa);
while(1);
}
INTERRUPT_HANDLER(UART2_RX_IRQHandler, 21)
{
unsigned char c;
c = UART2_DR; // 接收到数据了
PD_ODR=c;
}
请各位高手指教,我用LED指示接收到的数据,可是没任何反应,求教 |