我这段程序是测速度和心率的,但是我现在烧进52后,在串口小程序里收不到数据,连0也没有,设置串口小程序显示16进制了,还是没有,求大神指点,是我哪里写错了,应该怎么改!谢谢
#include <reg52.h>
unsigned char flag_d = 0; //发送标志
unsigned char time = 0; /
unsigned int heart = 0; //心率变量
unsigned int num[2] = {0,0}; //
unsigned int speed = 0;
float temp;
float count = 0; //间隔时间
//发送字符
void UART_SChar(unsigned char ch)
{
SBUF = ch; //发送数据
while(TI == 0); //等待发送完成
TI = 0; //清楚发送标志
}
void main(void)
{
TMOD = 0x21; //定时器工作方式
SCON = 0X40; //串口工作方式
TH0 = (65536-45872)/256; //定时器0初值
TL0 = (65536-45872)%256;
TH1 = 0XFD; //定时器1初值
TL1 = 0XFD;
IT0 = 0; //外部中断0低电平触发速度
IT1 = 1; //下降沿触发心率
EA = 1; //开中断
ES = 1; //开串行口中断
EX0 = 1; //开外部0中断
EX1 = 1; //开外部1中断
ET0 = 1; //开定时器0中断
ET1 = 1;
TR0 = 1;
TR1 = 1; //启动定时器1
while(1)
{
if(flag_d != 0) //如果发送标志位有效
{
UART_SChar(0x00); //发送数据
UART_SChar(speed); //发送数据
UART_SChar(0xff); //发送数据
if(flag_d == 2)
{
UART_SChar(0x00); //发送数据
UART_SChar(heart); //发送数据
UART_SChar(0xff); //发送数据
}
}
flag_d = 0; //清除标志
}
}
//T0中断服务程序
void T0_ISR(void) interrupt 1 //
{
TH0 = (65536-45872)/256;
TL0 = (65536-45872)%256;
speed = num[0];
num[0] = 0 ;
flag_d = 1 ;
if (time == 40)
{
heart = num[1];
num[1] = 0 ;
flag_d = 2 ;
time = 0 ;
}
time++;
}
void INT0_ISR(void) interrupt 0
{
num[0]++;
}
//外部中断1服务程序
void INT1_ISR(void) interrupt 2 //
{
num[1]++;
}
|