CS计算机代考程序代写 ENG2008 lab 6 answer sheet

ENG2008 lab 6 answer sheet
There are three files in this task. LEDs.h, LEDs.c and main.c. Complete the missing code.

LEDs.h
#ifndef LEDS_H
#define LEDS_H

#define MASK(x) (1UL << (x)) // mbed Application Shield LEDs #define RED_LED_POS (5) // on port A #define GREEN_LED_POS (5) // on port D #define BLUE_LED_POS (13) // on port A // functions void Init_RGB_LEDs(void); void Control_RGB_LEDs(unsigned int red_on, unsigned int green_on, unsigned int blue_on); #endif ----------------------------------------------------------------------------------------------------------------------------------------------------------- LEDs.c #include
#include “LEDs.h”

void Init_RGB_LEDs(void) {
Click here to enter text.

// Enable clock to ports A and D (2 marks)
Click here to enter text.

// Make 3 pins for LEDs GPIO (2 marks)
// Set 3 pins for LEDs as outputs (2 marks)
Click here to enter text.

}

/*————————————————————————————–
Turn on/off relevant LED(s), 1 – on, 0 – off
—————————————————————————————*/
void Control_RGB_LEDs(unsigned int red_on, unsigned int green_on, unsigned int blue_on) {
if (red_on) {
PTA->PCOR = MASK(RED_LED_POS);
} else {
PTA->PSOR = MASK(RED_LED_POS);
}
if (green_on) {
PTD->PCOR = MASK(GREEN_LED_POS);
} else {
PTD->PSOR = MASK(GREEN_LED_POS);
}
if (blue_on) {
PTA->PCOR = MASK(BLUE_LED_POS);
} else {
PTA->PSOR = MASK(BLUE_LED_POS);
}
}
———————————————————————————————————————————————————–

main.c
/* ADC, Display results using LEDs */
#include
#include “LEDs.h”

/* ADC initialisation */
void Init_ADC(void) {
// Enable ADC clock (1 marks)
Click here to enter text.

Click here to enter text.

ADC0->CFG1 |= ADC_CFG1_ADLPC_MASK | ADC_CFG1_ADIV(0) | ADC_CFG1_ADLSMP_MASK | ADC_CFG1_MODE(3) ; // comment this line, explain how ADC is configured (1 mark)

ADC0->SC2 = 0; // comment this line, explain how ADC is configured (1 mark)
Click here to enter text.

}

Click here to enter text.

/* write a subroutine to store ADC result in a variable and return this variable, specify the type of this subroutine */
Measure_VBat(void) { // (1 mark)

Click here to enter text.

// your code here (4 marks)
}

/*————————————————————————————————————
Complete the main function to change LED colour according to measured voltage
*———————————————————————————————————–*/
int main (void) {
Init_RGB_LEDs();
Init_ADC();
Click here to enter text.

// your code here (6 marks)
Click here to enter text.

}