|
请各位大虾帮忙,现在只要看发送部分的
sbit DSR=P1^6;
sbit DTR=P1^7;
sbit RED=P1^4; //red led
sbit BLUE=P1^5; //blue led
sbit BUTTON=P1^0;// key
unsigned char aa[10]={1,2,3,4,5,6,7,8,9,0};
unsigned char i=0;
unsigned char idata ch[2];
void delay(unsigned char n)
{
unsigned char i;
while(n)
{
for(i=0;i<200;i++);
n--;
}
}
void main()
{
init();
while(1)
{
delay(20);
delay(20);
Send();
if(RED==1)
{
RED=0;
}
delay(20);
}
}
void Serial_Int() interrupt 4
{
if(RI)
{
for(i=0;i<2;i++)
{
ch=SBUF;
while(!RI);
RI=0;
}
}
if(TI)
{
TI=0;
delay(10);
{
SBUF=aa; //aa[10]={1,2,3,4,5,6,7,8,9,0};
while(TI==0);
TI=0;
}
delay(10);
i++;
if(i >= 10)
i=0;
if(DTR==0)
{
DTR=1;
}
else
{
DTR=0;
}
}
}
void init()
{
//crystal 22.1184MHz
SCON=0x50; //serial mode 1,sm2=0,REN=1
TMOD=0x20; //timer mode 2
TH1=0xFA; //auto reload baudrate 9600
TL1=0xFA;
TI=0;
RI=0;
PCON=0x00; //non double baudrate
ET1=0; //timer 1 can not interrupt
ES=1; //enable serial
TR1=1; //timer1 run
EA=1; //enable all interrupt
DTR=0;
DSR=0;
RED=1;
BLUE=1; //0 Led light, 1 led
}
void Send()
{
TI=1;
}
|
|