Hi all,
Iam new to embedded systems and I have started to learn with TIVA c TM4C123 board.
I have created the below program but it doesn't work proberly. Hope you can show me where the error is.
This program shall take input from sw1 and sw2 on the board and show specific colour on RGB led connected to PF 1,2,3
What happens when I run the code is when no switches pressed led light is blue and when sw1 is pressed it shows sky blue and when sw1 is pressed nothing happens.
what it should do is show green light if no switches pressed and red light if sw1 is pressed and blue light if switch 2 is pressed.
Here is the code
============
/*************************
PORT F Addresses
*************************/
#define RCGCGPIO (*((volatile unsigned long*)0x400FE608)) //CLOCK
#define PORTFDATA (*((volatile unsigned long*)0x400253FC)) //DATA
#define PORTFDIR (*((volatile unsigned long*)0x40025400)) //DIRECTION
#define PORTFDEN (*((volatile unsigned long*)0x4002551C)) //ENABLE
#define PORTFLOCK (*((volatile unsigned long*)0x40025520)) //LOCK (lock or unlocks PF0)
#define PORTFCR (*((volatile unsigned long*)0x40025524)) //COMMIT (uncommit PF0)
#define PORTFPUR (*((volatile unsigned long*)0x40025510)) // PULL UP resistor
#define PORTFPDR (*((volatile unsigned long*)0x40025514)) // PULL Down resistor
/*************************/
int sw1;
int sw2;
int main (void)
{
RCGCGPIO |= 0x20; //Enable clock for PORT F
PORTFLOCK = 0x4C4F434B; // unlock commit reg
PORTFCR |= 0x01; // unlock PF0
PORTFDEN |= 0x1F; //Enable pins 0 to 4
PORTFDIR |= 0x0E; // pins 0 and 4 input - pins 1,2,3 output
PORTFPUR |= 0x01;
while (1)
{
sw2 = PORTFDATA & 0x00000001;
sw1 = PORTFDATA & 0x00000010;
if (sw1 == 1)
{PORTFDATA = PORTFDATA | 0x00000002;}
else if (sw2 == 1)
{PORTFDATA = PORTFDATA | 0x00000004;}
else
{PORTFDATA = PORTFDATA | 0x00000008;}
}
}
================
Thank you