CH549EVT development board test - running light test
[Copy link]
This post was last edited by hujj on 2019-6-26 21:19
When I first came into contact with a new microcontroller, the first thing I did was of course to light up the LED. After the development platform was established and the download test was successful, I began to try to light up the light. At first, I was a little far-fetched and went to the manufacturer's forum to look for reference materials. After a few days, there was no result. I just didn't know how to control the level of the pin. Later, I suddenly thought that I should look for it in the examples provided by the manufacturer. In the GPIO directory, I found an example of controlling LED lights. In fact, it is very simple. According to the provided example, the first step is to add GOPI.C to the project (of course, you can also directly open the project file in the example). The second step is to add the code of MAIN.C in the example to main.c in the project. The code involved in lighting the light is mainly:
1. Add included header files
#include ".\GPIO\GPIO.H"
2. Define the pins (bits) corresponding to the LED
sbit LED2 = P2^2;
sbit LED3 = P2^3;
sbit LED4 = P2^4;
sbit LED5 = P2^5;
3. Configure the pins in the main function
/* Configure GPIO */
GPIO_Init( PORT1,PIN0,MODE3); //P1.0 pull-up input
GPIO_Init( PORT1,PIN4,MODE1); //P1.4 push-pull output
/* Configure external interrupt */
GPIO_Init( PORT0,PIN3,MODE3); //P03 pull-up input
GPIO_Init( PORT1,PIN5,MODE3); //P15 pull-up input
GPIO_Init( PORT3,PIN2,MODE3); //P32 (INT0) pull-up input
GPIO_Init( PORT3,PIN3,MODE3); //P33 (INT1) pull-up input
GPIO_INT_Init( (INT_P03_L|INT_P15_L|INT_INT0_L|INT_INT1_L),INT_EDGE,Enable); //External interrupt configuration
4. The pin is high by default, so turn on the first LED before the main loop.
LED2 = ~LED2;
5. Define a variable LEDS, and use the value of this variable to determine the on and off of each LED in the main loop
while(1)
{
ledx++;
switch(ledx){
case 1:
LED2 = ~LED2;
LED3 = ~LED3;
break;
case 2:
LED3 = ~LED3;
LED4 = ~LED4;
break;
case 3:
LED4 = ~LED4;
LED5 = ~LED5;
break;
case 4:
LED5 = ~LED5;
LED2 = ~LED2;
ledx = 0;
}
mDelaymS(100);
}
After downloading to the development board, the LED running light will run happily after reset. The following figure shows the test situation:
|