求助!!!!!!!!1
这是我用查表法做的一个收发数据的程序。大虾能不能帮我用中断来做。因为我是第一次编程。很急!!!!!!!在这先谢谢大虾。我的邮箱是nuowei_37@163.com
#pragma DEBUG OBJECTEXTEND CODE
#include <stdio.h>
#include <reg51.h>
int_port1()
{TMOD=0x20; //T1 mode 2//
SCON=0x50;
TH1=0xFD; //baud=9600//
TL1=0xFD;
PCON=0x00;
IE=0x98;
}
struct header
{
unsigned int destination,opcode,reserve,length,cs;
}header1={0x01,0x02,0x10,0x01};
tx_header() // transmit to dsp//
{
header1.cs=header1.destination^header1.opcode^header1.reserve^header1.length^0xaa;
SBUF=header1.destination;
TI=0;
while(!TI);
TI=0;
SBUF=header1.opcode;
while(!TI);
TI=0;
SBUF=header1.reserve;
while(!TI);
TI=0;
SBUF=header1.length;
while(!TI);
TI=0;
SBUF=header1.cs;
while(!TI);
TI=0;
}
struct rheader
{
unsigned int destination,opcode,ack,length,cs;
}rheader1;
rx_rheader() // receive from dsp//
{
RI=0;
while(!RI);
rheader1.destination=SBUF;
RI=0;
while(!RI);
rheader1.opcode=SBUF;
RI=0;
while(!RI);
rheader1.ack=SBUF;
RI=0;
while(!RI);
rheader1.length=SBUF;
RI=0;
while(!RI);
rheader1.cs=SBUF;
RI=0;
rheader1.cs=rheader1.destination^rheader1.opcode^rheader1.ack^rheader1.length^0xaa;
}
void main(void)
{
int_port1();
interrupt
tx_header();
rx_rheader();
while(1);
}
发表时间:2003年4月25日16:28:41