|
#include "msp430g2553.h"
unsigned char MST_Data, SLV_Data;
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT = 0x00; // P1 setup for LED & reset output
P1DIR |= BIT0; //
P1SEL = BIT1 + BIT2 + BIT4 + BIT5;
P1SEL2 = BIT1 + BIT2 + BIT4 + BIT5;
UCA0CTL0 |= UCCKPL + UCMSB + UCMST + UCSYNC + UCMODE_2; // 4-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 |= 0x02; // /2
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
__delay_cycles(75); // Wait for slave to initialize
MST_Data = 0x01; // Initialize data values
SLV_Data = 0x01;
UCA0TXBUF = MST_Data; // Transmit first character
__bis_SR_register(LPM0_bits + GIE); // CPU off, enable interrupts
}
// Test for valid RX and TX character
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR(void)
{
volatile unsigned int i;
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
if (UCA0RXBUF == SLV_Data) // Test for correct character RX'd
P1OUT |= BIT0; // If correct, light LED
else
P1OUT &= ~BIT0; // If incorrect, clear LED
MST_Data++; // Increment master value
SLV_Data++; // Increment expected slave value
UCA0TXBUF = MST_Data; // Send next value
__delay_cycles(50); // Add time between transmissions to
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|