Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
vielex
/
bes_labs_2019
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3ca637f2
authored
Mar 12, 2019
by
Víctor Elexpe
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.pld.ttu.ee:vielex/bes_labs_2019
parents
65fba1fc
f634a51d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
81 deletions
Labware/Lab8_SwitchLEDinterface/SwitchLEDInterface.c
Labware/Lab8_SwitchLEDinterface/SwitchLEDInterface.c
View file @
3ca637f2
// ***** 0. Documentation Section *****
// ***** 0. Documentation Section *****
// SwitchLEDInterface.c for Lab 8
// SwitchLEDInterface.c for Lab 8
// Runs on LM4F120/TM4C123
// Runs on LM4F120/TM4C123
// Use simple programming structures in C to toggle an LED
// Use simple programming structures in C to toggle an LED
// while a button is pressed and turn the LED on when the
// while a button is pressed and turn the LED on when the
// button is released. This lab requires external hardware
// button is released. This lab requires external hardware
// to be wired to the LaunchPad using the prototyping board.
// to be wired to the LaunchPad using the prototyping board.
// January 15, 2016
// January 15, 2016
// Jon Valvano and Ramesh Yerraballi
// Jon Valvano and Ramesh Yerraballi
// ***** 1. Pre-processor Directives Section *****
// ***** 1. Pre-processor Directives Section *****
#include "TExaS.h"
#include "TExaS.h"
#include "tm4c123gh6pm.h"
#include "tm4c123gh6pm.h"
#define GPIO_PORTE_DATA_R (*((volatile unsigned long *)0x400243FC))
// ***** 2. Global Declarations Section *****
#define GPIO_PORTE_DIR_R (*((volatile unsigned long *)0x40024400))
#define GPIO_PORTE_AFSEL_R (*((volatile unsigned long *)0x40024420))
// FUNCTION PROTOTYPES: Each subroutine defined
#define GPIO_PORTE_PUR_R (*((volatile unsigned long *)0x40024510))
void
DisableInterrupts
(
void
);
// Disable interrupts
#define GPIO_PORTE_DEN_R (*((volatile unsigned long *)0x4002451C))
void
EnableInterrupts
(
void
);
// Enable interrupts
#define GPIO_PORTE_LOCK_R (*((volatile unsigned long *)0x40024520))
void
PortE_Init
(
void
);
#define GPIO_PORTE_CR_R (*((volatile unsigned long *)0x40024524))
void
Delay100ms
(
unsigned
long
time
);
#define GPIO_PORTE_AMSEL_R (*((volatile unsigned long *)0x40024528))
#define GPIO_PORTE_PCTL_R (*((volatile unsigned long *)0x4002452C))
//unsigned long arm,sensor;
#define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))
//void delayms(unsigned long ms);
//void Delay(void);
// ***** 2. Global Declarations Section *****
//void EnableInterrupts(void);
unsigned
long
SW4
;
// ***** 3. Subroutines Section *****
unsigned
long
Out
;
// PE0, PB0, or PA2 connected to positive logic momentary switch using 10k ohm pull down resistor
// FUNCTION PROTOTYPES: Each subroutine defined
// PE1, PB1, or PA3 connected to positive logic LED through 470 ohm current limiting resistor
void
DisableInterrupts
(
void
);
// Disable interrupts
// To avoid damaging your hardware, ensure that your circuits match the schematic
void
EnableInterrupts
(
void
);
// Enable interrupts
// shown in Lab8_artist.sch (PCB Artist schematic file) or
void
PortE_init
(
void
);
// Init port PE0 PE1
// Lab8_artist.pdf (compatible with many various readers like Adobe Acrobat).
void
Delay1ms
(
unsigned
long
msec
);
unsigned
long
In
;
// input from PF4
// ***** 3. Subroutines Section *****
unsigned
long
Out
;
// output to PF2 (blue LED)
// PE0, PB0, or PA2 connected to positive logic momentary switch using 10k ohm pull down resistor
unsigned
long
SW
;
// PE1, PB1, or PA3 connected to positive logic LED through 470 ohm current limiting resistor
int
main
(
void
){
// To avoid damaging your hardware, ensure that your circuits match the schematic
//**********************************************************************
// shown in Lab8_artist.sch (PCB Artist schematic file) or
// The following version tests input on PE0 and output on PE1
// Lab8_artist.pdf (compatible with many various readers like Adobe Acrobat).
//**********************************************************************
int
main
(
void
)
{
TExaS_Init
(
SW_PIN_PE0
,
LED_PIN_PE1
,
ScopeOn
);
// activate grader and set system clock to 80 MHz
//**********************************************************************
// The following version tests input on PE0 and output on PE1
PortE_Init
();
// make PF3-1 out (PF3-1 built-in LEDs)
//**********************************************************************
TExaS_Init
(
SW_PIN_PE0
,
LED_PIN_PE1
,
ScopeOn
);
// activate grader and set system clock to 80 MHz
while
(
1
){
PortE_init
();
EnableInterrupts
();
// enable interrupts for the grader
Delay100ms
(
1
);
while
(
1
){
SW
=
GPIO_PORTE_DATA_R
&
0x01
;
// read PE0 into the switch
SW4
=
GPIO_PORTE_DATA_R
&
0x00
;
if
(
SW
==
1
){
if
(
SW4
)
{
GPIO_PORTE_DATA_R
^=
0x02
;
// Toggle PE1
GPIO_PORTE_DATA_R
=
0x02
;
}
else
{
}
GPIO_PORTE_DATA_R
|=
0x02
;
// Set PE1, LED On
Delay1ms
(
100
);
}
}
}
}
void
PortE_init
()
{
volatile
unsigned
long
delay
;
}
SYSCTL_RCGC2_R
|=
0x00000010
;
// 1) F clock
delay
=
SYSCTL_RCGC2_R
;
// delay to allow clock to stabilize
void
PortE_Init
(
void
){
volatile
unsigned
long
delay
;
GPIO_PORTE_AMSEL_R
&=
0x00
;
// 2) disable analog function
SYSCTL_RCGC2_R
|=
0x00000010
;
// 1) activate clock for Port E
GPIO_PORTE_PCTL_R
&=
0x00000000
;
// 3) GPIO clear bit PCTL
delay
=
SYSCTL_RCGC2_R
;
// allow time for clock to start
GPIO_PORTE_DIR_R
&=
~
0x00
;
// 4.1) PF0 input,
GPIO_PORTE_AMSEL_R
=
0x00
;
// 3) disable analog on PF
GPIO_PORTE_DIR_R
|=
0x01
;
// 4.2) PF1 output
GPIO_PORTE_PCTL_R
=
0x00000000
;
// 4) PCTL GPIO on PF4-0
GPIO_PORTE_AFSEL_R
&=
0x00
;
// 5) no alternate function
GPIO_PORTE_DIR_R
=
0x02
;
// 5) PE1 OUTPUT, PE0 INPUT -- 0000 0010
GPIO_PORTE_PUR_R
|=
0x10
;
// 6) enable pullup resistor on PF4
GPIO_PORTE_AFSEL_R
=
0x00
;
// 6) disable alt funct on PF7-0 no alternate function
GPIO_PORTE_DEN_R
|=
0x11
;
// 7) enable digital pins PF1-PF0
GPIO_PORTE_DEN_R
=
0x03
;
// 7) enable digital I/O on PF4-0
}
GPIO_PORTE_DATA_R
|=
0x02
;
// Initialize led ON
void
Delay1ms
(
unsigned
long
msec
)
{
}
unsigned
long
count
;
while
(
msec
>
0
)
{
void
Delay100ms
(
unsigned
long
time
){
count
=
1600
;
unsigned
long
i
;
while
(
count
>
0
)
{
while
(
time
>
0
){
count
--
;
i
=
1333333
;
// 100ms
}
while
(
i
>
0
){
ms
--
;
i
=
i
-
1
;
}
}
}
time
=
time
-
1
;
// decrements every 100 ms
\ No newline at end of file
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment