[Embedded system experiment] 2 Marquee experiment

1 Development environment

  • STM32F407ZGT6
  • Wedge uVision 5

2 Experiment content

  • Create the following function:
  1. The led_left() function realizes that the led light moves to the left, the right light is on, and then the right light is off while the left light is on, and then all are off. The number of cycles is determined by the function entry parameter.
  2. The led_right() function realizes that the led light moves to the right, the left light is on, and then the left light is off while the right light is on, and then all are off. The number of cycles is determined by the function entry parameter.
  3. The led_blink() function realizes the LED light flashing, which light flashes, and the number of flashes are determined by the function entry parameters.
  4. The led_bcd() function realizes the display of values ​​from 0 to 3, such as 0-00, 1-01, 2-10, 3-11, and the displayed value is determined by the function entry parameters.
  • After the function is written, call the demonstration in main() respectively.
[main.c]
int main(void)
{
    
     
	delay_init(168);		//延时初始化 
	LED_Init();				//LED初始化
	
	led_left(3);			//LED右移3次
	led_right(3);			//LED左移3次
	
	led_blink(0,0,3);		//LED0和LED1不闪烁,3次
	led_blink(0,1,3);		//LED0不闪烁,LED1闪烁3次
	led_blink(1,0,3);		//LED0闪烁3次,LED1不闪烁
	led_blink(1,1,3);		//LED0和LED1同时闪烁3次
	
	led_bcd(0);				//显示0——00
	delay_ms(1000);
	led_bcd(1);				//显示1——01
	delay_ms(1000);
	led_bcd(2);				//显示2——10
	delay_ms(1000);
	led_bcd(3); 			//显示3——11

	while(1);
}

3 Experimental code

[main.c]

void led_left(int times){
    
    
	int t=0;
	while(t<times)
	{
    
    
		GPIO_ResetBits(GPIOF,GPIO_Pin_10);
		GPIO_SetBits(GPIOF,GPIO_Pin_9);
		delay_ms(500);
		GPIO_ResetBits(GPIOF,GPIO_Pin_9);
		GPIO_SetBits(GPIOF,GPIO_Pin_10);
		delay_ms(500);
		GPIO_SetBits(GPIOF,GPIO_Pin_9);
		delay_ms(500);
		t++;
	}
}
void led_right(int times){
    
    
	int t=0;
	while(t<times)
	{
    
    
		GPIO_ResetBits(GPIOF,GPIO_Pin_9);
		GPIO_SetBits(GPIOF,GPIO_Pin_10);
		delay_ms(500);
		GPIO_ResetBits(GPIOF,GPIO_Pin_10);
		GPIO_SetBits(GPIOF,GPIO_Pin_9);
		delay_ms(500);
		GPIO_SetBits(GPIOF,GPIO_Pin_10);
		delay_ms(500);
		t++;
	}
}
void led_blink(int pick_9,int pick_10,int times){
    
    
/*注释部分为异步闪烁*/
//	if(pick_9){
    
    
//		int t=0;
//		while(t<times){
    
    
//			GPIO_ResetBits(GPIOF,GPIO_Pin_9);
//			delay_ms(500);
//			GPIO_SetBits(GPIOF,GPIO_Pin_9);
//			delay_ms(500);
//			t++;
//		}
//	}
//	if(pick_10){
    
    
//		int t=0;
//		while(t<times){
    
    
//			GPIO_ResetBits(GPIOF,GPIO_Pin_10);
//			delay_ms(500);
//			GPIO_SetBits(GPIOF,GPIO_Pin_10);
//			delay_ms(500);
//			t++;
//		}
//	}

	if(pick_9&&pick_10){
    
    
		int t=0;
		while(t<times){
    
    
			GPIO_ResetBits(GPIOF,GPIO_Pin_9);
			GPIO_ResetBits(GPIOF,GPIO_Pin_10);
			delay_ms(500);
			GPIO_SetBits(GPIOF,GPIO_Pin_9);
			GPIO_SetBits(GPIOF,GPIO_Pin_10);
			delay_ms(500);
			t++;
		}
	}
	else{
    
    
		if(pick_9){
    
    
			int t=0;
			while(t<times){
    
    
				GPIO_ResetBits(GPIOF,GPIO_Pin_9);
				delay_ms(500);
				GPIO_SetBits(GPIOF,GPIO_Pin_9);
				delay_ms(500);
				t++;
			}
		}
		else if(pick_10){
    
    
			int t=0;
			while(t<times){
    
    
				GPIO_ResetBits(GPIOF,GPIO_Pin_10);
				delay_ms(500);
				GPIO_SetBits(GPIOF,GPIO_Pin_10);
				delay_ms(500);
				t++;
			}
		}
		else{
    
    
			int t=0;
			while(t<times){
    
    
				GPIO_SetBits(GPIOF,GPIO_Pin_10);
				delay_ms(500);
				GPIO_SetBits(GPIOF,GPIO_Pin_10);
				delay_ms(500);
				t++;
			}
		}
	}
}
void led_bcd(int num){
    
    
	switch(num){
    
    
		case 0:
		default:
			GPIO_SetBits(GPIOF,GPIO_Pin_9);
			GPIO_SetBits(GPIOF,GPIO_Pin_10);
			break;
		case 1:
			GPIO_SetBits(GPIOF,GPIO_Pin_9);
			GPIO_ResetBits(GPIOF,GPIO_Pin_10);
			break;
		case 2:
			GPIO_ResetBits(GPIOF,GPIO_Pin_9);
			GPIO_SetBits(GPIOF,GPIO_Pin_10);
			break;
		case 3:
			GPIO_ResetBits(GPIOF,GPIO_Pin_9);
			GPIO_ResetBits(GPIOF,GPIO_Pin_10);
			break;
	}
}

Guess you like

Origin blog.csdn.net/qq_44714521/article/details/108703814