4370 views|3 replies

931

Posts

3

Resources
The OP
 

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:

This post is from MCU

Latest reply

  Details Published on 2019-7-2 09:17
 

2w

Posts

341

Resources
2
 

Once you can light a lamp, you can start learning microcontrollers.

Support learning domestic single-chip microcomputer

This post is from MCU

Comments

Yes, this is the beginning, and you can go deeper step by step from there.  Details Published on 2019-6-27 09:23
 
 

931

Posts

3

Resources
3
 
qwqwqw2088 posted on 2019-6-27 07:34 If you can light a lamp, you can start learning about single-chip microcomputers. Support learning about domestic single-chip microcomputers

Yes, this is the beginning, and you can go deeper step by step from there.

This post is from MCU
 
 
 

305

Posts

0

Resources
4
 

This post is from MCU
 
Personal signature单价1元含税的USB和Touchkey单片机CH551G已大批量出货,试样QQ:1258305301
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list