Advertisement
Guest User

msp430_uart_and_timer

a guest
Apr 4th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <msp430.h>
  2. #include <signal.h>
  3.  
  4. static volatile long count =0;
  5.  
  6. static inline void init_timer_A() {
  7.  
  8.    
  9.     TACCR0 = 25000; // since clk = 1MHhz => 25us count
  10.     TACTL = TASSEL1 | MC0;
  11.     //TACCTL0 |= OUTMOD2; / Toggle mode - OUTMODx = 100
  12.     TACCTL0 |= CCIE; //enable interrupt for capture/compatre;
  13. }
  14.  
  15.  
  16. static inline void uart_init() {
  17. //config uart for 9600 bps
  18.     P1SEL = BIT1 + BIT2;
  19.     P1SEL2 = BIT1 + BIT2;
  20.    
  21.     UCA0CTL1 |= UCSSEL_2; //select UCSSELx = 10 - SMCLK
  22.     UCA0BR0 = 104;
  23.     UCA0BR1 = 0;
  24.     UCA0MCTL = UCBRS0; //modulation control.
  25.     UCA0CTL1 &= ~UCSWRST; //this enables Rx and Txhardware
  26.  
  27.     IE2 |= UCA0RXIE;
  28. }
  29.  
  30.  
  31.  
  32. interrupt(TIMER0_A0_VECTOR) timer_blink(void) {
  33.     //generate delay for 500ms
  34.     count++;
  35.     if(count >= 20)  {
  36.         P1OUT ^= (BIT0 + BIT6);
  37.         count = 0;
  38.     }
  39. }
  40.  
  41. interrupt(USCIAB0RX_VECTOR) echo(void) {
  42.     while(!(IFG2 & UCA0TXIFG));
  43.     UCA0TXBUF = UCA0RXBUF; //echo
  44. }
  45.  
  46. int main(int argc, const char *argv[])
  47. {
  48.     WDTCTL = WDTPW + WDTHOLD;
  49.     __write_status_register(OSCOFF);
  50.     P1DIR = BIT0 + BIT6;
  51.     P1OUT = BIT0;
  52.  
  53.     if(CALBC1_1MHZ != 0xff) { //set up for 1Mhz operting freq.
  54.         DCOCTL=0;
  55.         BCSCTL1 = CALBC1_1MHZ;
  56.         DCOCTL = CALDCO_1MHZ;
  57.     }
  58.  
  59.     uart_init();
  60.     init_timer_A();
  61.     eint();
  62.     LPM0;
  63.     while(1) {
  64.     }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement