[TM4C1294NCPDT]如果不使LED闪烁固定次数,则在按住开关的同时使LED连续闪烁 [英] [TM4C1294NCPDT ]make the led blink continuously while pressing a switch if not make the led blink a fixed number of times
本文介绍了[TM4C1294NCPDT]如果不使LED闪烁固定次数,则在按住开关的同时使LED连续闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正在使用的板卡是TM4C1294NCPDT,其想法是在按下开关1时,LED会不断闪烁并不断闪烁(我理解这部分),并且在未按下开关的情况下,如果出现以下情况,它会开始闪烁固定数字:时间,让我说5,那是我所在的地方,当不按下开关时,我看不到如何陈述条件.
The board in use is the TM4C1294NCPDT, the idea is that while the switch 1 is pressed the led blinks off and on continuously ( I understand that part) and in the moment the switch is not pressed begin to blink a fixed number if times,lets say 5, that's where I'm and I do not see how to state the condition when the switch its not pressed.
我做了一个流程图和代码.
闪光灯1或2只是打开和关闭说明的标签
领导.
I did a flow chart and the code.
The flash led 1 or 2 are only tags to the instructions to turn on and off
the led.
#include <stdbool.h>
#include <stdint.h>
#include "inc/tm4c1294ncpdt.h"
uint32_t i; //int 1
int main(void) {
SYSCTL_RCGCGPIO_R=0X1100; // set clock portn
i=SYSCTL_RCGCGPIO_R; // delay (more than 3 cycles)
GPIO_PORTN_DIR_R=0X03; //enable the GPIO pin for the LED-PN0, set the direction as output, and
GPIO_PORTN_DEN_R=0X03; //enable the GPIO pin for digital function
GPIO_PORTJ_AHB_DIR_R=0;
GPIO_PORTJ_AHB_DEN_R=0X03;
GPIO_PORTJ_AHB_PUR_R=0X01;
while(1){
GPIO_PORTN_DATA_R &=~0X02; //turn led off
while (GPIO_PORTJ_AHB_DATA_R & 0X01){
GPIO_PORTN_DATA_R |=0X01; //turn led on
SysCtlDelay(2666666);
GPIO_PORTN_DATA_R &=~0X01; //turn led off again
SysCtlDelay(2666666);
}
GPIO_PORTN_DATA_R |=0X02;
}
}
推荐答案
#include <stdbool.h>
#include <stdint.h>
#include "inc/tm4c1294ncpdt.h"
uint32_t i,j; //int 1
int main(void) {
SYSCTL_RCGCGPIO_R=0X1100; // set clock portn
i=SYSCTL_RCGCGPIO_R; // delay (more than 3 cycles)
j=0;
GPIO_PORTN_DIR_R=0X03; //enable the GPIO pin for the LED-PN0, set the direction as output, and
GPIO_PORTN_DEN_R=0X03; //enable the GPIO pin for digital function
GPIO_PORTJ_AHB_DIR_R=0;
GPIO_PORTJ_AHB_DEN_R=0X03;
GPIO_PORTJ_AHB_PUR_R=0X01;
while(1){
GPIO_PORTN_DATA_R &=~0X02; //turn led off
while (GPIO_PORTJ_AHB_DATA_R & 0X01){
GPIO_PORTN_DATA_R |=0X01; //turn led on
SysCtlDelay(2666666);
GPIO_PORTN_DATA_R &=~0X01; //turn led off again
SysCtlDelay(2666666);
}
for (j=0; i<5; i++)
{
GPIO_PORTN_DATA_R |=0X01; //turn led on
SysCtlDelay(2666666);
GPIO_PORTN_DATA_R &=~0X01; //turn led off again
SysCtlDelay(2666666)
}
GPIO_PORTN_DATA_R |=0X02; //clear the interrupt flag before return
}
}
这篇关于[TM4C1294NCPDT]如果不使LED闪烁固定次数,则在按住开关的同时使LED连续闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文