Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <msp430.h>
- volatile unsigned int start_time;
- volatile unsigned int stop_time;
- volatile unsigned int max_time;
- volatile unsigned int counter = 0;
- #pragma vector = TIMER0_A1_VECTOR
- __interrupt void counter1(void){
- counter++;
- TA0CTL &= ~TAIFG;
- }
- #pragma vector = PORT1_VECTOR
- __interrupt void IR_SENSORS(void){
- if((P1IFG & 1) != 0){
- start_time = counter;
- max_time = TA0CCR0 * 2000;
- if((P1IN & 1) != 0){
- stop_time = start_time;
- if(stop_time < max_time){
- P2OUT ^= 1<<3;
- }
- }
- P1IFG &= ~1;
- }
- if((P1IFG & 1<<1) != 0){
- P2OUT ^= 1<<4;
- P1IFG &= ~(1<<1);
- }
- if((P1IFG & 1<<2) != 0){
- P2OUT ^= 1<<5;
- P1IFG &= ~(1<<2);
- }
- }
- int main(void){
- WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
- DCOCTL = CALDCO_1MHZ;
- BCSCTL1 = CALBC1_1MHZ;
- TA0CTL |= TASSEL_2 | ID_1 | MC_1 | TAIE; //1 SEC = 1MHZ.
- TA0CCR0 = 1000; // 1ms
- P2DIR |= 1<<3 | 1<<4 | 1<<5;
- P2OUT |= 1<<3 | 1<<4 | 1<<5;
- P1DIR &= ~(1 | 1<<1 | 1<<2);
- P1REN |= 1 | 1<<1 | 1<<2;
- P1OUT &= ~(1 | 1<<1 | 1<<2);
- P1IE |= 1 | 1<<1 | 1<<2;
- P1IES &= ~(1 | 1<<1 | 1<<2);
- __enable_interrupt();
- while(1){
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement