Use the C programming language, not C++. #include “driverlib.h” #include #include #define MAXCOUNT 500 Bool isPrime(uint16_t x); // Main Function Void main(void){ volatile uint16_t ii; // declare local loop variable // Halt the WDT and unlock PMM for Port I/O Configuration WDT_A_hold(WDT_A_BASE); PMM_unlockLPM5(); //Set P1.0 (RED LED) as Output GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); //Set P1.0 (RED LED) Low -- Turns RED LED OFF GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); for(ii=0; ii
Use the C
#include “driverlib.h”
#include <stdint.h>
#include <stdbool.h>
#define MAXCOUNT 500
Bool isPrime(uint16_t x);
// Main Function
Void main(void){
volatile uint16_t ii; // declare local loop variable
// Halt the WDT and unlock PMM for Port I/O Configuration
WDT_A_hold(WDT_A_BASE);
PMM_unlockLPM5();
//Set P1.0 (RED LED) as Output
GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
//Set P1.0 (RED LED) Low -- Turns RED LED OFF
GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
for(ii=0; ii<MAXCOUNT; ii++){
if(isPrime(ii)) GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
}
while(1); // Spin Loop
}
// Function isPrime
// Input x -- number to check if prime
// Returns: True, if x is prime else FALSE
//
Bool isPrime(uint16_t x){
volatile uint16_t ii;
uint16_t maxValue;
if((x==0) || (x==1)) return false;
if((x==2) || (x==3)) return true;
maxValue = (x/2) + 1; // doesn’t hurt to add parenthesis
for(ii=2; ii<= maxValue; ii++){
if((x % ii) == 0) return false;
}
return true;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images