初始化管脚
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //ÉùÃ÷½á¹¹Ìå±äÁ¿
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //ʹÄÜPB¶Ë¿ÚʱÖÓ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
//ÐèÒª³õʼ»¯µÄ¹Ü½Å
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO¿ÚËÙ¶ÈΪ50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //¸ù¾ÝÉ趨²ÎÊý³õʼ»¯GPIOB.12
}
对着原理图,对管脚初始化
#define LED_A PBout(0)
#define LED_B PBout(1)
#define LED_C PBout(2)
#define LED_D PBout(3)
#define LED_1 PBout(12)
#define LED_2 PBout(13)
#define LED_3 PBout(14)
#define LED_4 PBout(15)
并且在led.h中也需要进行初始化。
LE为锁定控制端,当 LE=1时,译码器是锁定保持状态。当LE=0时,允许译码输出。这就是每段需要写一下LED_1=0的原因,即允许译码输出。
LED_1 = 1;
LED_2 = 1;
LED_3 = 1;
LED_4 = 1;
delay_ms(1);
LED_1 = 0;
LED_A = 1;
LED_B = 0;
LED_C = 0;
LED_D = 0; //µÚÒ»¸öÏÔʾ1
LED_1 = 1;
delay_ms(1);
LED_2 = 0;
LED_A = 0;
LED_B = 1;
LED_C = 0;
LED_D = 0; //µÚ¶þ¸öÏÔʾ2
LED_2 = 1;
delay_ms(1);
LED_3 = 0;
LED_A = 0;
LED_B = 1;
LED_C = 0;
LED_D = 0; //µÚÈý¸öÏÔʾ2
LED_3 = 1;
delay_ms(1);
LED_4 = 0;
LED_A = 1;
LED_B = 0;
LED_C = 0;
LED_D = 0; //µÚËĸöÏÔʾ7
LED_4 = 1;
delay_ms(1);
结果如图所示: