Commit ffba0b05 by Víctor Elexpe

Possible solution

parent 1b6e15b4
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// 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
...@@ -12,11 +12,26 @@ ...@@ -12,11 +12,26 @@
#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 Delay1ms(unsigned long msec);
// ***** 3. Subroutines Section ***** // ***** 3. Subroutines Section *****
...@@ -25,16 +40,41 @@ void EnableInterrupts(void); // Enable interrupts ...@@ -25,16 +40,41 @@ void EnableInterrupts(void); // Enable interrupts
// 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){ 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 EnableInterrupts(); // enable interrupts for the grader
while(1){ while(1){
SW4 = GPIO_PORTE_DATA_R&0x00;
if (SW4) {
GPIO_PORTE_DATA_R = 0x02;
}
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
GPIO_PORTE_AMSEL_R &= 0x00; // 2) disable analog function
GPIO_PORTE_PCTL_R &= 0x00000000; // 3) GPIO clear bit PCTL
GPIO_PORTE_DIR_R &= ~0x00; // 4.1) PF0 input,
GPIO_PORTE_DIR_R |= 0x01; // 4.2) PF1 output
GPIO_PORTE_AFSEL_R &= 0x00; // 5) no alternate function
GPIO_PORTE_PUR_R |= 0x10; // 6) enable pullup resistor on PF4
GPIO_PORTE_DEN_R |= 0x11; // 7) enable digital pins PF1-PF0
}
void Delay1ms(unsigned long msec) {
unsigned long count;
while(msec > 0) {
count = 1600;
while(count > 0) {
count--;
}
ms--;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment