|
1: Experiment name Four-digit running lamp
2: Experimental contentRealize the cycle of flashing the four-position running lamp
3. Purpose of the experiment1: Master the LED hardwarecircuit 2: Master the register configuration method of KL25 GPIO module output 3: Master the programming method of four-digit running light cycle flashing
4. Experimental methods 1: Consult the circuit diagram of that section It was found that the PTB8, PTB9, PTB10, and PTB11 pins of KL25 control the four LED light-emitting diodes D6, D7, D8, and D9 respectively. file:///C:\Users\AA\AppData\Local\Temp\ksohtml\wps_clip_image-3968.png 2: Configure the corresponding registers of the GPIO module (1) Refer to page 122 of the KL25 Reference Manual and find that the GPIO is provided by the platform clock.
(2) Connect the Platform clock clock and the POTRB module, and program it as follows: SIM_SCGC5=SIM_SCGC5_PORTB_MASK; SIM_SCGC5 registers can be consulted
(3) Set the multiplexing pin attributes, configure PTB8, PTB9, PTB10, and PTB11 as GPIO functions, and program them as follows: PORTB_PCR8=PORT_PCR_MUX(1); PORTB_PCR9=PORT_PCR_MUX(1); PORTB_PCR10=PORT_PCR_MUX(1); PORTB_PCR11=PORT_PCR_MUX(1); Refer to the PORTx_PCRn register and page 46 of the KL25 Data Sheet for more information
(4) Set the input and output direction of the pins, set PTB8, PTB9, PTB10, and PTB11 to output, and program them as follows: GPIOB_PDDR=GPIO_PDDR_PDD(0x00000f00u); GPIOx_PDDR registers can be consulted
(5) Set the output logic level of the pin, set the output high level of PTB8, PTB9, PTB10, PTB11, and program it as follows: GPIOB_PDOR=GPIO_PDOR_PDO(0x00000f00u); Consult GPIOx_PDOR registers
3: Realize the cycle flashing of the four-position running lamp [mw_shl_code=c,true]Consult the corresponding program in the main function of the routine/* *********************************************************** * file name : main.c * function : function for main * *********************************************************** */
#include "derivative.h" #include "config.h" #include "crg.h" #include "gpio.h"
/******************************主函数*************************************/ int main(void)
{ asm(" CPSID i"); The general interruption of the pass
crg_default_init(); System default clock //crg_configuration_init(); Clock after configuration MCGIRCLK_outenable(); Enables MCGIRCL output 2M clock_test(4); Tests of the corresponding clocks
gpio_init(); GPIO initialization
asm(" CPSIE i"); Open the total interruption
for(;; ) { GPIOB_PDOR=GPIO_PDOR_PDO(0x00000100u); PTB8 output high level, D6LED light on delayms(15000); Delay GPIOB_PDOR=GPIO_PDOR_PDO(0x00000200u); PTB9 output high level, D7LED light on delayms(15000); Delay GPIOB_PDOR=GPIO_PDOR_PDO(0x00000400u); PTB10 output high level, D8LED light on delayms(15000); Delay GPIOB_PDOR=GPIO_PDOR_PDO(0x00000800u); PTB11 output high level, D9LED light on delayms(15000); Delay }
}[/mw_shl_code]
|