Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I only need part two. Please show full code. Here is my code for problem 1 to give you an idea of what type of

I only need part two. Please show full code.

image text in transcribed

Here is my code for problem 1 to give you an idea of what type of language and coding style we are using. Also, I will rate when finished.

Problem 1:

#include <__cross_studio_io.h> #include "nrf.h" #include "nrf51.h"

// create #define statements that convert values in manual to words // Makes the code more communicative

//Button GPIO PINS #define BUT1 17 #define BUT2 18 #define BUT3 19 #define BUT4 20 //LED GPIO PINS #define LED1 21 #define LED2 22 #define LED3 23 #define LED4 24

//GPIO DIRECTION #define GPIO_DirIn 0 #define GPIO_DirOut 1 //GPIO INPUT BUFFER #define GPIO_InputBufConn 0 #define GPIO_InputBufDisconn 1 //GPIO PULL #define GPIO_PullNo 0 #define GPIO_PullLow 1 #define GPIO_PullHigh 3 //GPIO DRIVE //S=Standard;H=High;D=disconnect //0=low;1=high #define GPIO_DriveS0S1 0 #define GPIO_DriveH0S1 1 #define GPIO_DriveS0H1 2 #define GPIO_DriveH0H1 3 #define GPIO_DriveD0S1 4 #define GPIO_DriveD0H1 5 #define GPIO_DriveS0SD 6 #define GPIO_DriveH0SD 7 //GPIO Sense #define GPIO_SenseDisabled 0 #define GPIO_SenseHigh 2 #define GPIO_SenseLow 3

// Define High and Low #define High 1 #define Low 0

void main(void) { /* Have similar code where we ended yesterday, Button Press Controls LED, Now we Convert to more conversational coding due to definitions THis is similar to other higher order coding systems or predefined embedded systems (Arduino) */

// declare our variables and define them if necessary uint32_t wait_var=10000; uint32_t dataIn; uint32_t A,B,C,D,E;

/***************************************************************************************************************************************************************************** **************************************************************LED 1 WITH BUTTON 1********************************************************************************************* ******************************************************************************************************************************************************************************/

// Setup and configure your pins and peripherals // setup pin 21 as an LED NRF_GPIO->PIN_CNF[LED1]&=~((0x3PIN_CNF[LED1]|=((GPIO_SenseDisabled

// Perform a check Our register should be set properly //Allows program to check registers rather than you looking through register in debug A=(NRF_GPIO->PIN_CNF[LED1]>>0) & (0X1);// B=(NRF_GPIO->PIN_CNF[LED1]>>1) & (0X1);// C=(NRF_GPIO->PIN_CNF[LED1]>>2) & (0X3);// D=(NRF_GPIO->PIN_CNF[LED1]>>8) & (0X7);// E=(NRF_GPIO->PIN_CNF[LED1]>>16) & (0X3);//

// Setup Button 1 (PIN17) as an input NRF_GPIO->PIN_CNF[BUT1]&=~((0x3PIN_CNF[BUT1]|=((GPIO_SenseDisabled

/***************************************************************************************************************************************************************************** **************************************************************LED 2 WITH BUTTON 2********************************************************************************************* ******************************************************************************************************************************************************************************/ // Setup and configure your pins and peripherals // setup pin 22 as an LED NRF_GPIO->PIN_CNF[LED2]&=~((0x3PIN_CNF[LED2]|=((GPIO_SenseDisabled

// Perform a check Our register should be set properly //Allows program to check registers rather than you looking through register in debug A=(NRF_GPIO->PIN_CNF[LED2]>>0) & (0X1);// B=(NRF_GPIO->PIN_CNF[LED2]>>1) & (0X1);// C=(NRF_GPIO->PIN_CNF[LED2]>>2) & (0X3);// D=(NRF_GPIO->PIN_CNF[LED2]>>8) & (0X7);// E=(NRF_GPIO->PIN_CNF[LED2]>>16) & (0X3);//

// Setup Button 2 (PIN18) as an input NRF_GPIO->PIN_CNF[BUT2]&=~((0x3PIN_CNF[BUT2]|=((GPIO_SenseDisabled

/***************************************************************************************************************************************************************************** **************************************************************LED 3 WITH BUTTON 3********************************************************************************************* ******************************************************************************************************************************************************************************/ // Setup and configure your pins and peripherals // setup pin 23 as an LED NRF_GPIO->PIN_CNF[LED3]&=~((0x3PIN_CNF[LED3]|=((GPIO_SenseDisabled

// Perform a check Our register should be set properly //Allows program to check registers rather than you looking through register in debug A=(NRF_GPIO->PIN_CNF[LED3]>>0) & (0X1);// B=(NRF_GPIO->PIN_CNF[LED3]>>1) & (0X1);// C=(NRF_GPIO->PIN_CNF[LED3]>>2) & (0X3);// D=(NRF_GPIO->PIN_CNF[LED3]>>8) & (0X7);// E=(NRF_GPIO->PIN_CNF[LED3]>>16) & (0X3);//

// Setup Button 3 (PIN19) as an input NRF_GPIO->PIN_CNF[BUT3]&=~((0x3PIN_CNF[BUT3]|=((GPIO_SenseDisabled

/***************************************************************************************************************************************************************************** **************************************************************LED 4 WITH BUTTON 4********************************************************************************************* ******************************************************************************************************************************************************************************/ // Setup and configure your pins and peripherals // setup pin 23 as an LED NRF_GPIO->PIN_CNF[LED4]&=~((0x3PIN_CNF[LED4]|=((GPIO_SenseDisabled

// Perform a check Our register should be set properly //Allows program to check registers rather than you looking through register in debug A=(NRF_GPIO->PIN_CNF[LED4]>>0) & (0X1);// B=(NRF_GPIO->PIN_CNF[LED4]>>1) & (0X1);// C=(NRF_GPIO->PIN_CNF[LED4]>>2) & (0X3);// D=(NRF_GPIO->PIN_CNF[LED4]>>8) & (0X7);// E=(NRF_GPIO->PIN_CNF[LED4]>>16) & (0X3);//

// Setup Button 4 (PIN20) as an input NRF_GPIO->PIN_CNF[BUT4]&=~((0x3PIN_CNF[BUT4]|=((GPIO_SenseDisabled

while(1) { //************************************************************** THIS IS FOR LED 1 WITH BUTTON 1 // read bit 17 only from our in register dataIn=((NRF_GPIO->IN)>>BUT1)& 0x1;

if (dataIn) // i am not pushing the button { //OUR ONBOARD LEDS ARE ACTIVE LOW //LED should be off NRF_GPIO->OUT|= (0X1OUT&=~ (0X1

//************************************************************* THIS IS FOR LED 2 WITH BUTTON 2 // read bit 17 only from our in register dataIn=((NRF_GPIO->IN)>>BUT2)& 0x1;

if (dataIn) // i am not pushing the button { //OUR ONBOARD LEDS ARE ACTIVE LOW //LED should be off NRF_GPIO->OUT|= (0X1OUT&=~ (0X1

//************************************************************* THIS IS FOR LED 3 WITH BUTTON 3 // read bit 17 only from our in register dataIn=((NRF_GPIO->IN)>>BUT3)& 0x1;

if (dataIn) // i am not pushing the button { //OUR ONBOARD LEDS ARE ACTIVE LOW //LED should be off NRF_GPIO->OUT|= (0X1OUT&=~ (0X1

//************************************************************* THIS IS FOR LED 4 WITH BUTTON 4 // read bit 17 only from our in register dataIn=((NRF_GPIO->IN)>>BUT4)& 0x1;

if (dataIn) // i am not pushing the button { //OUR ONBOARD LEDS ARE ACTIVE LOW //LED should be off NRF_GPIO->OUT|= (0X1OUT&=~ (0X1

}// end repeat while loop

}// end Main

Create the following Programs: 1) Create a program where each button controls its respective onboard LED (ie button 1 to LED 1). 2) Create a program with the following constraints Buttons Pressed LED States No buttons Pressed LEDs 1,2,3,4 blink on and off (think hazard lights) Button 1 pressed only Lights cycle clockwise Button 4 pressed Lights cycle counter clockwise Buttons 2 or 3 pressed All lights stay on while pressed Any combination of All lights off buttons pressed (ie button 2 and 3 at same time) Note: cycle means that one light turns on and off before the next light turns on and off (ie LED1 on LED 1 off LED 2 on LED 2 off, etc

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

Students also viewed these Databases questions

Question

What are the five forces that determine an industrys profitability?

Answered: 1 week ago