Sarik_Kumpan

LED slide

Nov 15th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include "msp.h"
  2.  
  3. // Define SYSTEM TICK
  4. #define SYSTICK_STCSR (*((volatile unsigned long *)0xE000E010))
  5. #define SYSTICK_STRVR (*((volatile unsigned long *)0xE000E014))
  6. #define SYSTICK_STCVR (*((volatile unsigned long *)0xE000E018))
  7. // Defind state checking
  8. volatile int state = 0;
  9.  
  10. // Prepare method
  11. void SystemTick_Init(void);
  12. void SystemTick_wait(uint32_t delay);
  13. void Port_Init(void);
  14.  
  15. // Main loop
  16. int main(void) {
  17.     Port_Init();
  18.     SystemTick_Init();
  19.     while(1){
  20.         SystemTick_wait(3000000);
  21.         while(~P1IN & 0x02){state = 0;}
  22.         while(~P1IN & 0x10){state = 1;}
  23.         if(state == 0){
  24.             P2OUT = P2OUT << 1;
  25.             if(P2OUT == 0x08){P2OUT = 0x01;}
  26.         }else{
  27.             P2OUT = P2OUT >> 1;
  28.             if(P2OUT == 0x00){P2OUT = 0x04;}
  29.         }
  30.     }
  31. }
  32.  
  33. // Add descript method
  34. void Port_Init(void){
  35.     P1SEL1 = 0x00;
  36.     P1SEL0 = 0x00;
  37.     P2SEL1 = 0x00;
  38.     P2SEL0 = 0x00;
  39.     P1DIR = 0x00;
  40.     P2DIR = 0x07;
  41.     P1OUT = 0x12;
  42.     P2OUT = 0x01;
  43.     P1REN = 0x12;
  44. }
  45.  
  46. void SystemTick_Init(void){
  47.         SYSTICK_STCSR = 0;
  48.       SYSTICK_STRVR = 0x00FFFFFF;
  49.       SYSTICK_STCVR = 0;
  50.       SYSTICK_STCSR = 0x00000005;
  51. }
  52.  
  53. // delay parameter is units of the 3MHz clock.
  54. void SystemTick_wait(uint32_t delay){
  55.     SYSTICK_STRVR = delay - 1;
  56.     SYSTICK_STCVR = 0;
  57.     while((SYSTICK_STCSR & 0x00010000) == 0){}
  58. }
Advertisement
Add Comment
Please, Sign In to add comment