This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LM4F232 coding help

hey i working on project . if i press a button, user led should on and again if i pss the same button the led should turn off . so i have written some code so can u please check and guide me how can i do that. becoz i am new to this programming.


#include<stdio.h>
#include "lm4f232h5qd.h"

int main(void)
{

int i = 0;


////////// port G initialisation for user LED /////////////

GPIO_PORTG_DIR_R = GPIO_PORTG_DIR_R | 0x04;

// SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

GPIO_PORTG_DATA_R |= 0x04;

GPIO_PORTG_AFSEL_R &= 0x00;

GPIO_PORTG_DEN_R |= 0x04;

//////////// port M inititalisation for UP button ///////////


GPIO_PORTM_DIR_R = GPIO_PORTM_DIR_R & 0x00;

GPIO_PORTM_DATA_R |= 0x01;

GPIO_PORTM_AFSEL_R &= 0x00;

GPIO_PORTM_DEN_R |= 0x01;

//////////////////////////////////////////////////////////////////////////////////


while(1)
{

if( (GPIO_PORTM_DATA_R &= 0x01) == 0)
{
GPIO_PORTG_DATA_R |= 0x04; // Set the pin HIGH using OR operation .


for(i=0;i<1000;i++)
{

}


if( (GPIO_PORTM_DATA_R &= 0x01) == 0)
{
GPIO_PORTG_DATA_R &= ~(0x04); // Set the pin LOW using AND operation .

}

}

}

}

i am using IAR test bench.

please guide me how to initialise system clock and crysal frequency.

  • Hello Somashekar,

    I would ask you to refer the example code in TIVWare for LM4F232 devices.

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\ek-lm4f232\uart_echo

    You would want to look at the API ROM_SysCtlClockSet to initialize the System Clock and Crystal Frequency.

    Secondly, an important thing we advocate is the use of API's rather than register access macro's so that a certain level of comfort-ability is built using the device. There is no harm in using register macro but already looking at the code post, I see mistakes that can be easily avoided.

    Regards

    Amit