// transmit and receive 3 // using buffers // working as of Dec. 2, 2004 #include <16F628.h> #device adc=8 #use delay(clock=4000000) #fuses PUT, XT, NOMCLR, NOWDT, NOLVP, NOBROWNOUT #use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8) // --------------------- // Port B // --------------------- //#define TRW_CLK2 PIN_B0 // #define TRW_CLK1 PIN_B5 // #define TRW_CS PIN_B7 // #define TRW_CE PIN_B3 // //#define TRW_DOUT2 PIN_B4 // #define TRW_DATA PIN_B4 // #define TRW_DR1 PIN_B6 // //#define TRW_DR2 PIN_B7 // // 0-out 1-in 0b76543210 #define B_TRIS 0b11110000 inline initPorts() { port_b_pullups(FALSE); disable_interrupts(INT_RB); // SET_TRIS_A( A_TRIS ); // SET_TRIS_B( B_TRIS ); // SET_TRIS_C( C_TRIS ); } // ======================================================================== // Timing // #define XTAL 4000000 #define IPS (XTAL/4) // Master tick clock is 8bit with no prescaler //> 20kHz , 50us =BUFFER_SIZE)j=0; unsent_bytes--; // transmit (RF) trwSetTx(); // switch to transmit delay_ms(1); putBuf(); // send packet (buf) delay_ms(1); // won't go back to recieve without this trwSetRx(); // switch back to receive delay_ms(1); } } //while } //main //--------------------------------------------------------------------------- #int_rda void serial_isr() { int8 a; // add to rf transmit buffer (unless the buffer is full) a = getchar(); if(unsent_bytes +1 < BUFFER_SIZE){ q[i] = a; i++; if(i >= BUFFER_SIZE) i = 0; unsent_bytes++; } }