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
f634a51d
authored
Mar 05, 2019
by
vielex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code working
parent
ffba0b05
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
39 deletions
Labware/Lab8_SwitchLEDinterface/SwitchLEDInterface.c
Labware/Lab8_SwitchLEDinterface/SwitchLEDInterface.c
View file @
f634a51d
...
@@ -12,27 +12,18 @@
...
@@ -12,27 +12,18 @@
#include "TExaS.h"
#include "TExaS.h"
#include "tm4c123gh6pm.h"
#include "tm4c123gh6pm.h"
#define GPIO_PORTE_DATA_R (*((volatile unsigned long *)0x400243FC))
#define GPIO_PORTE_DIR_R (*((volatile unsigned long *)0x40024400))
#define GPIO_PORTE_AFSEL_R (*((volatile unsigned long *)0x40024420))
#define GPIO_PORTE_PUR_R (*((volatile unsigned long *)0x40024510))
#define GPIO_PORTE_DEN_R (*((volatile unsigned long *)0x4002451C))
#define GPIO_PORTE_LOCK_R (*((volatile unsigned long *)0x40024520))
#define GPIO_PORTE_CR_R (*((volatile unsigned long *)0x40024524))
#define GPIO_PORTE_AMSEL_R (*((volatile unsigned long *)0x40024528))
#define GPIO_PORTE_PCTL_R (*((volatile unsigned long *)0x4002452C))
#define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))
// ***** 2. Global Declarations Section *****
// ***** 2. Global Declarations Section *****
unsigned
long
SW4
;
unsigned
long
Out
;
// FUNCTION PROTOTYPES: Each subroutine defined
// FUNCTION PROTOTYPES: Each subroutine defined
void
DisableInterrupts
(
void
);
// Disable interrupts
void
DisableInterrupts
(
void
);
// Disable interrupts
void
EnableInterrupts
(
void
);
// Enable interrupts
void
EnableInterrupts
(
void
);
// Enable interrupts
void
PortE_
init
(
void
);
// Init port PE0 PE1
void
PortE_
Init
(
void
);
void
Delay1
ms
(
unsigned
long
msec
);
void
Delay1
00ms
(
unsigned
long
time
);
//unsigned long arm,sensor;
//void delayms(unsigned long ms);
//void Delay(void);
//void EnableInterrupts(void);
// ***** 3. Subroutines Section *****
// ***** 3. Subroutines Section *****
// PE0, PB0, or PA2 connected to positive logic momentary switch using 10k ohm pull down resistor
// PE0, PB0, or PA2 connected to positive logic momentary switch using 10k ohm pull down resistor
...
@@ -40,41 +31,52 @@ void Delay1ms(unsigned long msec);
...
@@ -40,41 +31,52 @@ void Delay1ms(unsigned long msec);
// To avoid damaging your hardware, ensure that your circuits match the schematic
// To avoid damaging your hardware, ensure that your circuits match the schematic
// shown in Lab8_artist.sch (PCB Artist schematic file) or
// shown in Lab8_artist.sch (PCB Artist schematic file) or
// Lab8_artist.pdf (compatible with many various readers like Adobe Acrobat).
// Lab8_artist.pdf (compatible with many various readers like Adobe Acrobat).
int
main
(
void
)
{
unsigned
long
In
;
// input from PF4
unsigned
long
Out
;
// output to PF2 (blue LED)
unsigned
long
SW
;
int
main
(
void
){
//**********************************************************************
//**********************************************************************
// The following version tests input on PE0 and output on PE1
// The following version tests input on PE0 and output on PE1
//**********************************************************************
//**********************************************************************
TExaS_Init
(
SW_PIN_PE0
,
LED_PIN_PE1
,
ScopeOn
);
// activate grader and set system clock to 80 MHz
TExaS_Init
(
SW_PIN_PE0
,
LED_PIN_PE1
,
ScopeOn
);
// activate grader and set system clock to 80 MHz
PortE_init
();
EnableInterrupts
();
// enable interrupts for the grader
PortE_Init
();
// make PF3-1 out (PF3-1 built-in LEDs)
while
(
1
){
while
(
1
){
SW4
=
GPIO_PORTE_DATA_R
&
0x00
;
if
(
SW4
)
{
Delay100ms
(
1
);
GPIO_PORTE_DATA_R
=
0x02
;
SW
=
GPIO_PORTE_DATA_R
&
0x01
;
// read PE0 into the switch
if
(
SW
==
1
){
GPIO_PORTE_DATA_R
^=
0x02
;
// Toggle PE1
}
else
{
GPIO_PORTE_DATA_R
|=
0x02
;
// Set PE1, LED On
}
}
Delay1ms
(
100
);
}
}
}
}
void
PortE_
init
()
{
volatile
unsigned
long
delay
;
void
PortE_
Init
(
void
){
volatile
unsigned
long
delay
;
SYSCTL_RCGC2_R
|=
0x00000010
;
// 1) F clock
SYSCTL_RCGC2_R
|=
0x00000010
;
// 1) activate clock for Port E
delay
=
SYSCTL_RCGC2_R
;
// delay to allow clock to stabilize
delay
=
SYSCTL_RCGC2_R
;
// allow time for clock to start
GPIO_PORTE_AMSEL_R
&=
0x00
;
// 2) disable analog function
GPIO_PORTE_AMSEL_R
=
0x00
;
// 3) disable analog on PF
GPIO_PORTE_PCTL_R
&=
0x00000000
;
// 3) GPIO clear bit PCTL
GPIO_PORTE_PCTL_R
=
0x00000000
;
// 4) PCTL GPIO on PF4-0
GPIO_PORTE_DIR_R
&=
~
0x00
;
// 4.1) PF0 input,
GPIO_PORTE_DIR_R
=
0x02
;
// 5) PE1 OUTPUT, PE0 INPUT -- 0000 0010
GPIO_PORTE_
DIR_R
|=
0x01
;
// 4.2) PF1 output
GPIO_PORTE_
AFSEL_R
=
0x00
;
// 6) disable alt funct on PF7-0 no alternate function
GPIO_PORTE_
AFSEL_R
&=
0x00
;
// 5) no alternate function
GPIO_PORTE_
DEN_R
=
0x03
;
// 7) enable digital I/O on PF4-0
GPIO_PORTE_PUR_R
|=
0x10
;
// 6) enable pullup resistor on PF4
GPIO_PORTE_DATA_R
|=
0x02
;
// Initialize led ON
GPIO_PORTE_DEN_R
|=
0x11
;
// 7) enable digital pins PF1-PF0
}
}
void
Delay1
ms
(
unsigned
long
msec
)
{
void
Delay1
00ms
(
unsigned
long
time
){
unsigned
long
count
;
unsigned
long
i
;
while
(
msec
>
0
)
{
while
(
time
>
0
){
count
=
1600
;
i
=
1333333
;
// 100ms
while
(
count
>
0
)
{
while
(
i
>
0
){
count
--
;
i
=
i
-
1
;
}
}
ms
--
;
time
=
time
-
1
;
// decrements every 100 ms
}
}
}
}
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