static void prvSetupHardware( void ) { extern void FPU_enableModule( void ); /* The clocks are not configured here, but inside main_full() and main_blinky() as the full demo uses a fast clock and the blinky demo uses a slow clock. */ /* Stop the watchdog timer. */ MAP_WDT_A_holdTimer(); /* Ensure the FPU is enabled. */ FPU_enableModule(); /* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION ); MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); MAP_GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); /* Enable S2 and LED2 */ MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 ); MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN1 ); MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1); MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN2 ); MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2); MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4); MAP_GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN4, GPIO_HIGH_TO_LOW_TRANSITION); MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN4); MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4); MAP_Interrupt_enableInterrupt(INT_PORT1); }
/* * ======== WatchdogMSP432_close ======== */ void WatchdogMSP432_close(Watchdog_Handle handle) { WatchdogMSP432_Object *object = handle->object; WatchdogMSP432_HWAttrs const *hwAttrs = handle->hwAttrs; MAP_WDT_A_holdTimer(); /* Destroy the SYS/BIOS objects. */ if (object->hwiHandle) { HwiP_delete(object->hwiHandle); } /* Remove power constraints */ if (object->resetMode == Watchdog_RESET_ON || hwAttrs->clockSource == WDT_A_CLOCKSOURCE_SMCLK || hwAttrs->clockSource == WDT_A_CLOCKSOURCE_ACLK) { Power_releaseConstraint(PowerMSP432_DISALLOW_DEEPSLEEP_0); Power_releaseConstraint(PowerMSP432_DISALLOW_SHUTDOWN_0); } else { Power_releaseConstraint(PowerMSP432_DISALLOW_DEEPSLEEP_1); } Power_releaseConstraint(PowerMSP432_DISALLOW_SHUTDOWN_1); object->isOpen = false; }
int main(void) { /* Halting WDT */ MAP_WDT_A_holdTimer(); /* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); /* Setting DCO to 48MHz (upping Vcore) */ MAP_PCM_setCoreVoltageLevel(PCM_VCORE1); CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); /* Configuring UART Module */ MAP_UART_initModule(EUSCI_A0_MODULE, &uartConfig); /* Enable UART module */ MAP_UART_enableModule(EUSCI_A0_MODULE); /* Enabling interrupts */ MAP_UART_enableInterrupt(EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT); MAP_Interrupt_enableInterrupt(INT_EUSCIA0); MAP_Interrupt_enableSleepOnIsrExit(); while(1) { MAP_UART_transmitData(EUSCI_A0_MODULE, TXData); MAP_Interrupt_enableSleepOnIsrExit(); MAP_PCM_gotoLPM0InterruptSafe(); } }
/* * ======== switchToWatchdogTimer ======== * * Use 250ms watchdog timer interrupt to drive the Clock tick * Stop the default Timer_A then start the watchdog timer. */ static void switchToWatchdogTimer() { Clock_TimerProxy_Handle clockTimer; static Hwi_Handle wdtHwi = NULL; /* Stop Timer_A currrently being used by Clock */ clockTimer = Clock_getTimerHandle(); Clock_TimerProxy_stop(clockTimer); MAP_WDT_A_holdTimer(); if (wdtHwi == NULL) { /* Create watchdog Timer Hwi */ wdtHwi = Hwi_create(19, clockTickFxn, NULL, NULL); /* set WDT to use 32KHz input, 250ms period */ MAP_WDT_A_initIntervalTimer(WDT_A_CLOCKSOURCE_XCLK, WDT_A_CLOCKITERATIONS_8192); } /* don't allow deeper than DEEPSLEEP1 */ Power_setConstraint(PowerMSP432_DISALLOW_DEEPSLEEP_1); /* Start watchdog Timer */ MAP_WDT_A_clearTimer(); MAP_WDT_A_startTimer(); /* hence, Clock_tick() will be called from 250ms watchdog timer interrupt */ }
/* application. */ void resetISR(void) { /* Jump to the CCS C Initialization Routine. */ MAP_WDT_A_holdTimer(); __asm(" .global _c_int00\n" " b.w _c_int00"); }
int main(void) { /* Halting WDT */ MAP_WDT_A_holdTimer(); /* Selecting P1.2 and P1.3 in UART mode */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); /* Setting DCO to 12MHz */ CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12); /* Configuring UART Module */ MAP_UART_initModule(EUSCI_A0_MODULE, &uartConfig); /* Enable UART module */ MAP_UART_enableModule(EUSCI_A0_MODULE); /* Enabling interrupts */ MAP_UART_enableInterrupt(EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT); MAP_Interrupt_enableInterrupt(INT_EUSCIA0); MAP_Interrupt_enableSleepOnIsrExit(); MAP_Interrupt_enableMaster(); while(1) { MAP_PCM_gotoLPM0(); } }
int main(void) { /* Halting WDT */ MAP_WDT_A_holdTimer(); MAP_Interrupt_enableSleepOnIsrExit(); resPos = 0; /* Setting up clocks * MCLK = MCLK = 3MHz * ACLK = REFO/4 = 32Khz */ MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); /* Initializing ADC (MCLK/1/1) */ MAP_ADC14_enableModule(); MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1, 0); /* Configuring GPIOs (5.5 A0) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); /* Configuring ADC Memory */ MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true); MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); /* Configuring Timer_A in continuous mode and sourced from ACLK */ MAP_Timer_A_configureContinuousMode(TIMER_A0_MODULE, &continuousModeConfig); /* Configuring Timer_A0 in CCR1 to trigger at 16000 (0.5s) */ MAP_Timer_A_initCompare(TIMER_A0_MODULE, &compareConfig); /* Configuring the sample trigger to be sourced from Timer_A0 and setting it * to automatic iteration after it is triggered*/ MAP_ADC14_setSampleHoldTrigger(ADC_TRIGGER_SOURCE1, false); /* Enabling the interrupt when a conversion on channel 1 is complete and * enabling conversions */ MAP_ADC14_enableInterrupt(ADC_INT0); MAP_ADC14_enableConversion(); /* Enabling Interrupts */ MAP_Interrupt_enableInterrupt(INT_ADC14); MAP_Interrupt_enableMaster(); /* Starting the Timer */ MAP_Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_CONTINUOUS_MODE); /* Going to sleep */ while (1) { MAP_PCM_gotoLPM0(); } }
int main(void) { volatile uint32_t ii; /* Stop WDT */ MAP_WDT_A_holdTimer(); /* * Select Port 7 * Set Pin 1 to output Primary Module Function, (COUT). */ MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P7, GPIO_PIN1, GPIO_PRIMARY_MODULE_FUNCTION); /* Set P7.7 to be comparator in (C0.2) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P7, GPIO_PIN7, GPIO_TERTIARY_MODULE_FUNCTION); /* Initialize the Comparator E module * Comparator Instance 0, * Pin CE2 to Positive(+) Terminal, * Reference Voltage to Negative(-) Terminal, * Normal Power Mode, * Output Filter On with max delay, * Non-Inverted Output Polarity */ MAP_COMP_E_initModule(COMP_E0_MODULE, &compConfig); /*Set the reference voltage that is being supplied to the (-) terminal * Comparator Instance 0, * Reference Voltage of 2.0 V, * Lower Limit of 2.0*(32/32) = 2.0V, * Upper Limit of 2.0*(32/32) = 2.0V */ MAP_COMP_E_setReferenceVoltage(COMP_E0_MODULE, COMP_E_VREFBASE2_0V, 32, 32); /* Disable Input Buffer on P1.2/CE2 * Base Address of Comparator E, * Input Buffer port * Selecting the CEx input pin to the comparator * multiplexer with the CEx bits automatically * disables output driver and input buffer for * that pin, regardless of the state of the * associated CEPD.x bit */ MAP_COMP_E_disableInputBuffer(COMP_E0_MODULE, COMP_E_INPUT2); /* Allow power to Comparator module */ MAP_COMP_E_enableModule(COMP_E0_MODULE); MAP_PCM_gotoLPM0(); __no_operation(); }
/* * ======== switchToTimerA ======== * * Use 1ms Timer_A interrupt to drive the Clock tick * By default, the Timer_A Hwi object has already been * statically created and configured to call Clock_tick(). * Simply stop the watchdog timer and restart the Timer_A. */ static void switchToTimerA() { Clock_TimerProxy_Handle clockTimer; /* Stop watchdog Timer */ MAP_WDT_A_holdTimer(); /* Re-start Timer_A */ clockTimer = Clock_getTimerHandle(); Clock_TimerProxy_start(clockTimer); /* hence, Clock_tick() will be called from 1ms Timer_A interrupt */ }
void main(void) { //WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer /* Halting WDT and disabling master interrupts */ MAP_WDT_A_holdTimer(); MAP_Interrupt_disableMaster(); startup_MSP432(); while(1) accelz = sensor_read(MPU9150_ACCEL_ZOUT_H,MPU9150_ACCEL_ZOUT_L); }
int main(void) { /* Variables we will store the sizes in. Declared volatile so the compiler * does not optimize out */ volatile uint32_t sramSize, flashSize; /* Halting the Watchdog */ MAP_WDT_A_holdTimer(); /* Disabling SRAM bank 1. This also disables banks 2-6 */ MAP_SysCtl_disableSRAMBank(SYSCTL_SRAM_BANK1); /* No operation. Set Breakpoint here */ __no_operation(); }
int main(void) { uint32_t ii; /* Disabling the Watchdog */ MAP_WDT_A_holdTimer(); xferIndex = 0; /* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function, * (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL). */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); /* Configuring GPIO P1.0 to be an input. As the GPIO is pulled up by the * master, when the port is set to an input the pull-up defaults and the * pin is high. When the interrupt is asserted, we set the GPIO to an * output low and cause the interrupt to occur. */ MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN1); MAP_GPIO_setAsInputPin(GPIO_PORT_P1, GPIO_PIN0); /* eUSCI I2C Slave Configuration */ MAP_I2C_initSlave(EUSCI_B0_MODULE, SLAVE_ADDRESS_1, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); /* Enable the module and enable interrupts */ MAP_I2C_enableModule(EUSCI_B0_MODULE); MAP_Interrupt_enableInterrupt(INT_EUSCIB0); /* Sleeping while not in use */ while (1) { /* Delaying between transactions */ for(ii=0;ii<4000;ii++); /* Initiating the read from the master by asserting our GPIO */ MAP_I2C_enableInterrupt(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0); MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); MAP_Interrupt_enableSleepOnIsrExit(); MAP_PCM_gotoLPM0InterruptSafe(); } }
int main(void) { /* Disabling the Watchdog */ MAP_WDT_A_holdTimer(); xferIndex_0 = 0; xferIndex_1 = 0; /* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function, * (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL). */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); /* eUSCI I2C Slave Configuration */ /* Slave Address 1 (0x48) */ MAP_I2C_initSlave(EUSCI_B0_MODULE, SLAVE_ADDRESS_1, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); /* Slave Address 1 (0x49) */ MAP_I2C_initSlave(EUSCI_B0_MODULE, SLAVE_ADDRESS_2, EUSCI_B_I2C_OWN_ADDRESS_OFFSET1, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); /* Set in receive mode */ MAP_I2C_setMode(EUSCI_B0_MODULE, EUSCI_B_I2C_RECEIVE_MODE); /* Enable the module and enable interrupts */ MAP_I2C_enableModule(EUSCI_B0_MODULE); MAP_I2C_clearInterruptFlag(EUSCI_B0_MODULE, EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_RECEIVE_INTERRUPT1); MAP_I2C_enableInterrupt(EUSCI_B0_MODULE, EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_RECEIVE_INTERRUPT1); MAP_Interrupt_enableSleepOnIsrExit(); MAP_Interrupt_enableInterrupt(INT_EUSCIB0); MAP_Interrupt_enableMaster(); /* Sleeping while not in use */ while (1) { MAP_PCM_gotoLPM0(); } }
static void prvSetupHardware( void ) { extern void FPU_enableModule( void ); /* The clocks are not configured here, but inside main_full() and main_blinky() as the full demo uses a fast clock and the blinky demo uses a slow clock. */ /* Stop the watchdog timer. */ MAP_WDT_A_holdTimer(); /* Ensure the FPU is enabled. */ FPU_enableModule(); /* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION ); MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); MAP_GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); }
/* application. */ void resetISR(void) { // Stop Watch Dog Timer MAP_WDT_A_holdTimer(); // Zero fill the bss segment __asm(" ldr r0, =__bss_start__\n" " ldr r1, =__bss_end__\n" " mov r2, #0\n" " .thumb_func\n" "zero_loop:\n" " cmp r0, r1\n" " it lt\n" " strlt r2, [r0], #4\n" " blt zero_loop"); // Switch to main() function __asm(" .global main\n" " b.w main"); }
int main() { uint8_t *httpchar = 0; MAP_WDT_A_holdTimer(); UART_PC_init(); init_timer32_0(); SL_D_init(); UART_GSM_init(); while(1){ if(call_server_flag){ httpchar = request_to_server(); update_display(httpchar); call_server_flag = false; //reset flag init_timer32_0(); } } }
int main(void) { volatile uint32_t ii; /* Halting the Watchdog */ MAP_WDT_A_holdTimer(); /* Configuring P1.0 as output */ MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); while (1) { /* Delay Loop */ for(ii=0;ii<5000;ii++) { } MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); } }
//------------------------------------------------------------------------------ int InitFunction(void) { int err = NONE; MAP_WDT_A_holdTimer(); /* Configuring P6.7 as an input. P1.0 as output and enabling interrupts */ // MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1); //Setting RGB LED as output MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2); //Set P6.1 to be the pin interupt MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P6, GPIO_PIN1); MAP_GPIO_clearInterruptFlag(GPIO_PORT_P6, GPIO_PIN1); MAP_GPIO_enableInterrupt(GPIO_PORT_P6, GPIO_PIN1); MAP_Interrupt_enableInterrupt(INT_PORT6); MAP_Interrupt_enableMaster(); return err; }
int main(void) { /* Halting WDT */ MAP_WDT_A_holdTimer(); /* Selecting P1.2 and P1.3 in UART mode */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); /* Setting DCO to 12MHz */ CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12); /* Configuring UART Module */ MAP_UART_initModule(EUSCI_A0_MODULE, &uartConfig); /* Enable UART module */ MAP_UART_enableModule(EUSCI_A0_MODULE); MAP_Interrupt_enableMaster(); /* Initialize values to display */ char *s = "printf test"; char c = '!'; int i = -12345; unsigned u = 4321; long int l = -123456780; long unsigned n = 1098765432; unsigned x = 0xABCD; while(1) { printf(EUSCI_A0_MODULE, "String %s\r\n", s); printf(EUSCI_A0_MODULE, "Char %c\r\n", c); printf(EUSCI_A0_MODULE, "Integer %i\r\n", i); printf(EUSCI_A0_MODULE, "Unsigned %u\r\n", u); printf(EUSCI_A0_MODULE, "Long %l\r\n", l); printf(EUSCI_A0_MODULE, "uNsigned loNg %n\r\n", n); printf(EUSCI_A0_MODULE, "heX %x\r\n", x); } }
int main(void) { MAP_WDT_A_holdTimer(); /* Remapping TACCR0 to P2.0 */ MAP_PMAP_configurePorts((const uint8_t *) port_mapping, P2MAP, 1, PMAP_DISABLE_RECONFIGURATION); MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION); /* Initialize compare registers to generate PWM1 */ MAP_Timer_A_initCompare(TIMER_A1_MODULE, &compareConfig_PWM1); /* Configuring Timer_A1 for UpDown Mode and starting */ MAP_Timer_A_configureUpDownMode(TIMER_A1_MODULE, &upDownConfig); MAP_Timer_A_startCounter(TIMER_A1_MODULE, TIMER_A_UPDOWN_MODE); while (1) { MAP_PCM_gotoLPM0(); } }
int main(void) { volatile uint32_t ii; /* Disabling the Watchdog */ MAP_WDT_A_holdTimer(); /* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function, * (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL). */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); sendStopCondition = false; sendToSlaveAddress2 = false; /* Initializing I2C Master to SMCLK at 400kbs with no autostop */ MAP_I2C_initMaster(EUSCI_B0_MODULE, &i2cConfig); /* Specify slave address. For start we will do our first slave address */ MAP_I2C_setSlaveAddress(EUSCI_B0_MODULE, SLAVE_ADDRESS_1); /* Set Master in receive mode */ MAP_I2C_setMode(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_MODE); /* Enable I2C Module to start operations */ MAP_I2C_enableModule(EUSCI_B0_MODULE); /* Enable and clear the interrupt flag */ MAP_I2C_clearInterruptFlag(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT); //Enable master Receive interrupt MAP_I2C_enableInterrupt(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT); MAP_Interrupt_enableInterrupt(INT_EUSCIB0); while (1) { /* Load Byte Counter */ TXByteCtr = 4; /* Making sure the last transaction has been completely sent out */ while (MAP_I2C_masterIsStopSent(EUSCI_B0_MODULE) == EUSCI_B_I2C_SENDING_STOP); /* Sending the initial start condition for appropriate * slave addresses */ if(sendToSlaveAddress2) { MAP_I2C_setSlaveAddress(EUSCI_B0_MODULE, SLAVE_ADDRESS_2); } else { MAP_I2C_setSlaveAddress(EUSCI_B0_MODULE, SLAVE_ADDRESS_1); } MAP_I2C_masterSendMultiByteStart(EUSCI_B0_MODULE, TXData++); while(sendStopCondition == false) { /* Go to sleep while data is being transmitted */ MAP_Interrupt_enableSleepOnIsrExit(); MAP_PCM_gotoLPM0InterruptSafe(); } sendStopCondition = false; } }
int main(void) { /* Stop Watchdog */ MAP_WDT_A_holdTimer(); SL_D_init(); /* Display Refresh */ // uint8_t cmdArr[3] = {0x24, 0x01, 0x00}; // SL_D_sendCmd(cmdArr, 3); // /* Reset Data Pointer */ // uint8_t cmdArr1[3] = {0x20, 0x0D, 0x00}; // SL_D_sendCmd(cmdArr1, 3); // // /* Upload Image Data */ // uint8_t cmdArr2[20] = {0x20, 0x01, 0x00, 0x10, //UploadImageData Cmd // 0x3A, 0x01, 0xE0, 0x03, 0x20, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //EPD File Header // uint8_t cmdArr2_1[180] = {0x20, 0x01, 0x00, 0xA0, //UploadImageData Cmd // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //EPD File Data // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // SL_D_sendCmd(cmdArr2, 20); // SL_D_sendCmd(cmdArr2_1, 180); // SL_D_sendCmd(cmdArr2_1, 180); // SL_D_sendCmd(cmdArr2_1, 180); // SL_D_sendCmd(cmdArr2_1, 180); // SL_D_sendCmd(cmdArr2_1, 180); // SL_D_sendCmd(cmdArr2_1, 180); // SL_D_sendCmd(cmdArr2_1, 180); // SL_D_sendCmd(cmdArr2_1, 180); // SL_D_sendCmd(cmdArr2_1, 180); // SL_D_sendCmd(cmdArr2_1, 180); // // /* Display Refresh */ // uint8_t cmdArr3[3] = {0x24, 0x01, 0x00}; // SL_D_sendCmd(cmdArr3, 3); uint8_t cmdArr1[20] = {0x20, 0x01, 0x00, 0x10, 0x3A, 0x01, 0xE0, 0x03, 0x20, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; SL_D_sendCmd(cmdArr1, 20); uint8_t cmdArr2[64] = {0x20, 0x01, 0x00, 0x3C, 0xF0, 0x00, 0x5C, 0x55, 0xFA, 0x90, 0x5F, 0xCC, 0x22, 0x81, 0x7D, 0x3A, 0xE6, 0xEE, 0x11, 0x19, 0xEA, 0xA2, 0x51, 0x0F, 0xF0, 0x00, 0x5C, 0x55, 0xFA, 0x90, 0x5F, 0xCC, 0x22, 0x81, 0x7D, 0x3A, 0xE6, 0xEE, 0x11, 0x19, 0xEA, 0xA2, 0x51, 0x0F, 0xF0, 0x00, 0x5C, 0x55, 0xFA, 0x90, 0x5F, 0xCC, 0x22, 0x81, 0x7D, 0x3A, 0xE6, 0xEE, 0x11, 0x19, 0xEA, 0xA2, 0x51, 0x0F }; int i; for(i=0; i<800; i++) { SL_D_sendCmd(cmdArr2, 64); } uint8_t cmdArr3[3] = {0x24, 0x01, 0x00}; SL_D_sendCmd(cmdArr3, 3); while(1) { __no_operation(); } }
//----------------------------------------------------------------------- // // THIS CODE HAS THE MANUAL CHIP SELECT FOR THE DISPLAY // int main (void) { //============== Local Variables ===================== int encoderValue = 0; int16_t temp0, temp2, temp3; unsigned int temp1; int refreshValues = YES, i, t = 0, h = 0; double temptemp1, temptemp2; screen = 2; tempFormat = CEL; tempCharacter[0] = 'C'; // Turning off watch dog timer MAP_WDT_A_holdTimer(); //Configuring pins for peripheral/crystal usage. CS_setExternalClockSourceFrequency(32768,48000000); MAP_PCM_setCoreVoltageLevel(PCM_VCORE1); MAP_FlashCtl_setWaitState(FLASH_BANK0, 2); MAP_FlashCtl_setWaitState(FLASH_BANK1, 2); CS_startHFXT(false); //Setting other clocks to speeds needed throughout the project MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_4); MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ, GPIO_PIN3 | GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION); //Initialization functions for variable peripherals InitFunction(); err = DisplayInit(); err |= InitOneWire(); err |= RF_Init(); if(err) { printf("ERROR occured in initialization functions.\n"); } //Setting variables to initial values temperatureOUT[0] = 250; temperatureOUT[1] = 251; temperatureIN[0] = 220; temperatureIN[1] = 221; humidityOUT[0] = 440; humidityOUT[1] = 441; humidityIN[0] = 330; humidityIN[1] = 331; pressure[0] = 60; pressure[1] = 61; lux[0] = 9000; lux[1] = 9001; lightIndex[0] = 1; lightIndex[1] = 2; //Enable interupts and set the interupt for the One-Wire to have highest priority MAP_Interrupt_enableMaster(); MAP_Interrupt_setPriority(INT_TA0_0, 0x00); //Keep process in infinite loop while(1) { while(!Setup) //'Setup' controls whether or not the user is view the data from //the remote system, or is editing the time for the RTC { if (status) //'status' is set high when the IQR pin is set high -- meaning there is a packet //available to be read in from the RF chip { status = 0; r_rx_payload((uint8_t)PACKET_SIZE, &data); //retrieve data sscanf(data, "<T%dP%dH%dL%d>", &temp0, &temp1, &temp2, &temp3); //parse data temperatureOUT[0] = temp0; pressure[0] = temp1; humidityOUT[0] = temp2; lux[0] = temp3; calculateLighting(lux[0], lightIndexString[0], &lightIndex[0]); //Figure out the lighting condition //Convert to F if 'tempFormat' is set high when tempFormat is set high, indicating that there needs to be a //C to F convserion. The data is C from the sensors. if(tempFormat == FAR) { //C to F convserion temptemp2 = ((float)temperatureOUT[0]); temperatureOUT[0] = (int)((temptemp2 * 1.8)); temperatureOUT[0] += 320; } } //Tick is set high every second from the RTC interupt if(tick) { i = 0; MAP_SysTick_disableModule(); // disable the systick interupt during while getting the // temperature and humidity data from sensor //Getting the temp and humidity data __delay_cycles(100); dht_start_read(); t = dht_get_temp(); h = dht_get_rh(); MAP_SysTick_enableModule(); //Enable the systick interupt again __delay_cycles(100); //put the humidity and temperature values in the needed variables humidityIN[0] = h; temperatureIN[0] = t; //Convert to F if 'tempFormat' is set high when tempFormat is set high, indicating that there needs to be a //C to F convserion. The data is C from the sensors. if(tempFormat == FAR) { //C to F conversion temptemp1 = ((float)temperatureIN[0]); temperatureIN[0] = (int)((temptemp1 * 1.8)); temperatureIN[0] += 320; } } //'screen' is either set to the value of 1 or 2. // screen == 1 is the main screen with only the temperatures and lighting condition displayed if(screen == 1) { //If the time has been updated or the screen has been switched, update the string if(tick || refreshValues) { tick = 0; //Create the time and date strings sprintf(dateString, "%s %02X, %X", months[newTime.month], newTime.dayOfmonth, newTime.year); sprintf(timeString, "%02X:%02X:%02X", newTime.hours, newTime.minutes, newTime.seconds); //Write "IN:" in the lower part of the screen to indicate to the user which temperature is the //inside tempterature if(refreshValues == YES) { ST7735_DrawStringHorizontal(50, 140, "IN:", ST7735_Color565(255, 255, 255), 1); } //Printing the time for(i = 0; i < strlen(timeString); i++) { ST7735_DrawChar(22+(11*i), 10, timeString[i], timeStringColor[i], 0x0000, 2); } //Printing the date for(i = 0; i < strlen(dateString); i++) { ST7735_DrawChar(30+(6*i), 30, dateString[i], dateStringColor[i], 0x0000, 1); } } //If the new data value is different than the previous value, or the screen has been changes, update display if((temperatureOUT[0] != temperatureOUT[1]) || refreshValues == YES) { //Re-write the last string in black (the same color as the backgruond) to cover it up so that the // new value is not written overtop. sprintf(tempString, "%02d.%.1d", temperatureOUT[1]/10, temperatureOUT[1]%10); ST7735_DrawStringHorizontal(20, 80, tempString, ST7735_Color565(0, 0, 0), 4); ST7735_DrawCharS((20 + strlen(tempString)*4*6), 80, tempCharacter[1], ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1); //Write the new string sprintf(tempString, "%02d.%.1d", temperatureOUT[0]/10, temperatureOUT[0]%10); ST7735_DrawStringHorizontal(20, 80, tempString, ST7735_Color565(255, 0, 0), 4); ST7735_DrawCharS((20 + strlen(tempString)*4*6), 80, tempCharacter[0], ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1); temperatureOUT[1] = temperatureOUT[0]; tempCharacter[1] = tempCharacter[0]; } //If the new data value is different than the previous value, or the screen has been changes, update display if((temperatureIN[0] != temperatureIN[1]) || refreshValues == YES) { //Re-write the last string in black (the same color as the backgruond) to cover it up so that the // new value is not written overtop. sprintf(tempString, "%02d.%.1d", temperatureIN[1]/10, temperatureIN[1]%10); ST7735_DrawStringHorizontal(70, 130, tempString, ST7735_Color565(0, 0, 0), 2); ST7735_DrawCharS((70 + strlen(tempString)*2*6), 130, tempCharacter, ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1); //Write the new string sprintf(tempString, "%02d.%.1d", temperatureIN[0]/10, temperatureIN[0]%10); ST7735_DrawStringHorizontal(70, 130, tempString, ST7735_Color565(255, 0, 0), 2); ST7735_DrawCharS((70 + strlen(tempString)*2*6), 130, tempCharacter, ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1); temperatureIN[1] = temperatureIN[0]; tempCharacter[1] = tempCharacter[0]; } //If the new data value is different than the previous value, or the screen has been changes, update display if((lightIndex[0] != lightIndex[1]) || refreshValues == YES) { //Re-write the last string in black (the same color as the backgruond) to cover it up so that the // new value is not written overtop. sprintf(tempString, "%s", lightIndexString[1]); ST7735_DrawStringVertical(0, 60, tempString, ST7735_Color565(0, 0, 0), 2); //Write the new string sprintf(tempString, "%s", lightIndexString[0]); ST7735_DrawStringVertical(0, 60, tempString, ST7735_Color565(0, 255, 0), 2); memcpy(lightIndexString[1], lightIndexString[0], sizeof(lightIndexString[0])); lightIndex[1] = lightIndex[0]; } //Reset the refreshValues variable. This variable will be set high when the user swithces screen by turning the knob refreshValues = NO; } //'screen' equalling 2 is the screen that displays all the data to the user if(screen == 2) { //If the time has been updated or the screen has been switched, update the string if(time || refreshValues) { tick = 0; //Create the time string that will be written sprintf(timeString, "%02X:%02X:%02X", newTime.hours, newTime.minutes, newTime.seconds); //Write the new time string for(i = 0; i < strlen(timeString); i++) { ST7735_DrawChar(35+(6*i), 5, timeString[i], ST7735_Color565(0, 0, 0), ST7735_Color565(255, 255, 255), 1); } } //When update the items on the screen that will remain constant when the screen is changed. if(refreshValues == YES) { sprintf(tempString, "Inside"); ST7735_DrawStringVertical(0, 10, tempString, ST7735_Color565(0, 255, 0), 1); sprintf(tempString, "Outside"); ST7735_DrawStringVertical(120, 90, tempString, ST7735_Color565(0, 255, 0), 1); sprintf(tempString, "_______________________"); ST7735_DrawStringHorizontal(0, 55, tempString, ST7735_Color565(255, 255, 255), 1); } //If the new data value is different than the previous value, or the screen has been changes, update display if((temperatureIN[0] != temperatureIN[1]) || refreshValues == YES) { //Re-write the last string in black (the same color as the backgruond) to cover it up so that the // new value is not written overtop. sprintf(tempString, "%02d.%.1d", temperatureIN[1]/10, temperatureIN[1]%10); ST7735_DrawStringHorizontal(12, 30, tempString, ST7735_Color565(0, 0, 0), 2); ST7735_DrawCharS((12 + strlen(tempString)*2*6), 25, tempCharacter, ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1); //Write the new string sprintf(tempString, "%02d.%.1d", temperatureIN[0]/10, temperatureIN[0]%10); ST7735_DrawStringHorizontal(12, 30, tempString, ST7735_Color565(255, 0, 0), 2); ST7735_DrawCharS((12 + strlen(tempString)*2*6), 25, tempCharacter, ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1); temperatureIN[1] = temperatureIN[0]; tempCharacter[1] = tempCharacter[0]; } //If the new data value is different than the previous value, or the screen has been changes, update display if((humidityIN[0] != humidityIN[1]) || refreshValues == YES) { //Re-write the last string in black (the same color as the backgruond) to cover it up so that the // new value is not written overtop. sprintf(tempString, "%02d.%.1d", humidityIN[1]/10, humidityIN[1]%10); ST7735_DrawStringHorizontal(74, 30, tempString, ST7735_Color565(0, 0, 0), 2); ST7735_DrawCharS((74 + strlen(tempString)*2*6), 27, '%', ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1); //Write the new string sprintf(tempString, "%02d.%.1d", humidityIN[0]/10, humidityIN[0]%10); ST7735_DrawStringHorizontal(74, 30, tempString, ST7735_Color565(255, 0, 0), 2); ST7735_DrawCharS((74 + strlen(tempString)*2*6), 27, '%', ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1); humidityIN[1] = humidityIN[0]; } //========================================================================================================================== //If the new data value is different than the previous value, or the screen has been changes, update display if((temperatureOUT[0] != temperatureOUT[1]) || refreshValues == YES) { //Re-write the last string in black (the same color as the backgruond) to cover it up so that the // new value is not written overtop. sprintf(tempString, "%02d.%.1d", temperatureOUT[1]/10, temperatureOUT[1]%10); ST7735_DrawStringHorizontal(0, 70, tempString, ST7735_Color565(0, 0, 0), 2); ST7735_DrawCharS((0 + strlen(tempString)*2*6), 68, tempCharacter, ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1); //Write the new string sprintf(tempString, "%02d.%.1d", temperatureOUT[0]/10, temperatureOUT[0]%10); ST7735_DrawStringHorizontal(0, 70, tempString, ST7735_Color565(255, 0, 0), 2); ST7735_DrawCharS((0 + strlen(tempString)*2*6), 68, tempCharacter, ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1); temperatureOUT[1] = temperatureOUT[0]; tempCharacter[1] = tempCharacter[0]; } //If the new data value is different than the previous value, or the screen has been changes, update display if((humidityOUT[0] != humidityOUT[1]) || refreshValues == YES) { //Re-write the last string in black (the same color as the backgruond) to cover it up so that the // new value is not written overtop. sprintf(tempString, "%02d.%.1d", humidityOUT[1]/10, humidityOUT[1]%10); ST7735_DrawStringHorizontal(0, 90, tempString, ST7735_Color565(0, 0, 0), 2); ST7735_DrawCharS((0 + strlen(tempString)*2*6), 87, '%', ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1); //Write the new string sprintf(tempString, "%02d.%.1d", humidityOUT[0]/10, humidityOUT[0]%10); ST7735_DrawStringHorizontal(0, 90, tempString, ST7735_Color565(255, 0, 0), 2); ST7735_DrawCharS((0 + strlen(tempString)*2*6), 87, '%', ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1); humidityOUT[1] = humidityOUT[0]; } if((lux[0] != lux[1]) || refreshValues == YES) { //Re-write the last string in black (the same color as the backgruond) to cover it up so that the // new value is not written overtop. sprintf(tempString, "%d", lux[1]); ST7735_DrawStringHorizontal(0, 112, tempString, ST7735_Color565(0, 0, 0), 2); ST7735_DrawCharS((0 + strlen(tempString)*2*6), 112, 'L', ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1); //Write the new string sprintf(tempString, "%d", lux[0]); ST7735_DrawStringHorizontal(0, 112, tempString, ST7735_Color565(255, 0, 0), 2); ST7735_DrawCharS((0 + strlen(tempString)*2*6), 112, 'L', ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1); lux[1] = lux[0]; } //If the new data value is different than the previous value, or the screen has been changes, update display if((pressure[0] != pressure[1]) || refreshValues == YES) { //Re-write the last string in black (the same color as the backgruond) to cover it up so that the // new value is not written overtop. sprintf(tempString, "%d", pressure[1]); ST7735_DrawStringHorizontal(0, 135, tempString, ST7735_Color565(0, 0, 0), 2); ST7735_DrawStringHorizontal((0 + strlen(tempString)*2*6), 135, "Pa", ST7735_Color565(0, 0, 0), 1); //Write the new string sprintf(tempString, "%d", pressure[0]); ST7735_DrawStringHorizontal(0, 135, tempString, ST7735_Color565(255, 0, 0), 2); ST7735_DrawStringHorizontal((0 + strlen(tempString)*2*6), 135, "Pa", ST7735_Color565(255, 0, 0), 1); pressure[1] = pressure[0]; } //If the new data value is different than the previous value, or the screen has been changes, update display if((lightIndex[0] != lightIndex[1]) || refreshValues == YES) { //Re-write the last string in black (the same color as the backgruond) to cover it up so that the // new value is not written overtop. sprintf(tempString, "%s", lightIndexString[1]); ST7735_DrawStringVertical(105, 70, tempString, ST7735_Color565(0, 0, 0), 2); //Write the new string sprintf(tempString, "%s", lightIndexString[0]); ST7735_DrawStringVertical(105, 70, tempString, ST7735_Color565(0, 0, 255), 2); memcpy(lightIndexString[1], lightIndexString[0], sizeof(lightIndexString[0])); lightIndex[1] = lightIndex[0]; } refreshValues = NO; } //Check to see in the knob has been changed at all encoderValue = EncoderDecipher(&Encoder1, &Encoder2, &PushButton); //If encoder has been held, this indicates enting the setting of the RTC time if(encoderValue == HOLD) { Setup = YES; //Now that is this set high, the process will exit the while loop above //Set all varaibles to what is needed for editing the time and date memset(dateStringColor, 0xFFFF, sizeof(dateStringColor)); memset(timeStringColor, 0xFFFF, sizeof(timeStringColor)); dateStringColor[0] = ST7735_Color565(255, 0, 0); dateStringColor[1] = ST7735_Color565(255, 0, 0); dateStringColor[2] = ST7735_Color565(255, 0, 0); //Getting the current RTC values and put them into variables that will then used to manipulate sprintf(temp, "%x, %x, %x, %x, %x, %x", newTime.month, newTime.dayOfmonth, newTime.year, newTime.hours, newTime.minutes, newTime.seconds); sscanf(temp, "%d, %d, %d, %d, %d, %d", &date[0], &date[1], &date[2], &time[0], &time[1], &time[2]); //Fill the screen in all black ST7735_FillScreen(0); //Variable controlling the whether editing the time or date Top = YES; } //If the user turns the knob, change the screen variable and set the refreshValues high so that the screen will change for the user else if (encoderValue == RIGHT || encoderValue == LEFT) { if(screen == 1) { screen = 2; ST7735_FillScreen(0); //Clear screen refreshValues = YES; } else if(screen == 2) { screen = 1; ST7735_FillScreen(0); //Clear screen refreshValues = YES; } } //If the user just pressed the encoder (not holds it) change the temperature to be displayed in the opposite type else if(encoderValue == PRESS) { if(tempFormat == CEL) { tempFormat = FAR; tempCharacter[0] = 'F'; } else { tempFormat = CEL; tempCharacter[0] = 'C'; } } } //Keep process inside this loop while the encoder is not being touched while(!movement) { if(encoderRefresh) { //Getting the movement of the encoder movement = EncoderDecipher(Encoder1, Encoder2, PushButton); encoderRefresh = 0; } if(flag) { flag = 0; //Write the date and time strings for(i = 0; i < strlen(dateString); i++) { ST7735_DrawChar((11*i), 10, dateString[i], dateStringColor[i], 0x0000, 2); } for(i = 0; i < strlen(timeString); i++) { ST7735_DrawChar(22+(11*i), 40, timeString[i], timeStringColor[i], 0x0000, 2); } } } //Is user turned the knob right, increment withever value the user is editing if(movement == RIGHT) { flag = 1; if(Top) // Up { if(dateStringColor[1] == 31) { if(++date[0] > 11) date[0] = 0; } else if(dateStringColor[4] == 31) { if(++date[1] > 31) date[1] = 0; } else { if(++date[2] > 2050) date[2] = 1950; } } else { if(timeStringColor[1] == 31) { if(++time[0] > 24) time[0] = 0; } else if(timeStringColor[4] == 31) { if(++time[1] > 59) time[1] = 0; } else { if(++time[2] > 59) time[2] = 0; } } } //Is user turned the knob left, decrement withever value the user is editing if(movement == LEFT) { flag = 1; if(Top) // Up { if(dateStringColor[1] == 31) { if(--date[0] < 0) date[0] = 11; } else if(dateStringColor[4] == 31) { if(--date[1] < 0) date[1] = 31; } else { if(--date[2] < 1950) date[2] = 2050; } } else { if(timeStringColor[1] == 31) { if(--time[0] < 0) time[0] = 23; } else if(timeStringColor[4] == 31) { if(--time[1] < 0) time[1] = 59; } else { if(--time[2] < 0) time[2] = 59; } } } //Is user presses the right, swith which what is highlighted, to indicate to the user //what is being edited if(movement == PRESS) { flag = 1; if(Top) // XXX XX XXXX { if(dateStringColor[1] == 31) { memset(dateStringColor, 0xFFFF, sizeof(dateStringColor)); dateStringColor[4] = ST7735_Color565(255, 0, 0); dateStringColor[5] = ST7735_Color565(255, 0, 0); } else if(dateStringColor[4] == 31) { memset(dateStringColor, 0xFFFF, sizeof(dateStringColor)); dateStringColor[7] = ST7735_Color565(255, 0, 0); dateStringColor[8] = ST7735_Color565(255, 0, 0); dateStringColor[9] = ST7735_Color565(255, 0, 0); dateStringColor[10] = ST7735_Color565(255, 0, 0); } else if(dateStringColor[8] == 31) { memset(dateStringColor, 0xFFFF, sizeof(dateStringColor)); memset(timeStringColor, 0xFFFF, sizeof(timeStringColor)); timeStringColor[0] = ST7735_Color565(255, 0, 0); timeStringColor[1] = ST7735_Color565(255, 0, 0); Top = NO; } } else //XX XX XX { if(timeStringColor[1] == 31) { memset(timeStringColor, 0xFFFF, sizeof(timeStringColor)); timeStringColor[3] = ST7735_Color565(255, 0, 0); timeStringColor[4] = ST7735_Color565(255, 0, 0); } else if(timeStringColor[4] == 31) { memset(timeStringColor, 0xFFFF, sizeof(timeStringColor)); timeStringColor[6] = ST7735_Color565(255, 0, 0); timeStringColor[7] = ST7735_Color565(255, 0, 0); } else if(timeStringColor[7] == 31) { memset(timeStringColor, 0xFFFF, sizeof(timeStringColor)); dateStringColor[0] = ST7735_Color565(255, 0, 0); dateStringColor[1] = ST7735_Color565(255, 0, 0); dateStringColor[2] = ST7735_Color565(255, 0, 0); Top = YES; } } } //Update the new time and date strings sprintf(dateString, "%s %02d,%d", months[date[0]], date[1], date[2]); sprintf(timeString, "%02d:%02d:%02d", time[0], time[1], time[2]); //If used holds the encoder down, the time and date will be written to the RTC and the process will return //to the top where the temp, humid... data is diplayed. Editing the time/date is exited. if(movement == HOLD) { if(!Setup) { //Setting new time Setup = 1; flag = 1; if(dateStringColor[0] == 31 || dateStringColor[4] == 31 || dateStringColor[8] == 31 || timeStringColor[0] == 31 || timeStringColor[4] == 31 || timeStringColor[7] == 31) { memset(timeStringColor, 0xFFFF, sizeof(timeStringColor)); memset(dateStringColor, 0xFFFF, sizeof(dateStringColor)); } else { memset(dateStringColor, 0xFFFF, sizeof(dateStringColor)); memset(timeStringColor, 0xFFFF, sizeof(timeStringColor)); dateStringColor[0] = ST7735_Color565(255, 0, 0); dateStringColor[1] = ST7735_Color565(255, 0, 0); dateStringColor[2] = ST7735_Color565(255, 0, 0); Top = YES; } } else //Exiting setup { //Setup new time into system. Exiting setup Setup = 0; tick = 1; memset(dateStringColor, 0xFFFF, sizeof(dateStringColor)); memset(timeStringColor, 0xFFFF, sizeof(timeStringColor)); //Set the values (in the correct type) back into the RTC structure so that it can be updated. sprintf(temp, "%d, %d, %d, %d, %d, %d", date[0], date[1], date[2], time[0], time[1], time[2]); sscanf(temp, "%x, %x, %x, %x, %x, %x", &setTime.month, &setTime.dayOfmonth, &setTime.year, &setTime.hours, &setTime.minutes, &setTime.seconds); //Set the RTC with the values the uset chose MAP_RTC_C_initCalendar(&setTime, RTC_C_FORMAT_BCD); MAP_RTC_C_startClock(); //Clear screen ST7735_FillScreen(0); } } movement = NONE; } }