⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 MSP430 EZ430-F2012 Application on IAR Embedded Workbench that blinks the LED lights on the EZ430.
💻 C
字号:
#include "intrinsics.h"
#include "io430.h"

// *** PINOUTS ***
#define DATA    BIT0 //Data to Shift Register: 9 individual LED positive lines
#define CP      BIT1 //Shift Register Clock Pulse
#define GND1    BIT2 //Ground Control 1
#define GND2    BIT3 //Ground Control 2
#define GND3    BIT4 //Ground Control 3
#define LED_PIN BIT5

//*** INDIVIDUAL LED IDENTIFICATION (on shift Register)***
#define LED1 BIT0
#define LED2 BIT1
#define LED3 BIT2
#define LED4 BIT3
#define LED5 BIT4
#define LED6 BIT5
#define LED7 BIT6
#define LED8 BIT7
#define LED9 1337

void send_LED_chunk(int LED_data);

// lights up one specific LED, without turning off any others.
//g_select: GND1, GND2 or GND3 to select which ground line to pull high.
//id_led: LED1-LED9 to select the individual LED
void light_up(int GNDX, int LEDX)
{
  P1OUT |= (GNDX << 2);
  send_LED_chunk(LEDX);
}

//turn off all LEDs
void lights_off()
{
  P1OUT &= ~(GND1|GND2|GND3);
  send_LED_chunk(0);
}

// Assumes CP is high to begin with & leaves CP high when finished.
// assumes the bit to be sent is the least significant bit.
void send_bit(int bit) {
  P1OUT &= ~(CP);   //set CP low
  //send bit to DATA pin:
  if((bit & BIT0) == 1) {
    P1OUT |= DATA;
  }
  else {
    P1OUT &= ~(DATA);
  }
  P1OUT |= CP;   //set CP high (activate Shift Register)
}

// send a chunk of data (to the positive line of the LEDs)
void send_LED_chunk(int LED_data)
{
  send_bit(LED_data & LED1);          //send LED1
  send_bit((LED_data & LED2) >> 1);   //send LED2
  send_bit((LED_data & LED3) >> 2);   //send LED3
  send_bit((LED_data & LED4) >> 3);   //send LED4
  send_bit((LED_data & LED5) >> 4);   //send LED5
  send_bit((LED_data & LED6) >> 5);   //send LED6
  send_bit((LED_data & LED7) >> 6);   //send LED7
  send_bit((LED_data & LED8) >> 7);   //send LED8
  
  //make an exception for PIN9:
  if(LED_data == LED9) { 
    P1OUT |= LED_PIN;
  }
  else {
    P1OUT &= ~(LED_PIN);
  }
}

int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  P1DIR = DATA | CP | GND1 | GND2 | GND3; //set pins as output
  P1OUT = 0;
  
  //*** LAYER 1 ***
  light_up(GND1, LED1);
  light_up(GND1, LED3);
  light_up(GND1, LED5);
  light_up(GND1, LED7);
  light_up(GND1, LED9);
  
  //*** LAYER 2 ***
  light_up(GND2, LED2);
  light_up(GND2, LED4);
  light_up(GND2, LED6);
  light_up(GND2, LED8);
  
  //*** LAYER 3 ***
  light_up(GND3, LED1);
  light_up(GND3, LED3);
  light_up(GND3, LED5);
  light_up(GND3, LED7);
  light_up(GND3, LED9);
  
  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -