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.

        

#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.
			delay(1);																// Wait 1 sec.
			
  		GPIO_PORTF_DATA_R = 0x00;								//	Turn off red led.
			delay(1);																//	Wait 1 sec.
		}
}
void delay(unsigned long sec){
	
unsigned long c,d;
	for(c=1; c<=sec; c++)
		for(d=0; d<400000; d++) {} 							// I dont ensure this number but
}																							// I tried many many number from 40.000 to 40.000.000
																						  // none of them worked.
																							
   

                                        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.

#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.
			delay(1);							// Wait 1 sec.
		
  		GPIO_PORTF_DATA_R = 0x00;				//	Turn off red led.
			delay(1);							//	Wait 1 sec.
		}
}
void delay(unsigned long sec){
	
unsigned long c,d;
	for(c=1; c<=sec; c++)
		for(d=0; d<400000; d++) {} 				// I dont ensure this number but
}								     			// I tried many many number from 40.000 to 40.000.000
								    			// none of them worked.

Parents
  • It's always a good idea to tidy up before posting to forums

    I definitely agree with you but I've tidied my code up before posting but when I share my question, my code is  messed up. I dont know why this is happened. 

    By the way, thank you vey much your response. I will try to do what you said.

Reply
  • It's always a good idea to tidy up before posting to forums

    I definitely agree with you but I've tidied my code up before posting but when I share my question, my code is  messed up. I dont know why this is happened. 

    By the way, thank you vey much your response. I will try to do what you said.

Children