Question: Please help me to explain the code line by line. This is C language. Thanks a lot. I appreciate it. // 0.Documentation Section // Lab7_HeartBlock,

Please help me to explain the code line by line. This is C language. Thanks a lot. I appreciate it.

// 0.Documentation Section // Lab7_HeartBlock, main.c

// Runs on LM4F120 or TM4C123 LaunchPad // Input from PF4(SW1) is AS (atrial sensor), // Output to PF3, Green LED, is Ready, // Output to PF1, Red LED, is VT (ventricular trigger) // Make PF4 input, PF3,PF1 output // Initialize Ready to high and VT to low // Repeat this sequence of operation over and over // 1) Wait for AS to fall (touch SW1 switch) // 2) Clear Ready low // 3) Wait 10ms (debounces the switch) // 4) Wait for AS to rise (release SW1) // 5) Wait 250ms (simulates the time between atrial and ventricular contraction) // 6) set VT high, which will pulse the ventricles // 7) Wait 250ms // 8) clear VT low // 9) set Ready high

// Date: January 15, 2016

// 1. Pre-processor Directives Section #include "TExaS.h"

// Constant declarations to access port registers using // symbolic names instead of addresses #define GPIO_PORTF_DATA_R (*((volatile unsigned long *)0x400253FC)) #define GPIO_PORTF_DIR_R (*((volatile unsigned long *)0x40025400)) #define GPIO_PORTF_AFSEL_R (*((volatile unsigned long *)0x40025420)) #define GPIO_PORTF_PUR_R (*((volatile unsigned long *)0x40025510)) #define GPIO_PORTF_DEN_R (*((volatile unsigned long *)0x4002551C)) #define GPIO_PORTF_LOCK_R (*((volatile unsigned long *)0x40025520)) #define GPIO_PORTF_CR_R (*((volatile unsigned long *)0x40025524)) #define GPIO_PORTF_AMSEL_R (*((volatile unsigned long *)0x40025528)) #define GPIO_PORTF_PCTL_R (*((volatile unsigned long *)0x4002552C)) #define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108)) // 2. Declarations Section // Global Variables

// Function Prototypes void PortF_Init(void); void Delay1ms(unsigned long msec); void EnableInterrupts(void); // Enable interrupts void WaitForASLow(void); void WaitForASHigh(void); void SetVT(void); void ClearVT(void); void SetReady(void); void ClearReady(void);

// 3. Subroutines Section // MAIN: Mandatory for a C Program to be executable int main(void){ TExaS_Init(SW_PIN_PF40, LED_PIN_PF31,ScopeOn); // activate grader and set system clock to 80 MHz PortF_Init(); // Init port PF4 PF3 PF1 EnableInterrupts(); // enable interrupts for the grader while(1){ SetReady(); WaitForASLow(); ClearReady(); Delay1ms(10); WaitForASHigh(); Delay1ms(250); SetVT(); Delay1ms(250); ClearVT(); } } // Subroutine to initialize port F pins for input and output // PF4 is input SW1 and PF3-1 is output LEDs // Inputs: None // Outputs: None // Notes: ... void PortF_Init(void){ volatile unsigned long delay; SYSCTL_RCGC2_R |= 0x00000020; // 1) F clock delay = SYSCTL_RCGC2_R; // delay to allow clock to stabilize GPIO_PORTF_AMSEL_R &= 0x00; // 2) disable analog function GPIO_PORTF_PCTL_R &= 0x00000000; // 3) GPIO clear bit PCTL GPIO_PORTF_DIR_R &= ~0x10; // 4.1) PF4 input, GPIO_PORTF_DIR_R |= 0x0E; // 4.2) PF3,2,1 output GPIO_PORTF_AFSEL_R &= 0x00; // 5) no alternate function GPIO_PORTF_PUR_R |= 0x10; // 6) enable pullup resistor on PF4 GPIO_PORTF_DEN_R |= 0x1E; // 7) enable digital pins PF4-PF1 } // Color LED(s) PortF // dark --- 0 // red R-- 0x02 // blue --B 0x04 // green -G- 0x08 // yellow RG- 0x0A // sky blue -GB 0x0C // white RGB 0x0E

void WaitForASLow(void){ unsigned int SW1; while(SW1){ SW1=GPIO_PORTF_DATA_R&(1<<4); } }

void WaitForASHigh(void){ unsigned int SW1; while(!SW1){ SW1=GPIO_PORTF_DATA_R&(1<<4); }

}

void SetVT(void){ GPIO_PORTF_DATA_R |= (1<<1); }

void ClearVT(void){ GPIO_PORTF_DATA_R &= ~(1<<1); } void SetReady(void){ GPIO_PORTF_DATA_R |= (1<<3); }

void ClearReady(void){ GPIO_PORTF_DATA_R &= ~(1<<3); }

void Delay1ms(unsigned long msec){ unsigned long int time; time = msec*72724*20/91; while(time > 0) time --; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!