MSP430F169 (1) —— Light up the LED

LED module

1. Working principle of LED lamp

Insert picture description here
The core part of the light-emitting diode is a wafer composed of a P-type semiconductor and an N-type semiconductor. There is a transition layer between the P-type semiconductor and the N-type semiconductor, called a PN junction. In the PN junction of some semiconductor materials, the injected minority carriers and majority carriers will release excess energy in the form of light, thereby directly converting electrical energy into light energy. The reverse voltage is added to the PN junction, and minority carriers are difficult to inject, so they do not emit light. When it is in the forward working state ( that is, the forward voltage is applied to both ends ), when the current flows from the anode to the cathode of the LED, the semiconductor crystal emits light of different colors from ultraviolet to infrared. The intensity of the light is related to the current.

2. LED circuit

Insert picture description here

Code analysis

1. Bit operation LED water light

void LED_light_By_Bit_Open()
{
	volatile unsigned int j;
	volatile unsigned int i;
	for (;;)
	{
	for (j = 0;j < 8;j++)			//从左向右依次点亮
	{
	    P6OUT = P6OUT << 1;
	    i = 5000;
	    do(i--);
	    while (i != 0) ;
	}
	P6OUT = 0XFF;	
	for (j = 0;j < 8;j++)			//从右向左依次点亮
	    {
	        P6OUT = P6OUT >> 1;
	        i = 5000;
	        do(i--);
	        while (i != 0) ;
	    }
	P6OUT = 0XFF;
	}
}

2. Switch LED water light

void LED_Runing(unsigned char LED_NUM)
{
	switch(LED_NUM)
	{
        case 0:
          LED8 &= ~(1<<0);  //点亮D1灯
          break;
        case 1:
          LED8 &= ~(1<<1);  //点亮D2灯
          break;
        case 2:
          LED8 &= ~(1<<2);  //点亮D3灯
          break;
        case 3:
          LED8 &= ~(1<<3);  //点亮D4灯
          break; 
        case 4:
          LED8 &= ~(1<<4);  //点亮D5灯
          break;
        case 5:
          LED8 &= ~(1<<5);  //点亮D6灯
          break;
        case 6:
          LED8 &= ~(1<<6);  //点亮D7灯
          break;
        case 7:
          LED8 &= ~(1<<7);  //点亮D8灯
          break;				
        default:
          LED8 = 0x00;     //点亮所有的LED灯
          break;
	}
}

Published 3 original articles · won 3 · views 112

Guess you like

Origin blog.csdn.net/qq_43313294/article/details/105528101