一个关于printf串口打印的问题 找不到问题所在 求大虾 帮.....
时间:10-02
整理:3721RD
点击:
#include<stdio.h>
#include <reg52.h>
#include<intrins.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
//////////////////////////////////
bit Flag;
//////////////////////////////////
sbit studylamp=P2^7;
sbit lamp=P2^6;
sbit studykey=P3^2;
sbit remotein=P1^1;
sbit remoteout=P1^0;
sbit txkey=P2^0;
uint i,j,m=255,n,k,s;
uchar idata remotedata[206];
int head;
uint remdata;
int temp=100;
////////////////////////////////////
uint ReData,SenData;
///////////////////////////////////
void init_chuankou()
{
SCON = 0x50; //REN=1允许串行接受状态,串口工作模式1
TMOD|= 0x20; //定时器工作方式2
PCON|= 0x80;
//TH1 = 0xFD; //baud*2 /* reload value 19200、数据位8、停止位1。效验位无 (11.0592)
TH1 = 0xF3; // //baud*2 /* 波特率4800、数据位8、停止位1。效验位无 (12M)
TL1 = 0xF3;
TR1 = 1;
ES = 1; //开串口中断
EA = 1; // 开总中断
}
//一毫秒延时程序
delay1ms(uint t)
{
for(i=0;i<t;i++)
for(i=0;j<120;j++);
}
//初始化函数
clearmen()
{
studylamp=1;
lamp=1;
remoteout=0;
remotein=1;
for(i=0;i<206;i++)
{
remotedata[i]=0x00;
}
IE=0x00;
IP=0x01;
TMOD=0x22;
PCON=0X00;
TH1=0xf3;
TL1=0xf3;
IT0=1;
EX0=1;
EA=1;
}
//键功能函数
void key_tx()
{
if(txkey==0)
{delay1ms(1);
if(txkey==0)
{
while(txkey==0);
ET1=1;
TR1=1;
for(i=head;i>0;i--);
remoteout=0;
T1=0;
TR1=0;
n=0;
while(1)
{
lamp=0;
studylamp=1;
if(remotedata[n]==0x00)
{
delay1ms(10);
break;
}
for(i=remotedata[n];i>0;i--)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
}
n++;
ET1=1;
TR1=1;
for(i=remotedata[n];i>0;i--);
remoteout=0;
ET1=0;
TR1=0;
n++;
}
}
}
////////////////////////////////
ES=0;
TI=1;
puts("\n ce shi shu ju ru xia .....\n");
// printf("head is :%d\n",head); //////////////////////////这一句注释啦 就没问题 打开就有问题 不知道 何故 求解??
while(!TI);
TI=0;
ES=1;
Flag=0;
}
////////////////////////////
//主函数
void main()
{
clearmen(); //初始化
init_chuankou();
while(1)
{
if(Flag==1)
{
ES=0;
SBUF=SenData; //SUBF接受/发送缓冲器
while(TI==0);
TI=0;
TI=1;
puts("\n hello world\n");
// printf("kai shi ce shi ....\n");
while(!TI);
TI=0;
ES=1;
Flag=0;
break;
}
}
while(1)
{
key_tx(); //按键扫描
}
}
//40KHz发生器
void time_intt1(void) interrupt 3
{
remoteout=~remoteout;
}
//外中断0
void intt0(void) interrupt 0
{
ET1=0;
TR1=0;
EX0=0;
EA=0;
head=0;
while(studykey==0);
studylamp=0;
lamp=1;
while(remotein==1);
head=0;
while(remotein==0)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
head++;
}
n=0;
remdata=0x0000;
while(1)
{
while(remotein==1)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
remdata++;
}
if(remdata>m) //高电平>5毫秒退出?
{
remotedata[n]=0x00;
EX0=1;
EA=1;
goto end;
}
remotedata[n]=remdata;
n++;
remdata=0x0000;
while(remotein==0)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
remdata++;
}
remotedata[n]=remdata;
n++;
remdata=0x00;
}
end: lamp=0;
studylamp=0;
}
/****************************************************
串口中断程序
******************************************************/
void ser_int (void) interrupt 4
{
// if(RI == 1) //RI接受中断标志
{
RI = 0; //清除RI接受中断标志
ReData = SBUF; //SUBF接受/发送缓冲器
SenData=ReData;
Flag=1;
}
}
#include <reg52.h>
#include<intrins.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
//////////////////////////////////
bit Flag;
//////////////////////////////////
sbit studylamp=P2^7;
sbit lamp=P2^6;
sbit studykey=P3^2;
sbit remotein=P1^1;
sbit remoteout=P1^0;
sbit txkey=P2^0;
uint i,j,m=255,n,k,s;
uchar idata remotedata[206];
int head;
uint remdata;
int temp=100;
////////////////////////////////////
uint ReData,SenData;
///////////////////////////////////
void init_chuankou()
{
SCON = 0x50; //REN=1允许串行接受状态,串口工作模式1
TMOD|= 0x20; //定时器工作方式2
PCON|= 0x80;
//TH1 = 0xFD; //baud*2 /* reload value 19200、数据位8、停止位1。效验位无 (11.0592)
TH1 = 0xF3; // //baud*2 /* 波特率4800、数据位8、停止位1。效验位无 (12M)
TL1 = 0xF3;
TR1 = 1;
ES = 1; //开串口中断
EA = 1; // 开总中断
}
//一毫秒延时程序
delay1ms(uint t)
{
for(i=0;i<t;i++)
for(i=0;j<120;j++);
}
//初始化函数
clearmen()
{
studylamp=1;
lamp=1;
remoteout=0;
remotein=1;
for(i=0;i<206;i++)
{
remotedata[i]=0x00;
}
IE=0x00;
IP=0x01;
TMOD=0x22;
PCON=0X00;
TH1=0xf3;
TL1=0xf3;
IT0=1;
EX0=1;
EA=1;
}
//键功能函数
void key_tx()
{
if(txkey==0)
{delay1ms(1);
if(txkey==0)
{
while(txkey==0);
ET1=1;
TR1=1;
for(i=head;i>0;i--);
remoteout=0;
T1=0;
TR1=0;
n=0;
while(1)
{
lamp=0;
studylamp=1;
if(remotedata[n]==0x00)
{
delay1ms(10);
break;
}
for(i=remotedata[n];i>0;i--)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
}
n++;
ET1=1;
TR1=1;
for(i=remotedata[n];i>0;i--);
remoteout=0;
ET1=0;
TR1=0;
n++;
}
}
}
////////////////////////////////
ES=0;
TI=1;
puts("\n ce shi shu ju ru xia .....\n");
// printf("head is :%d\n",head); //////////////////////////这一句注释啦 就没问题 打开就有问题 不知道 何故 求解??
while(!TI);
TI=0;
ES=1;
Flag=0;
}
////////////////////////////
//主函数
void main()
{
clearmen(); //初始化
init_chuankou();
while(1)
{
if(Flag==1)
{
ES=0;
SBUF=SenData; //SUBF接受/发送缓冲器
while(TI==0);
TI=0;
TI=1;
puts("\n hello world\n");
// printf("kai shi ce shi ....\n");
while(!TI);
TI=0;
ES=1;
Flag=0;
break;
}
}
while(1)
{
key_tx(); //按键扫描
}
}
//40KHz发生器
void time_intt1(void) interrupt 3
{
remoteout=~remoteout;
}
//外中断0
void intt0(void) interrupt 0
{
ET1=0;
TR1=0;
EX0=0;
EA=0;
head=0;
while(studykey==0);
studylamp=0;
lamp=1;
while(remotein==1);
head=0;
while(remotein==0)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
head++;
}
n=0;
remdata=0x0000;
while(1)
{
while(remotein==1)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
remdata++;
}
if(remdata>m) //高电平>5毫秒退出?
{
remotedata[n]=0x00;
EX0=1;
EA=1;
goto end;
}
remotedata[n]=remdata;
n++;
remdata=0x0000;
while(remotein==0)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
remdata++;
}
remotedata[n]=remdata;
n++;
remdata=0x00;
}
end: lamp=0;
studylamp=0;
}
/****************************************************
串口中断程序
******************************************************/
void ser_int (void) interrupt 4
{
// if(RI == 1) //RI接受中断标志
{
RI = 0; //清除RI接受中断标志
ReData = SBUF; //SUBF接受/发送缓冲器
SenData=ReData;
Flag=1;
}
}
”printf“你想用这个函数做什么?你想一下单片机怎么识别这个函数
你想用printf这个函数做什么?你单片机怎么执行你这个函数?
此问题我已经解决了 写成子函数就没问题了 但还是不知道为什么 谢谢大虾们 恢复
学习 学习 谢谢分享
