大家好:帮我看看下面这个程序问题在哪里?收到控制码(test)时,程序里面做了相同的延时,实际通过示波器看到的延时却不同,不知道是哪里出了问题。另外,编译时有这个警告:Warning[596] : segment "rbit_0" (20-51) overlaps segment "intsave_2" (4A-4A) Warning[596] : segment "rbit_0" (20-51) overlaps segment "intsave_3" (4B-4B) 会是这个影响吗?程序如下:
#include <pic.h> #define False 0 #define True 1
static volatile bit EnableDir @ (unsigned)&TRISC*8+4; // bit4 in port c static volatile bit Enable @ (unsigned)&PORTC*8+4; // bit4 in port C static volatile bit HostTX @ (unsigned)&PORTC*8+7; // bit7 in port C static volatile bit SendBit @ (unsigned)&PORTA*8+3; // bit3 in port A static volatile bit HsyncPulse @ (unsigned)&PORTA*8+4; // bit4 in port A static volatile bit NoCoaxSign @ (unsigned)&PORTB*8+1; // bit1 in port B static volatile bit test1 @ (unsigned)&PORTB*8+7; // bit7 in port B static volatile bit test @ (unsigned)&PORTC*8+1; // bit1 in port C
unsigned char HDatatemp,Datatemp; unsigned char HData[4],Data[4]; unsigned char waite,i,j;
bit Vsync_flag; bit OverFlag; /****************************************************************/ /* Interrup subprogram */ /****************************************************************/ void interrupt ISR(void) { if(T0IF && T0IE) { T0IF=False; T0IE=False; OverFlag=1; } /* if (RCIF && RCIE) { if (OERR || FERR) // error process, any error drop all { OERR=0; // clean overrun flag RxCommand=RCREG; // read Rx register CREN = 0; // reset receiver CREN = 1; // restart RxFullSign=1; } else { RxCommand=RCREG; // read Rx register RxFullSign=1; } }*/ } void InitialCCP(void) {
CCP1CON=5; CCP2CON=4; TRISC1=1; TRISC2=1; TMR1CS=0; TMR1ON=1; GIE=True; } void IO_Initial(void) { TRISA=0xf7; TRISB=0x02; TRISC=0xAe; RBPU=0; ADCON0=0; ADCON1=0x06; SendBit=0; } void TMR0_Initial(void) { T0CS=1; // set T0 counter mode and down edge trigger T0SE=1; TMR0=00; T0IF=False; T0IE=False; } void WGT_Init(void) { PSA=1; //if no clear WGT in 36ms,CPU reset. PS0=1; PS1=1; PS2=1; } void TMR2_Init(void) { TMR2IF=False; // clean interrupt flag TMR2IE=0; // disenable interrupt PEIE=True; } void sci_Init(void) { BRGH = 1; /* high baud rate */ SPBRG = 64; /* set the baud rate 19200bps */ SYNC = 0; /* asynchronous */ SPEN = 1; /* enable serial port pins */ CREN = 1; /* enable reception */ SREN = 0; /* no effect */ TXIE = 0; /* disable tx interrupts */ RCIE = 1; /* disable rx interrupts */ TX9 = 0; /* 8- or 9-bit transmission */ //RX9 = 0; /* 8- or 9-bit reception */ TXEN = 1; /* enable the transmitter */ } void delay1(void) { //3.4us;2.6us // waite++;waite++; waite=0; waite++;//waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; } void delay2(void) { //11.2us; waite=0;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;//waite++;//waite++; waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++;waite++; } void delay3(void) { //6.2us; waite=0;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; } void delay4(void) { //7.6us; waite=0;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; waite++;waite++; } void delay5(void) { //6.2us; waite=0;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; waite++;waite++;waite++;waite++;waite++; // waite++;waite++;waite++;waite++;waite++; } void GetData(void) { unsigned char loop; // HDatatemp=0; // Datatemp=0; // SendBit=0; // RCIE = 0; while (TMR0<0xf8);//f8 while (!HsyncPulse); while (TMR0<0xfa); //fa //11 while (!HsyncPulse); while(TMR0<254);//15 while (!HsyncPulse); for(loop=0;loop<4;loop++) { HDatatemp=0; Datatemp=0; // while (!HsyncPulse); while (HsyncPulse); // delay2();//11.2us delay5();//5.2us if (test) { HDatatemp|=0x10;//0.4us test1=1;//0.2us } else { // test1=1; HDatatemp|=0;//0.2us test1=0; test1=0; test1=0; } delay1(); //2.6us if (test) { HDatatemp|=0x8;//0.4us test1=1; } else //0.6us { HDatatemp|=0;//0.2us test1=0;//0.2us test1=0; test1=0;
} delay1();//2.6us if (test) { HDatatemp|=0x4; test1=1; } else //0.6us { HDatatemp|=0;//0.2us test1=0;//0.2us test1=0; test1=0; } delay1();//2.6us if (test) //1.4us??????????? { HDatatemp|=0x2;//0.4us test1=1;//0.2us } else { HDatatemp|=0; test1=0; test1=0; test1=0; } delay1();//2.6us if (test) { HDatatemp|=0x1;//0.4us test1=1;//0.2us } else { HDatatemp|=0; test1=0; test1=0; test1=0; } //----------------------------数据 delay1();//2.6us if (test) { Datatemp|=0x80; test1=1; } else { Datatemp|=0; test1=0; test1=0; test1=0; } delay1(); if (test) { Datatemp|=0x40; test1=1; } else { Datatemp|=0; test1=0; test1=0; test1=0; } delay1(); if (test) { Datatemp|=0x20; test1=1; } else { Datatemp|=0; test1=0; test1=0; test1=0; } delay1(); if (test) { Datatemp|=0x10; test1=1; } else { Datatemp|=0; test1=0; test1=0; test1=0; } delay1(); if (test) { Datatemp|=0x8; test1=1; } else { Datatemp|=0; test1=0; test1=0; test1=0; } delay1(); if (test) { Datatemp|=0x4; test1=1; } else { Datatemp|=0; test1=0; test1=0; test1=0; } delay1(); if (test) { Datatemp|=0x2; test1=1; } else { Datatemp|=0; test1=0; test1=0; test1=0; } delay1(); if (test) { Datatemp|=0x1; test1=1; } else { Datatemp|=0; test1=0; test1=0; test1=0; } HData[loop] =HDatatemp; Data[loop] =Datatemp; delay4();//7.2us } test1=0; } void ReceiveFromCoax(void) { unsigned char loop; for (loop=0;loop<4;loop++) { HData[loop]=0; Data[loop] =0; } HDatatemp=0; Datatemp =0; GetData(); } void SendCommandToOut(void) {
if(HData[0]==0x13 )&&HData[1]==0xc )&&HData[2]==0x13 &&HData[3]==0xc) { for (i=0;i<4;i++); { TXREG=Data; for (j=0;j<55;j++) delay2(); //19200 90*6.2us>520us } } } void main (void) { IO_Initial(); InitialCCP(); WGT_Init(); TMR0_Initial(); TMR2_Init(); sci_Init(); EnableDir=0; //output Enable=0; while (NoCoaxSign) { if (!HostTX) { EnableDir=0; //output for (i=0;i<140;i++) for (j=0;j<15;j++); } EnableDir=1;//input asm ("clrwdt"); } for(;;) { ReFind: while (HsyncPulse); while (!HsyncPulse); for (i=0;i<9;i++); if (HsyncPulse) { Vsync_flag=True; goto ReFind; } // SendBit=0; if (Vsync_flag) { OverFlag=0; asm ("clrwdt"); TMR0=0xf3; T0IF=False; T0IE=True; Vsync_flag=False; // RCIE = 0; test1=0; ReceiveFromCoax(); // RCIE = 1; SendCommandToOut(); } } }
|