I recently bought the LAB-X2 (by microEngineering Labs) with a 4Mhz 16f877. My development tools are listed below. The problem: the code (attached below), when in the PIC, fails to jump to the "sendData" subroutine. Although the code works properly in the emulator. Has anyone else had this problem and solved it? Could the code generated by the cc5x compiler be effected by the bootloader? I have been researching this problem for about a week and have found nothing useful. I am hoping someone on the list has a solution. Compiler: cc5x V. 3.1C Bootloader: microEngineering Labs, Target firmware V 1.0 IDE: MPLab 5.11.00 Code: A rs232 example problem provided by the maker of cc5x. // ********************************************************* /* SERIAL COMMUNICATION (RS232) ============================ Using 9600 baud, one stop bit, no parity. Baudrate 9600 baud => 104.167 microsec. per bit TMR0 counts each 8th microsec. => 13.02 steps per bit */ #pragma chip PIC16F877 #pragma cdata[0] = 0x0180 + 0x0A // CLRF PCLATH #pragma resetVector 1 // start address for user program // -------------------------------------------- #define _4_MHz /* 4 MHz system clock */ // #define UseTMR0 #pragma bit RS232_out @ PORTC.6 #pragma bit RS232_in @ PORTC.7 #ifdef _4_MHz #define TimeStartbit 4 #define BitTimeIncr 13 #endif char bitCount, limit; char serialData; #ifdef _4_MHz #ifdef UseTMR0 #define delayStart limit = TMR0; #define delayOneBit \ limit += BitTimeIncr; \ while ( limit != TMR0) \ ; #else #define delayStart /* empty */ #define delayOneBit { \ char ti; \ ti = 30; \ do ; while( --ti > 0); \ nop(); \ } /* total: 5 + 30*3 - 1 + 1 + 9 \ = 104 microsec. at 4 MHz */ #endif #endif // //------------------------------------------- // void sendData( char dout) /* sends one byte */ { PORTB.2 = 0; // Test LED RS232_out = 0; /* startbit */ delayStart for ( bitCount = 9; ; bitCount--) { delayOneBit if ( bitCount == 0) break; Carry = 1; /* incl. stopbit */ dout = rr( dout); RS232_out = Carry; } PORTB.1 = 0; // Test LED } // //-------------------------------------------- // #define NText 12 char text( char W) { skip(W); #pragma return[NText] = "Hello world!" } // //------------------------------------------- //-------------- main ---------------------- // void main( void) { char i,j; PORTB = 0b.0000.0001; // xxxx xxxx TRISB = 0b.0000.0000; // xxxx xxxx PORTC = 0b.1111.1111; // xxxx xxxx TRISC = 0b.1011.1111; // xxxx xxxx OPTION = 2; // prescaler divide by 8 PORTB.1 =1; // for ( i = 0; i < NText; i++); PORTB.2 = 1; for ( i = 0; i < NText; i++) { j = text(i); sendData( j ); /* text string */ } WaitNextIO: while ( RS232_in == 1) ; Start_RS232: /* sampling once per bit */ TMR0 = 0; limit = TimeStartbit; while ( limit != TMR0) ; if ( RS232_in == 1) goto StartBitError; bitCount = 8; do { limit += BitTimeIncr; while ( limit != TMR0) ; Carry = RS232_in; serialData = rr( serialData); /* rotate carry */ } while ( -- bitCount > 0); limit += BitTimeIncr; while ( limit != TMR0) ; if ( RS232_in == 0) goto StopBitError; /* 'serialData' can be processed here */ /* NOTE: limited time (40 - 50 microsec.) */ goto WaitNextIO; StopBitError: /* RS232 stopbit error, waiting while line is low */ while ( RS232_in == 0) ; StartBitError: goto WaitNextIO; } // ********************************************************* Regards, Brendon ______________________________________________________________ Brendon R. Holt, Ph.D. E-mail: drholt@flash.net -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads