Commit 65fba1fc by Víctor Elexpe

First steps

parent ffba0b05
Showing with 18 additions and 2 deletions
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
// ***** 1. Pre-processor Directives Section ***** // ***** 1. Pre-processor Directives Section *****
#include "TExaS.h" #include "TExaS.h"
#include "tm4c123gh6pm.h" #include "tm4c123gh6pm.h"
#include <stdbool.h>
// ***** 2. Global Declarations Section ***** // ***** 2. Global Declarations Section *****
...@@ -25,16 +26,21 @@ void EnableInterrupts(void); // Enable interrupts ...@@ -25,16 +26,21 @@ void EnableInterrupts(void); // Enable interrupts
/* /*
This Lab9 starter project is the same as C9_Debugging example but This Lab9 starter project is the same as C9_Debugging example but
includes the connections to the Lab9 grader. You will make three changes. includes the connections to the Lab9 grader. You will make three changes.
First, make the LED flash at 10 Hz. In other words, make it turn on for 0.05 seconds, First, make the LED flash at 10 Hz. In other words, make it turn on for 0.05 seconds,
and then turn off for 0.05 seconds. and then turn off for 0.05 seconds.
Second, make the LED flash if either switch SW1 or SW2 is pressed Second, make the LED flash if either switch SW1 or SW2 is pressed
(this means flash the LED if either PF4 or PF0 is 0). (this means flash the LED if either PF4 or PF0 is 0).
Third, record PortF bits 4,1,0 every time the input changes or the output changes. Third, record PortF bits 4,1,0 every time the input changes or the output changes.
For example, if your system detects a change in either PF4 or PF0 input, For example, if your system detects a change in either PF4 or PF0 input,
record PortF bits 4,1,0. If your system causes a change in PF1, record PortF bits 4,1,0. record PortF bits 4,1,0. If your system causes a change in PF1, record PortF bits 4,1,0.
If both PF4 and PF0 switch are not pressed, the PF1 output should be low. If both PF4 and PF0 switch are not pressed, the PF1 output should be low.
If either PF4 or PF0 switches is pressed, the output toggles at 10 Hz (±10%).
If either PF4 or PF0 switches is pressed, the output toggles at 10 Hz (�10%).
Information collected in the Data array matches the I/O on PortF. Information collected in the Data array matches the I/O on PortF.
50 data points are collected only on a change in input or a change in output. 50 data points are collected only on a change in input or a change in output.
This means no adjacent elements in the array should be equal. This means no adjacent elements in the array should be equal.
...@@ -65,7 +71,7 @@ void SysTick_Init(void){ ...@@ -65,7 +71,7 @@ void SysTick_Init(void){
} }
unsigned long Led; unsigned long Led;
void Delay(void){unsigned long volatile time; void Delay(void){unsigned long volatile time;
time = 160000; // 0.1sec time = 80000; // 0.05 sec
while(time){ while(time){
time--; time--;
} }
...@@ -75,16 +81,26 @@ unsigned long Time[50]; ...@@ -75,16 +81,26 @@ unsigned long Time[50];
// you must leave the Data array defined exactly as it is // you must leave the Data array defined exactly as it is
unsigned long Data[50]; unsigned long Data[50];
int main(void){ unsigned long i,last,now; int main(void){ unsigned long i,last,now;
bool changed;
TExaS_Init(SW_PIN_PF40, LED_PIN_PF1); // activate grader and set system clock to 16 MHz TExaS_Init(SW_PIN_PF40, LED_PIN_PF1); // activate grader and set system clock to 16 MHz
PortF_Init(); // initialize PF1 to output PortF_Init(); // initialize PF1 to output
SysTick_Init(); // initialize SysTick, runs at 16 MHz SysTick_Init(); // initialize SysTick, runs at 16 MHz
i = 0; // array index i = 0; // array index
changed = false;
last = NVIC_ST_CURRENT_R; last = NVIC_ST_CURRENT_R;
EnableInterrupts(); // enable interrupts for the grader EnableInterrupts(); // enable interrupts for the grader
while(1){ while(1){
if(!(GPIO_PORTF_DATA_R&0x01) || !(GPIO_PORTF_DATA_R&0x10)){ // PF0 or PF4
Led = GPIO_PORTF_DATA_R; // read previous Led = GPIO_PORTF_DATA_R; // read previous
Led = Led^0x02; // toggle red LED Led = Led^0x02; // toggle red LED
GPIO_PORTF_DATA_R = Led; // output GPIO_PORTF_DATA_R = Led; // output
changed = true;
}
else {
//disable LED if nothing is pressed
GPIO_PORTF_DATA_R &=~0x02;
}
if(i<50){ if(i<50){
now = NVIC_ST_CURRENT_R; now = NVIC_ST_CURRENT_R;
Time[i] = (last-now)&0x00FFFFFF; // 24-bit time difference Time[i] = (last-now)&0x00FFFFFF; // 24-bit time difference
......
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