//****************************************************************************** // Coder on MSP430 for RC toy remote control (RX2/TX2 set) // *replacing TX2 chip (in RF transmitter) with MSP430F20xx // // +3V ----------------- // | | XIN|- X -- // ----|RST | 32kHz (for IR calibration) // | XOUT|- X -- // ------------|P1.4 | // SW1| ---------|P1.5 | // \ | ------|P1.6 P1.3|--> to RF modulator (0V to +3V) // | \ | ---|P1.7 | (or LED (1k to +3V req.)) // --- | \ | | | // --- | \ MSP430F20xx // --- |SW4 // --- SK_Lab 2019 // Thanks to Texas Instruments, Inc // Built with CCS Version: 7.4.0.x. Flash/FRAM = 962 bytes. RAM = 51 bytes. //****************************************************************************** #include char command=0; void try_to_choose (char a); void try_to_send (char b); int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_1MHZ; // For 1MHz. Set range DCOCTL = CALDCO_1MHZ; // For 1MHz. Set DCO step + modulation */ P1DIR |= 0x08; // Set P1.3 to output direction P1REN |= 0xF0; // P1.4,5,6,7 pullup resistors P1OUT &= ~0x08; // Set P1.3 output to 'Lo' (RF 'OFF') P1IE |= 0xF0; // P1.4,5,6,7 interrupt enabled P1IES |= 0xF0; // P1.4,5,6,7 interrupt on Hi/lo edge P1IFG &= ~0xF0; // P1.4,5,6,7 IFG cleared __bis_SR_register(LPM3_bits + GIE); // Enter LPM4 w/interrupt } //Next will happen if level at any of P1.4,5,6,7 has fallen (button pressed) #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { //Will stuck in this loop if you hold buttons pressed. while ((P1IN & 0xF0) != 0xF0) //Is any button stay pressed? { command = ((P1IN>>4) ^ 0x0F); //Read buttons & convert to 0...15 try_to_choose (command); //Conversion & send } P1IFG &= ~0xF0; // P1.4 IFG cleared } //Choose the command (num. of pulses to transmit) vs button pressed; void try_to_choose (char a) { switch( a ) { case 0x01: try_to_send (58); break; //0001 - 58 case 0x02: try_to_send (40); break; //0010 - 40 case 0x03: try_to_send (52); break; //0011 - 52 case 0x04: try_to_send (10); break; //0100 - 10 case 0x05: try_to_send (28); break; //0101 - 28 case 0x08: try_to_send (64); break; //1000 - 64 case 0x0A: try_to_send (46); break; //1010 - 46 case 0x0C: try_to_send (34); break; //1100 - 34 } } //Generates 4 pulses "start" and amount of DATA pulses, as in variable 'b'. void try_to_send (char b) { char counter_st_pls = 4; //Will be 4 "Start" pulses while (counter_st_pls) //loop, 4 times { __delay_cycles(1500); P1OUT |= 0x08; //"Space", 1.5mS __delay_cycles(500); P1OUT &= ~0x08; //"Pulse", 0.5mS counter_st_pls--; } while (b) //Will be 'b' "DATA" pulses w/"Spaces" { __delay_cycles(500); P1OUT |= 0x08; //"Space", 0.5mS __delay_cycles(500); P1OUT &= ~0x08; //"Pulse", 0.5mS b--; } } /******************************************************************************/