EMS lab1[1]
EMS lab1[1]
HARINI MANDALAM(EC23I2012)
13/01/2025
THEORY :
GPIO MODULE :
The GPIO namely, General-Purpose Input Output module gives the access of outside world to the
processor and vice versa. Be it sensors or actuators or switches are connected to the processor through
this module.
In TIVA TM4C123GH6PM Launch Pad there are 43 programmable input/output pins divided into 6 ports.
The Port F is special as it has an onboard LED connected and two onboard switches connected in
negative logic.
SWITCH INTERFACE :
When a normally open (NO) switch with infinite resistance is closed, its resistance is about 0.1 ohms.
This register controls the clock gating logic in normal Run mode. Each bit controls a clock enable for a
given interface, function, or module. If set, the module receives a clock and functions.
Otherwise, the module is unclocked and disabled.
1
// Color LED(s) PortF
// dark --- 0
2
1.TOGGLE ONBOARD LED :
CODE:
#include "tm4c123gh6pm.h”
#include <stdint.h>
3
time--;
int main(void){
PortF_Init(); // make PF1 out (PF1 built-in LED) while(1){
GPIO_PORTF_DATA_R ^= 0x02;
Delay();
}}
OUTPUT:
RESULT :
A LED and switch was created. The Waveform was observed in bit form and the LED was made to toggle.
4
2.INTERFACE SW1 AND CONTROL LED :
Reading Rainbow Tip: Find an image online that resembles the setting of this story, then replace the
image above.
CODE:
// only PF0 and PF3 needs to be unlocked, other bits can't be locked
int main(void)
5
{
PortF_Init();
while(1)
Switch=GPIO_PORTF_DATA_R&0x11;
if(Switch==0x01)
GPIO_PORTF_DATA_R = 0x00;
OUTPUT:
6
RESULT :
7
3. LED G,B,R :
OBJECTIVE :To control on board LED switches to perform the following actions.
CODE :
// only PF0 and PF3 needs to be unlocked, other bits can't be locked
8
int main(void)
PortF_Init();
while(1)
Switch=GPIO_PORTF_DATA_R&0x11;
if(Switch==0x11)
GPIO_PORTF_DATA_R = 0x02;
else if (Switch==0x01)
GPIO_PORTF_DATA_R = 0x08;
else if (Switch==0x10)
GPIO_PORTF_DATA_R = 0x04;
else if (Switch==0x00)
GPIO_PORTF_DATA_R = 0x00;
9
OUTPUT :
10
When switch 1 is off and switch 2 is on YELLOW LED GLOWS :
11
RESULT :
When the onboard LED switches have been controlled to observe the required colors.
CODE :
12
SYSCTL_RCGC2_R |= 0x00000008; // 1) activate clock for Port D
PortD_Init();
while(1) {
SW =GPIO_PORTF_DATA_R&0x11;
if(SW==0x11)
GPIO_PORTD_DATA_R = 0x00;
else if (SW==0x01)
GPIO_PORTD_DATA_R = 0x08;
else if (SW==0x10)
(SW==0x00)
GPIO_PORTD_DATA_R = 0x09;
else
GPIO_PORTD_DATA_R = 0x00;
}}
13
OUTPUT :
When both the switches are turned off:
RESULT :
14