ng "), ShowString(0,Test1);break;
case 2: sprintf(Test1," 2 dang "), ShowString(0,Test1);break;
case 3: sprintf(Test1," 3 dang "), ShowString(0,Test1);break;
case 4: sprintf(Test1," 4 dang "), ShowString(0,Test1);break;
case 5: sprintf(Test1," 5 dang "), ShowString(0,Test1);break;
case 6: sprintf(Test1," 6 dang "), ShowString(0,Test1);break;
case 7: sprintf(Test1," 7 dang "), ShowString(0,Test1);break;
case 8: sprintf(Test1," 8 dang "), ShowString(0,Test1);break;
case 9: sprintf(Test1," 9 dang "), ShowString(0,Test1);break;
}
while(!jiansu);
}
}
if(
tingzhi==0) // 停止
{
delay(10);
if(tingzhi==0)
{
IN1=1;
IN2=1;
sprintf(Test1," tingzhi ");
ShowString(0,Test1);
sprintf(Test2," ");
ShowString(1,Test2);
while(!tingzhi);
}
}
}
void UARTinit(void)
{
SCON = 0x50; /* SCON: 模式 1, 8-bit UART, 使能接收 */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xFD; /* TH1: reload value for 9600 baud @ 11.0592MHz */
TL1 =TH1;
TR1 = 1; /* TR1: timer 1 run */
// EA = 1; /*打开总中断*/
// ES = 1; //打开串口中断
//TI = 1; //发送标志位
}
/******************************************************************/
/* 串口中断程序 */
/******************************************************************/
/*
void UART_SER (void) interrupt 4 //串行中断服务程序
{
unsigned char temp;
// n= temp-80;
if(RI) //判断是接收中断产生
{
RI=0; //标志位清零
temp=SBUF; //读入缓冲区的值
// P1=Temp; //把值输出到P1口,用于观察
SBUF=temp; //把接收到的值再发回电脑端
}
if(TI) //如果是发送标志位,清零
TI=0;
} */
void UART_send_byte(unsigned char dat)
{
dat= SBUF ;
SBUF = dat;
while(!TI);
TI=0; // 此句可以不要,不影响后面数据的发送,只供代码查询数据是否发送完成
}
void scan()
{
if(zhengzhuan==0&&fanzhuan==0) // 正转
{
delay(10);
if(zhengzhuan==0&&fanzhuan==0)
{
n=5;
UART_send_byte(n);
}
}
if(jiasu==0) // 加速
{
delay(10);
if(jiasu==0)
{
n++;
UART_send_byte(n);
}
}
if(jiansu==0) //减速
{
delay(10);
if(jiansu==0)
{
n--;
UART_send_byte(n);
}
}
}
void main()
{
InitLcd(); //初始化LCD
time_init();
UARTinit();
while(1)
{
keyscan();
scan();
tiaosu();
djkz(highv,lowv);
}
}
我就是检测到按键后需要发送,但是为什么接收不到发送的数字
一周热门 更多>