Advertisement
utroz

MSP430 Alternative LED

Sep 14th, 2011
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. /*
  2. --------------------------------
  3.  MSP 430
  4.  LED : RESET INT 0.x1
  5.  Developed by: Utroz(Raphael) and Kaddoush(Pablo)
  6.  Blog: http://oakcoders.com
  7. --------------------------------
  8. */
  9.  
  10. #include "io430.h"
  11. /* Definição de interrupções(ON/OFF) e manipulação de registradores */
  12. #include "in430.h"
  13.  
  14. #define LED_RED BIT0
  15. #define LED_GREEN BIT1
  16. #define DELAY 0xC350
  17.  
  18. unsigned short value = 0x01;
  19.  
  20. void delay(unsigned int arg)
  21. {
  22.      for(; arg > 0; arg--);
  23. }
  24.  
  25. int main(void)
  26. {  
  27.   WDTCTL = WDTPW + WDTHOLD; /* Desativa o watch dog */
  28.   P1DIR |= 0x01; /* Pino P.0 como saída e P.2 como entrada */
  29.   P1REN |= 0x04; /* Habilitar interrupção na porta P.2 */
  30.   P1IE |= 0x04; /* Temporariamente desativa a INT. */
  31.  
  32.   __bis_SR_register(GIE); /* Interrupção Global */
  33.  
  34.   while(1)
  35.   {
  36.     /* Teste condicional para verificar em qual LED(cor) está */
  37.     if(value == LED_RED)  
  38.       P1OUT ^= LED_RED;      /* Desliga LED */
  39.     else P1OUT ^= LED_GREEN; /*    "    "   */
  40.    
  41.     delay(DELAY); /* Chama função de delay */
  42.  
  43.   }    
  44.   return 0;
  45. }
  46.  
  47. /* Tratando RESET INT */
  48. #pragma vector=PORT1_VECTOR
  49. __interrupt void Port_1(void)
  50. {  
  51.   P1IFG &= ~0x04; /* Limpa o flag do registrador de INT */
  52.   P1DIR ^= 0x03; /* Bit a bit XOR para alterar a saída do LED */
  53.   P1OUT ^= 0x03;
  54.  
  55.   value ^= 0x03; /* Sobrecarga em value para teste condicional(0x01 ou 0x02)*/
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement