I got a problem again. i am trying to write a code for rgb led with 2 buttons the colors must get switch according to my switch press.....here is a code for default it is high so it is entering into both button high statement but when i press any switch i
#include <MKL25Z4.H>
volatile uint32_t msTicks;
void SysTick_Handler(void)
{
msTicks++; /* increment counter necessary in Delay() */
}
void Delay (uint32_t dlyTicks)
{
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks);
}
static void LED_Config(void)
{
SIM->SCGC5 |= (1 << 10) | (1 << 12); /* Enable Clock to Port B & D */
PORTB->PCR[18] = (1 << 8); /* Pin PTB18 is GPIO */
PORTB->PCR[19] = (1 << 8); /* Pin PTB19 is GPIO */
PORTB->PCR[0] = (1 << 8);
PORTB->PCR[1] = (1 << 8);
PORTD->PCR[1] = (1 << 8); /* Pin PTD1 is GPIO */
FPTB->PDDR|=(1 << 18|1 << 19);
//FPTB->PDDR|=(0 << 0 | 0 << 1);
FPTD->PDDR|=(1 << 1);
}
int main(void)
{
SystemCoreClockUpdate();
SysTick_Config(SystemCoreClock/1000);
LED_Config();
while(1)
{
if(FPTB->PDIR & (1 << 0) && FPTB->PDIR & (1 << 1) )
{
FPTB->PSOR = 1<< 18;
FPTB->PSOR = 1<<19;
FPTD->PSOR = 1<<1;
Delay(500);
}
if(FPTB->PDIR & (0 << 0) )//|| FPTB->PDIR & (1 << 1))
{
FPTB->PSOR = 1<<19;
FPTD->PSOR = 1<<1;
FPTB->PCOR = 1<<18;
Delay(500);
}
if(FPTB->PDIR & (0 << 1))// || FPTB->PDIR & (0 << 1))
{
FPTB->PSOR = 1<< 18;
FPTD->PSOR = 1<<1;
FPTB->PCOR = 1<<19;
Delay(500);
}
if(FPTB->PDIR & (0 << 0) && FPTB->PDIR & (0 << 1))
{
FPTB->PSOR = 1<< 18;
FPTB->PSOR = 1<<19;
FPTD->PCOR = 1<<1;
Delay(500);
}
}
}