我正在尝试生成与上升相对应的一系列二进制模式 微控制器的端口N anf F中使用四个LED的无符号整数。 LED模式应显示如下:
0x00:(LLLL) 0x01:(LLLH) 0x02:(LLHL) … 0x0F:(HHHH) 0x10:(LLLL) 0x11:(LLLH) ...
我似乎无法使用计数器在while循环中按此顺序使LED闪烁,我该如何工作?该微控制器是德州仪器(TM)的TM4C1294XL,并且程序使用c代码编写。
int main(void)
{
/**
* GPIO initialization
*/
SYSCTL_RCGCGPIO_R |= 0x00001020 ; // enable port N & F
while((SYSCTL_RCGCGPIO_R & 0x00001020) == 0); // wait until the port is available
GPIO_PORTN_DEN_R = 0x03; // PN(0,1) enable
GPIO_PORTN_DIR_R = 0x03; // PN(0,1) output
GPIO_PORTF_AHB_DEN_R = 0x11; // PF(0,4) enable
GPIO_PORTF_AHB_DIR_R = 0x11; // PF(0,4) output
/**
* TIMER initialization: compare mode
*/
SYSCTL_RCGCTIMER_R |= (1<<1);
while (!(SYSCTL_PRTIMER_R & (1<<1)) == 0);
TIMER1_CTL_R &= ~(1<<0); // stop timer
TIMER1_CFG_R = 0x4; // 16-bit
TIMER1_TAMR_R |= 0x12; // periodic, upwards counting
TIMER1_TAPR_R = 245-1; // prescalar value: timeout=1s, f(cpu)=16MHz
TIMER1_TAILR_R = 65307-1; // interval load value: timeout=1s, f(cpu)=16MHz
TIMER1_CTL_R |= (1<<0); // start timer
unsigned int counter = 0;
while(1)
{
counter++;
while (GPIO_PORTN_DATA_R & counter == 0);
GPIO_PORTN_DATA_R = counter;
while (GPIO_PORTF_AHB_DATA_R & counter == 0);
GPIO_PORTF_AHB_DATA_R = counter;
while((TIMER1_RIS_R & (1<<0))==0);
TIMER1_ICR_R |= (1<<0);
GPIO_PORTN_DATA_R = 0x00;
GPIO_PORTF_AHB_DATA_R = 0x00;
}
return 0;
}