波特率用的是115200,内部时钟8M,可是不通啊,哪位帅哥给点建议啊
#include "io78f0411.h"
#include "intrinsics.h"
#pragma location= 0x0080
__root const unsigned char optbyte[4]={0x7e,0x01,0x00,0x03};
//0x7e:看门狗定时器允许计数,窗口周期100%,看门狗的溢出时间选择了496.48ms,内部低速振荡时钟可由软件中止
//0x01:POCMODE模式选择2.7/1。59V模式
//0x00:0082H、0083H保留区域
//0x03:允许操作,在确定片上调试安全ID失效时可以擦除Flash存储器数据
typedef unsigned long u32;
typedef unsigned int u16;
typedef unsigned char u8;
unsigned char flag=0;
char TxStx[5]= {0x77,0x77,0x77,0x77,0x77};
char RxStx[5]={0x77,0x77,0x77,0x77,0x77};
unsigned int i=0;
unsigned int m=0;
void uart0_init(unsigned char br,unsigned char as)
{
BRGC0=br;
ASIM0=as;
PM1=0xf7;
PU1=0x04;
P1=0x04;
STIF0=0;
SRIF0=0;
STMK0=0;
SRMK0=0;
POWER0=0;
}
void uart0_en(void)
{
POWER0=1;
}
void uart0_dis(void)
{
POWER0=0;
}
void uart0_en_tx(void)
{
TXE0=1;
}
void uart0_dis_tx(void)
{
TXE0=0;
}
void uart0_en_rx(void)
{
RXE0 = 1;
}
void uart0_dis_rx(void)
{
RXE0 = 0;
}
void uart0_clr_tx_Int_F(void)
{
STIF0 = 0;
}
void uart0_clr_rx_Int_F(void)
{
SRIF0 = 0;
}
unsigned char uart0_read_State_Reg(void)
{
unsigned char byte;
byte=ASIS0;
return (byte);
}
void uart0_sendbyte(unsigned char byte)
{
TXS0=byte;
}
void uart0_sendstring(void)
{
while(m<5)
{
uart0_sendbyte(TxStx[i]);
while(STIF0==0);
STIF0=0;
m++;
}
}
unsigned char uart0_receivebyte(void)
{
unsigned char byte;
while(SRIF0==0);
if(0x00==uart0_read_State_Reg())
byte=RXB0;
else
byte=0xff;
SRIF0=0;
// i++;
return byte;
}
#pragma vector=INTSR0_vect
__interrupt void INTSR0_Server(void)
{
unsigned char rx_data;
rx_data=uart0_receivebyte();
if(i<5)
{
RxStx[i]=rx_data;
i++;
}
else if(i==5)
{
flag=1;
i=0;
}
// uart0_receivestring();
}
void init_cpu()
{
IMS=0x04;
IXS=0X0c;
OSCCTL=0x00;
MCM=0x00;
PCC=0x40;
MOC=0x80;
while(RSTS==0);
uart0_init(0x51,0x0d);
}
void watchdog(void)
{
WDTE=0xac;
}
void delay_10us(void)
{
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
}
void delay_500ms(void)
{
for(unsigned int i=0;i<50000;i++)
delay_10us();
}
void main()
{
__disable_interrupt();
asm("SEL RB0");
/*设置低电压检测复位,LIVM寄存器设置LVISEL、LVION、LVIF、LVIMD,还有屏蔽LVIMK中断位,还有用于设置
检测电压等级的LVIS
LVIon=1,低电压检测使能
LVIMK=1,屏蔽低电压检测产生的中断
LVISEL=0,检测供电电压VDD
LVIMD=1,产生复位信号
LVIS=0,产生电压登记,从4.24V下降
*/
LVION=0;
LVIMK=1;
LVISEL=0;
LVIMD=1;
LVIS=0;
delay_10us();
delay_10us();
delay_10us();
LVION=1;
delay_500ms();
watchdog();
while(LVIF==1);
watchdog();
init_cpu();
__enable_interrupt();
uart0_en();
uart0_en_rx();
uart0_en_tx();
while(1)
{
if(flag)
{
uart0_sendstring();
flag=0;
}
}
}