Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <msp430.h>
- #include <signal.h>
- static volatile long count =0;
- static inline void init_timer_A() {
- TACCR0 = 25000; // since clk = 1MHhz => 25us count
- TACTL = TASSEL1 | MC0;
- //TACCTL0 |= OUTMOD2; / Toggle mode - OUTMODx = 100
- TACCTL0 |= CCIE; //enable interrupt for capture/compatre;
- }
- static inline void uart_init() {
- //config uart for 9600 bps
- P1SEL = BIT1 + BIT2;
- P1SEL2 = BIT1 + BIT2;
- UCA0CTL1 |= UCSSEL_2; //select UCSSELx = 10 - SMCLK
- UCA0BR0 = 104;
- UCA0BR1 = 0;
- UCA0MCTL = UCBRS0; //modulation control.
- UCA0CTL1 &= ~UCSWRST; //this enables Rx and Txhardware
- IE2 |= UCA0RXIE;
- }
- interrupt(TIMER0_A0_VECTOR) timer_blink(void) {
- //generate delay for 500ms
- count++;
- if(count >= 20) {
- P1OUT ^= (BIT0 + BIT6);
- count = 0;
- }
- }
- interrupt(USCIAB0RX_VECTOR) echo(void) {
- while(!(IFG2 & UCA0TXIFG));
- UCA0TXBUF = UCA0RXBUF; //echo
- }
- int main(int argc, const char *argv[])
- {
- WDTCTL = WDTPW + WDTHOLD;
- __write_status_register(OSCOFF);
- P1DIR = BIT0 + BIT6;
- P1OUT = BIT0;
- if(CALBC1_1MHZ != 0xff) { //set up for 1Mhz operting freq.
- DCOCTL=0;
- BCSCTL1 = CALBC1_1MHZ;
- DCOCTL = CALDCO_1MHZ;
- }
- uart_init();
- init_timer_A();
- eint();
- LPM0;
- while(1) {
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement