Professional Documents
Culture Documents
Practice
Lab Session 1
Exercise 3:Write a program for performing the following operations: ( control on board LED using on board Switch)
Switch (PF4) Sw1 Switch (PF0) Sw2 LEDs
1 1 R (0X02)
0 1 G (0X08)
1 0 B (0X04)
0 0 W (0X0E)
1.Header File
2.Port declaration
3.Delay
4.Main Program
#include "tm4c123gh6pm.h"
#include <stdint.h>
0010 0000
SYSCTL_RCGC2_R = 0x00000020; // 1) activate clock for Port F
0000 1110
13 Jan, 2021 21
GPIO Digital Enable (GPIODEN)
The GPIODEN register is the digital enable register
Enable the digital port (DEN)
1.Header File
2.Port declaration
3.Main Program
#include "tm4c123gh6pm.h"
#include <stdint.h>
unsigned long Switch;
1 1 R (0X02)
0 1 G (0X08)
1 0 B (0X04)
0 0 W (0X0E)
• #include "tm4c123gh6pm.h"
• #include <stdint.h>
• unsigned long Switch;
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 = 0x0E;
else
GPIO_PORTF_DATA_R = 0x00;
}
}
13 Jan, 2021 ESD Lab Session 1 37
1 1 --Red
1 1 NO (0X00)
0 1 Port D3 (0X08)
1 0 Port D0 (0X01)
0 0 Port D3 and D0
(0X09)
• #include "tm4c123gh6pm.h"
• #include <stdint.h>
• unsigned long SW;