STM32F103ZET6 development board to achieve Marquee experiment

Idle, bored!
Want to learn a chip, chip io port control is essential! Achieve stm32 (punctuality atom Elite Edition) complete the Marquee (led blinking cycle) test is the most basic control. We must understand the development board io port mode, then there are several pattern here?
I put them into input and output, this will be relatively easy to understand:
1: Output mode
(1) push-pull output: output a high intensity, low, can be connected to a digital device
(2) open-drain output: output can only be strong low, high intensity pulled external resistor
(3) Push-pull output multiplex: the on-chip peripheral functions, such as IIC
(. 4) with the open-drain output multiplex: the on-chip peripheral functions such as the MOSI, MISO and the like
explain multiplexing: io using this port is disposed at the second function, i.e., non-generic io mode
2: mode input
(1) input analog: analog input adc
pull-input (2): pull-up resistor input exists inside
(3) input dropdown: there is an input pull-down resistor internal
(4) floating input: KEY identification can be done, is determined by the high and low external input
Marquee experiment requires only a push-pull output of the above output mode, if you have configured to the foundation of the project, you can now start writing our own engineering it!
Looking for a good base configuration works can begin:
In the following foundation works to create a new folder HARDWARE

other name can, but to save their own projects peripherals project, and then enter into the keil5
Here Insert Picture Description
Manage Project Items inside HARDWARE add a new folder, such as 2 icon, and then create a new file named as led.c and led.h save just the new HAREWARE inside, step back on the map, stand-alone HAREWARE, click Add File ... , such as icons 3, HAREWARE found inside the .c file, add
Here Insert Picture Description
at this time the header file is missing, but we have just created, and how to add it?
Here Insert Picture Description
Find Options for targe 'template', if your project does not call template, single quotation marks is your own naming names, find the C / C ++ tab, click include paths,
Here Insert Picture Description
new construction, adding that contains the header files in directories on the line, click ok, so the basic framework like!
Some small partner to see inside led.c course there are a plus, but not their own,

Here Insert Picture Description
In-built led.c which added to the #include "led.h", compiled about the problem is solved.
We have to figure out the hardware connections:
Here Insert Picture Description
Here Insert Picture DescriptionHere Insert Picture Description
get a map, you want lights led, we should enter the low!
If the output is low, we can achieve a push-pull output lights may be provided to open-drain output may be outputted as a low level!
Here we start coding!
led.h:
#ifndef LED_H precompiled //
#define LED_H
#include "sys.h" system function //
void ledinit (void);
#endif
LED.c:
#include "led.h"
void ledinit (void)
{
GPIO_InitTypeDef GPIO_InitStructure; // gpio structure
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOE, the eNABLE); // enable clock
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; // mode selection
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // frequency selection
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; // port configuration
GPIO_Init (GPIOB, & GPIO_InitStructure); // port initialization
GPIO_SetBits (GPIOB, GPIO_Pin_5); // outputs a high
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init (GPIOE., & GPIO_InitStructure); // port initialization
GPIO_SetBits (GPIOE, GPIO_Pin_5); // Output High
}
main.c:
#include "sys.h"
#include "delay.h"
#include "led.h"
#define LED0 PBout (. 5)
#define LED1 Peout (. 5)
int main (void)
{
delay_init ();
ledinit ();
the while (. 1)
{
LED0 = 0;
LED1 =. 1;
Delay_ms (500); // delay 500ms
LED0 =. 1;
LED1 = 0;
Delay_ms (500);
}
}
if not understand where, can be found Origin!
Of course, in some places above it may not understand, can alone down in the understanding!
Thank you, nothing else, look Convicted spray!

Released two original articles · won praise 4 · Views 1186

Guess you like

Origin blog.csdn.net/weixin_42271802/article/details/104328122