2017-10-21 152 views
0

正在使用的电路板是TM4C1294NCPDT,其想法是当按下开关1时,指示灯闪烁,然后亮起连续地(我理解那部分),并且在开关未被按下的时刻开始闪烁固定的数字,如果时间,让我们说5,那就是我的位置,当开关没有按下时,我看不到如何声明条件。[TM4C1294NCPDT]在按下开关的同时使LED指示灯持续闪烁(如果不使LED指示灯闪烁固定次数)

我做了一个流程图和代码。 enter image description here
该闪光灯1或2只是标签的指示,以打开和关闭 的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; 
    } 

} 
+1

移动的次数LED2是闪烁'COUNTER = 5'到* *内的 “按下” 循环。在LED2闪烁循环的* start *处检查计数器,所以在LED2闪烁5次之后,再次按下按钮之前不会发生任何事情。 –

回答

0
#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 
    } 

}