Commit 65fba1fc by Víctor Elexpe

First steps

parent ffba0b05
Showing with 24 additions and 8 deletions
......@@ -11,6 +11,7 @@
// ***** 1. Pre-processor Directives Section *****
#include "TExaS.h"
#include "tm4c123gh6pm.h"
#include <stdbool.h>
// ***** 2. Global Declarations Section *****
......@@ -24,17 +25,22 @@ void EnableInterrupts(void); // Enable interrupts
/*
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,
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
(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.
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.
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 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%).
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.
This means no adjacent elements in the array should be equal.
......@@ -65,7 +71,7 @@ void SysTick_Init(void){
}
unsigned long Led;
void Delay(void){unsigned long volatile time;
time = 160000; // 0.1sec
time = 80000; // 0.05 sec
while(time){
time--;
}
......@@ -75,16 +81,26 @@ unsigned long Time[50];
// you must leave the Data array defined exactly as it is
unsigned long Data[50];
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
PortF_Init(); // initialize PF1 to output
SysTick_Init(); // initialize SysTick, runs at 16 MHz
i = 0; // array index
changed = false;
last = NVIC_ST_CURRENT_R;
EnableInterrupts(); // enable interrupts for the grader
while(1){
Led = GPIO_PORTF_DATA_R; // read previous
Led = Led^0x02; // toggle red LED
GPIO_PORTF_DATA_R = Led; // output
if(!(GPIO_PORTF_DATA_R&0x01) || !(GPIO_PORTF_DATA_R&0x10)){ // PF0 or PF4
Led = GPIO_PORTF_DATA_R; // read previous
Led = Led^0x02; // toggle red LED
GPIO_PORTF_DATA_R = Led; // output
changed = true;
}
else {
//disable LED if nothing is pressed
GPIO_PORTF_DATA_R &=~0x02;
}
if(i<50){
now = NVIC_ST_CURRENT_R;
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