i have got this code for interfacing of 2*2 keypad with tiva c but it is not working..........actually i wanted to see the output on putty using UART ...........
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
uint8_t k;
//function to detect which key is pressed
uint8_t key_detect()
{
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3, 0x08);
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)==0x00) return(0);
else if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0x00) return(1);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3, 0x04);
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)==0x00) return(2);
else if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0x00) return(3);
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)!=0x00 && GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)!=0x00)
return(6);
}
void key_function(uint8_t key)
{
switch(key)
{
case 0: SysCtlDelay(13333334);
UARTCharPut(UART0_BASE, '0');break;
case 1: SysCtlDelay(13333334);
UARTCharPut(UART0_BASE, '1');break;
case 2: SysCtlDelay(13333334);
UARTCharPut(UART0_BASE, '2');break;
case 3: SysCtlDelay(13333334);
UARTCharPut(UART0_BASE, '3');break;
//prints 6 when no key is pressed
case 6: SysCtlDelay(13333334);
UARTCharPut(UART0_BASE, '6');break;
}
}
int main(void)
{
// Tiva C LaunchPad System Initialisation //
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL| SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
//ENABLING PORTS
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//DEFINING THE PINS
//pins of PORT F are connected to the LEDs
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//pins of PORT D are connected to rows 1,2 of the keypad
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);
//pins of PORT E are connected to column 1,2 of the keypad
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_3);
// End of Tiva C LaunchPad System Initialisation //
// Wait 1 Millisecond after LCD Power Up //
SysCtlDelay(13333);
//making the rows 1,2 zero connected to PORTD
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3, 0x00);
SysCtlDelay(13333334);
//configuring UART
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
//defining the UART pins at PORTA 0,1
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 |GPIO_PIN_1);
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(),115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |UART_CONFIG_PAR_NONE));
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_3, 0x0c);
//To check whether the write operation has be done properly or not,if done properly blue LED glows
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0x08)
{
//blue LED glows
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3, 0x04);
}
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0x00)
{
//green LED glows
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3, 0x08);
}
SysCtlDelay(133333349);
// Loop for detecting key press and key function //
while(1)
{
//Reading the value of column 1 of keypad connected at PORTE
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)==0x00)
{
//glowing of LED
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3, 0x08);
SysCtlDelay(13333334);
k=key_detect();
key_function(k);
}
else if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0x00)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3, 0x02);
SysCtlDelay(13333334);
k=key_detect();
key_function(k);
}
//if no key is pressed
else if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)!=0x00 && GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)!=0x00)
{
SysCtlDelay(13333334);
k=key_detect();
key_function(k);
}
}
// End of loop for detecting key press and key function //
}
when i run this code blue LED is blinking showing that thePinWrite operation has been done correctly ,but on putty it is only diaplying 66666.....showing that no key is pressed even when i am pressing the key................