#include"precomp.h" #include"rsbus.h" #include"sysctl.h" int cnt=0; void port_init(void) { P1DIR |= BIT0+BIT6; // P1.0 P1.6 output P1OUT = 0; } void received(unsigned char* str,int len) { rsbus_w(0,str,len); } // Timer A0 interrupt service routine #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A0 (void) { ++cnt; if (cnt==25) { STATE(0)=(STATE(0)+1)&0xFF; cnt=0; P1OUT^=BIT6; } } //TIMER A0 initialize - // desired value: 5ms void TimerA0_Init(void) { // Configure TimerA0 TA0CTL = TASSEL_2 + MC_1 +ID_3 ; // Source: SMCLK=4MHz, UP mode, DIV by 8 -> 0.5M TA0CCR0 = 20000; // 0.5MHz / 20000 -> 25Hz -> 40ms TA0CCTL0 = CCIE; // CCR0 interrupt enabled } void init_devices(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF) while(1)_BIS_SR(CPUOFF); // If calibration constants erased, trap CPU!! BCSCTL1 = CALBC1_16MHZ; // Set range DCOCTL = CALDCO_16MHZ; // Set DCO step + modulation£¬DCO=8MHz BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO IFG1 &= ~OFIFG; // Clear OSCFault flag BCSCTL2 |= DIVS_2; // SMCLK = DCO/4 = 4MHz sysctl_init(); port_init(); TimerA0_Init(); rsbus_init(&received); _BIS_SR(GIE); } void main(void) { init_devices(); while(1) sysroutine(); }