This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I'd like to apply blink code to my card. But there is a problem?

I use Texas Instrumens Tiva C Series TM4C123G LaunchPad. The LaunchPad has a TM4C123GH6PM 80Mhz 32-bit Arm Cortex M4.

        

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "tm4c123gh6pm.h"
#include <stdlib.h>
#include <stdint.h>
void delay(unsigned long sec);
int main(void){
SYSCTL_RCGCGPIO_R = 0x20; // Activate clock for Port F.
while((SYSCTL_PRGPIO_R & 0x20)==0 ) {} // wait until port ready.
GPIO_PORTF_LOCK_R = 0x4C4F434B; // Unlock GPIO Port F.
GPIO_PORTF_CR_R = 0x1F; // Allow changes to PF4-0.
GPIO_PORTF_AMSEL_R = 0x00; // Disable analog on Port F.
GPIO_PORTF_PCTL_R = 0x00000000; // PCTL GPIO on PF4-0.
GPIO_PORTF_DIR_R = 0x02; // Set PF3-1 output
GPIO_PORTF_DEN_R = 0x02; // Enable only PF1 (red)
GPIO_PORTF_DATA_R = 0; // Set RGB led to 0.(initial)
while (1) {
GPIO_PORTF_DATA_R = 0x02; // Turn on red led.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   

                                        My clock frequency is 80 Mhz.

Normally, the led lights up like that (picture on the left). But when I tried to apply blink code and add some delay between turn on and turn off code, the led lights up very very low power (picture on the right).

What is the problem of my code. Actually the code and the idea is very simple but I dont understand what is the problem.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "tm4c123gh6pm.h"
#include <stdlib.h>
#include <stdint.h>
void delay(unsigned long sec);
int main(void){
SYSCTL_RCGCGPIO_R = 0x20; // Activate clock for Port F.
while((SYSCTL_PRGPIO_R & 0x20)==0 ) {} // wait until port ready.
GPIO_PORTF_LOCK_R = 0x4C4F434B; // Unlock GPIO Port F.
GPIO_PORTF_CR_R = 0x1F; // Allow changes to PF4-0.
GPIO_PORTF_AMSEL_R = 0x00; // Disable analog on Port F.
GPIO_PORTF_PCTL_R = 0x00000000; // PCTL GPIO on PF4-0.
GPIO_PORTF_DIR_R = 0x02; // Set PF3-1 output
GPIO_PORTF_DEN_R = 0x02; // Enable only PF1 (red)
GPIO_PORTF_DATA_R = 0; // Set RGB led to 0.(initial)
while (1) {
GPIO_PORTF_DATA_R = 0x02; // Turn on red led.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

0