打印
[经验分享]

关于printf 的 一个问题 亲 help!!!串口使用

[复制链接]
1331|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lurun|  楼主 | 2012-7-18 21:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <reg52.h>
#include<stdio.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=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); ////////////////////////////////请问这一句有什么问题啊 注释 就没有问题啦
//printf("a is shi:%d\n",temp);        
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;


}

}
沙发
lurun|  楼主 | 2012-7-20 10:06 | 只看该作者
错误:
SEGMENT:?ID?KONGDIANSHI
LENGTH:00CEH
***ERROR L105:PUBLIC REFERS TO IGNORED SEGMENT
SYMBOL: REMOTEDATA
SEGMENT:?ID?KONGDIANSHI

使用特权

评论回复
板凳
lurun|  楼主 | 2012-7-20 10:07 | 只看该作者
求解啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

3

帖子

0

粉丝