This is the program I'm trying to run. It's actually a program for a running light but for GPIOB's LED which is connected for the first LED just stayed on all the time, while the other 3 LED which is at GPIOA is is a running light sequence.
#include "stm32f4xx.h"void delayMs(int n);
int main(){ RCC -> AHB1ENR |= 3; GPIOA -> MODER &= ~0x0000FC00; GPIOA -> MODER |= 0x00005400; GPIOB -> MODER &= ~0x00003000; GPIOB -> MODER |= 0x00001000;
while(1){ GPIOB->BSRR |= 0x004000A0; delayMs(500); GPIOA->BSRR |= 0x00800060; delayMs(500); GPIOA->BSRR |= 0x004000A0; delayMs(500); GPIOA->BSRR |= 0x002000C0; delayMs(500); }}
void delayMs (int n){ int i; for(; n>0; n--) for(i=0; i<3000; i++);}
Can someone help me?
while(1){GPIOB->BSRR = 0x00000040; // PB6 ONdelayMs(500);GPIOB->BSRR = 0x00400000; // PB6 OFFdelayMs(500);GPIOA->BSRR = 0x00800060;// PA7 OFF, PA5,PA6 ONdelayMs(500);GPIOA->BSRR = 0x004000A0;delayMs(500);GPIOA->BSRR = 0x002000C0;delayMs(500);}
Yes, this is a little more succulent than what I wrote. And only use the BSRR to modify the ODR.
Oh I see, the coding for the LED for PB6 and LED for PA6 interfered with each other. I have tried your code and run it, and yeah, it works but after the execution of the PB6 OFF codes, the LED turns back on. Since I wanted the LED to turn off, so I copied the coding for PB6 ON after that which fixed the problem.
while(1){GPIOB->BSRR = 0x00000040; // PB6 ON (LED OFF)delayMs(500);GPIOB->BSRR = 0x00400000; // PB6 OFF (LED ON)delayMs(500);GPIOB->BSRR = 0x00000040; // PB6 ON (LED OFF)delayMs(500);GPIOA->BSRR = 0x00800060;// PA7 OFF, PA5,PA6 ONdelayMs(500);GPIOA->BSRR = 0x004000A0;delayMs(500);GPIOA->BSRR = 0x002000C0;delayMs(500);}
Thank you so much. I really appreciated the help you guys have given me. =D