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.