Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "msp.h"
- // Define SYSTEM TICK
- #define SYSTICK_STCSR (*((volatile unsigned long *)0xE000E010))
- #define SYSTICK_STRVR (*((volatile unsigned long *)0xE000E014))
- #define SYSTICK_STCVR (*((volatile unsigned long *)0xE000E018))
- // Defind state checking
- volatile int state = 0;
- // Prepare method
- void SystemTick_Init(void);
- void SystemTick_wait(uint32_t delay);
- void Port_Init(void);
- // Main loop
- int main(void) {
- Port_Init();
- SystemTick_Init();
- while(1){
- SystemTick_wait(3000000);
- while(~P1IN & 0x02){state = 0;}
- while(~P1IN & 0x10){state = 1;}
- if(state == 0){
- P2OUT = P2OUT << 1;
- if(P2OUT == 0x08){P2OUT = 0x01;}
- }else{
- P2OUT = P2OUT >> 1;
- if(P2OUT == 0x00){P2OUT = 0x04;}
- }
- }
- }
- // Add descript method
- void Port_Init(void){
- P1SEL1 = 0x00;
- P1SEL0 = 0x00;
- P2SEL1 = 0x00;
- P2SEL0 = 0x00;
- P1DIR = 0x00;
- P2DIR = 0x07;
- P1OUT = 0x12;
- P2OUT = 0x01;
- P1REN = 0x12;
- }
- void SystemTick_Init(void){
- SYSTICK_STCSR = 0;
- SYSTICK_STRVR = 0x00FFFFFF;
- SYSTICK_STCVR = 0;
- SYSTICK_STCSR = 0x00000005;
- }
- // delay parameter is units of the 3MHz clock.
- void SystemTick_wait(uint32_t delay){
- SYSTICK_STRVR = delay - 1;
- SYSTICK_STCVR = 0;
- while((SYSTICK_STCSR & 0x00010000) == 0){}
- }
Advertisement
Add Comment
Please, Sign In to add comment