⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tzxmb.c

📁 这是一个成熟的用于单片机和DVD控制MCU之间的通讯的程序.
💻 C
字号:
#include <at89x52.h>
#include <stdio.h> 
#include <math.h>

/////////////////////////////////////////////////
#define DATASIZE 30//100
static unsigned char recdata[DATASIZE];
unsigned int i_count=0;
//unsigned int x=0;
//#define  COM  P3_2

///////////////////////////////////////////////////

void delay1ms(int n)             
{ 
    int p,q;
    do{
       for(p=1;p<10;p++)
       for(q=0;q<35;q++);
       n--;
      }while(n); 

} 

/////////////////////////////////////////////////
void Send_Data_To_Pc(unsigned char dat)
{
    EA=0;
//    COM=1;
    TI=0;  

    SBUF=dat;              //data to 51 send buffer
    while(!TI)             //send to pc 
    {    
    }
    TI=0;
    EA=1; 

//    COM=0;
}

//////////////////////////////////////////////////  
void print(unsigned char dat)
{
//     int i;
	Send_Data_To_Pc(dat+0x30);
//	Send_Data_To_Pc(0xD);//回车
//	Send_Data_To_Pc(0xA);//换行
}

/////////////////////////////////////////////////
void Rec_Data_From_Pc() interrupt 4
{   
    EA=0;  
//    COM=0;
    recdata[i_count++]=SBUF; 
//	Send_Data_To_Pc(recdata[i_count-1]);
//	Send_Data_To_Pc(SBUF);
   while(!RI)                    
      {;
      }
    RI=0;
    EA=1;
}

//////////////////////////////////////////////////
void InitCom(void)
{
   EA=0;

   SCON=0x50;
   TMOD=0x20;

   TH1=0xfd;//set 19.6kbps rate.
   TL1=0xfd;

//wfu080918   PCON=PCON|0x80;//19200 bps 
   PCON=PCON|0x40;//9600 bps 
   IE=0x90;
   IT0=0;  //Use the level trigger
   TR1=1; 

   EA=1;                            
}

///////////////////////////////////////////////////
void InitVar(void)
{
     int i;
     for(i=0;i<DATASIZE;i++)
        recdata[i]=0;
}

//////////////////////////////////////////////////  

void main(void)
{
InitCom();
InitVar();
delay1ms(100);
//COM=0;

while(1)
	{
	int i;
	
//	for(i=0;i<100;i++)
//		Send_Data_To_Pc(0x30);
//	m=i_count;
	if(i_count>0)
		{
		EA=0;
		//print(i_count);
		//COM=1;
		for(i=0;i<i_count;i++)
			{
			//print(i);
			Send_Data_To_Pc(recdata[i]);
			//recdata[i]=0x36;
			//delay1ms(100);
			}
		i_count=0;
		//COM=0;
		Send_Data_To_Pc(0xD);//回车
		Send_Data_To_Pc(0xA);//换行
		EA=1;
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -