/***************************************************************************//** * @brief Main function. * * @return None. *******************************************************************************/ void main(void) { /* Initialize RDKRL78G14. */ RDKRL78G14_Init(); /* Enable interrupts. */ __enable_interrupt(); /* Initialize timer. */ TIME_Init(); /* Initialize the ST7579 Display. */ ST7579_Init(); /* Initialize AD7476. */ if(AD74xx_Init(AD7476) == 0) { ADI_Component("AD7476 OK"); } else { ADI_Component("AD7476 Error"); } ST7579_String(2, 0, "Conversion", 0); ST7579_String(3, 0, "Result A0:", 0); ST7579_String(5, 0, "HEX:", 0); ST7579_String(6, 0, "DEC:", 0); ST7579_String(7, 0, "VOLT:", 0); while(1) { /* Power up the device.*/ AD74xx_PowerUp(); /* Acquire one sample.*/ sample = AD74xx_GetRegisterValue(); /* Power down device while other tasks are being executed. */ AD74xx_PowerDown(); /* Convert the sample in voltage. */ voltage = AD74xx_ConvertToVolts(sample, 3.3); /* Display the value. */ ST7579_String(5, 36, " ", 0); ST7579_HexNumber(5, 36, sample, 0); ST7579_String(6, 36, " ", 0); ST7579_Number(6, 36, sample, 0); ST7579_String(7, 36, " ", 0); ST7579_FloatNumber(7, 36, voltage, 2, 0); /* Wait for 300 milliseconds. */ TIME_DelayMs(300); } }
/***************************************************************************//** * @brief Draws the ADI logo and displays the name of ADI component. * * @param componentName - The name of the ADI component. * * @return None. *******************************************************************************/ void ADI_Component(unsigned char* string) { const unsigned char adiComponent[7] = { 0xFE, 0xFE, 0x82, 0xC6, 0xEE, 0xFE, 0xFE }; ST7579_Image(0, 0, adiComponent, 7, 8); ST7579_String(0, 9, string, 0); }
/***************************************************************************//** * @brief Sends an integer number to ST7579 controller. * * @param yPosition - Y address of RAM. * @param xPosition - X address of RAM. * @param number - The number. * @param bigFont - Big font selection. * * @return None. *******************************************************************************/ void ST7579_Number(unsigned char yPosition, unsigned char xPosition, long number, unsigned char bigFont) { unsigned long mask = 1000000000; unsigned char chNumber = 10; unsigned char chIndex = 0; //bigFont = 0; if(number < 0) { ST7579_Char(yPosition, xPosition, '-', bigFont); xPosition += 6 + (bigFont * 12); number *= -1; } else { if(number == 0) { ST7579_String(yPosition, xPosition, " 0", bigFont); } else { ST7579_Char(yPosition, xPosition, '+', bigFont); xPosition += 6 + (bigFont * 12); } } while(mask > number) { mask /= 10; chNumber--; } for(chIndex = 0; chIndex < chNumber; chIndex++) { ST7579_Char(yPosition, xPosition, ((number / mask) % 10) + 0x30, bigFont); mask /= 10; xPosition += 6 + (bigFont * 12); } }
/***************************************************************************//** * @brief Sends an integer number in Hexa format to ST7579 controller. * * @param yPosition - Y address of RAM. * @param xPosition - X address of RAM. * @param number - The number. * @param bigFont - Big font selection. * * @return None. *******************************************************************************/ void ST7579_HexNumber(unsigned char yPosition, unsigned char xPosition, long number, unsigned char bigFont) { unsigned long long mask = 268435456; unsigned char chNumber = 8; unsigned char chIndex = 0; unsigned char display = 0; ST7579_String(yPosition, xPosition, "0x", bigFont); xPosition += (6 + (bigFont * 12)) * 2; if(number == 0) { ST7579_Char(yPosition, xPosition, '0', bigFont); } while(mask > number) { mask /= 16; chNumber--; } for(chIndex = 0; chIndex < chNumber; chIndex++) { display = (number / mask) % 16; mask /= 16; if(display <= 9) { display += 0x30; } else { display += 0x37; } ST7579_Char(yPosition, xPosition, display, bigFont); xPosition += 6 + (bigFont * 12); } }
/***************************************************************************//** * @brief Main function. * * @return None. *******************************************************************************/ void main(void) { /* Initialize RDKRL78G14. */ RDKRL78G14_Init(); /* Enable interrupts. */ __enable_interrupt(); /* Initialize timer. */ TIME_Init(); /* Initialize the ST7579 Display. */ ST7579_Init(); /* Init ADP5589 device. */ if(ADP5589_Init() == 0) { ADI_Component("ADP5589 OK"); } else { ADI_Component("ADP5589 Error"); } /* Init ADP5589 as keyboard decoder on J1 connector. */ ADP5589_InitKey(PMOD_IOXP_J1); /* Init PWM on pin R3. */ ADP5589_InitPwm(); ADP5589_SetPwm(1, 1); ST7579_String(3, 10, "Press 1A", 0); ST7579_String(4, 10, "to unlock", 0); /* Lock keypad, press 1A to unlock. */ ADP5589_KeyLock(0x25, 0x04, PMOD_IOXP_J1); ST7579_String(2, 10, " ", 0); ST7579_String(3, 10, " ", 0); ST7579_String(7 ,0, "R3: 0.5Mhz PWM ", 0); ADP5589_GpioDirection(ADP5589_ADR_GPIO_DIRECTION_A, 0xFE); while(1) { /* Read the value of FIFO1 register. */ val = ADP5589_GetRegisterValue(ADP5589_ADR_FIFO1); /* Decode the last key pressed. */ keyP = ADP5589_KeyDecode(val, ADP5589_EVENT_KEY_PRESSED, PMOD_IOXP_J1); /* Decode the last key released. */ keyR = ADP5589_KeyDecode(val, ADP5589_EVENT_KEY_RELEASED, PMOD_IOXP_J1); /* Display the last key pressed. */ ST7579_String(2, 0, "Last Pressed", 0); ST7579_String(3, 0, "Key: ", 0); if (keyP != 'x') { ST7579_Char(3, 30, keyP, 0); } /* Display the last key released. */ ST7579_String(4, 0, "Last Released", 0); ST7579_String(5, 0, "Key: ", 0); if (keyR != 'x') { ST7579_Char(5, 30, keyR, 0); } /* Read and display the status of R0 pin. */ if(ADP5589_GetPinState(ADP5589_ADR_GPI_STATUS_A) & 0x01) { ST7579_String(6, 0, "R0 is HIGH", 0); } else { ST7579_String(6, 0, "R0 is LOW ", 0); } } }
/***************************************************************************//** * @brief Sends a float number to ST7579 controller. * * @param yPosition - Y address of RAM. * @param xPosition - X address of RAM. * @param number - The number. * @param resolution - Float resolution. * @param bigFont - Big font selection. * * @return None. *******************************************************************************/ void ST7579_FloatNumber(unsigned char yPosition, unsigned char xPosition, float number, unsigned char resolution, unsigned char bigFont) { unsigned long mask = 1000000000; unsigned char chNumber = 10; unsigned char index = 0; long display = 1; long multiplication = 1; for(index = 0; index < resolution; index++) { multiplication *= 10; } display = (long)(number * multiplication); if(display < 0) { ST7579_Char(yPosition, xPosition, '-', bigFont); xPosition += 6 + (bigFont * 12); number *= -1; } else { if(display == 0) { xPosition += 6 + (bigFont * 12); ST7579_Char(yPosition, xPosition, '0', bigFont); xPosition += 6 + (bigFont * 12); if(resolution) { ST7579_Char(yPosition, xPosition, '.', bigFont); xPosition += 6 + (bigFont * 12); } for(index = 0; index < resolution; index++) { ST7579_Char(yPosition, xPosition, '0', bigFont); xPosition += 6 + (bigFont * 12); } } else { ST7579_Char(yPosition, xPosition, '+', bigFont); xPosition += 6 + (bigFont * 12); } } while(mask > display) { mask /= 10; chNumber--; } if((display > 0) && (display < multiplication)) { ST7579_String(yPosition, xPosition, "0.", bigFont); xPosition += 12 + (bigFont * 24); } for(index = 0; index < chNumber; index++) { ST7579_Char(yPosition, xPosition, ((display / mask) % 10) + 0x30, bigFont); mask /= 10; xPosition += 6 + (bigFont * 12); if((multiplication != 1) && (mask == (multiplication / 10))) { ST7579_Char(yPosition, xPosition, '.', bigFont); xPosition += 6 + (bigFont * 12); } } }
/***************************************************************************//** * @brief Main function. * * @return None. *******************************************************************************/ void main(void) { /* Set pin 7 and pin 8 (J11 connector) as input, to avoid the output pins of the Pmod ACL to be connected to an output pin of the microcontroller. */ PM7 |= (1 << 6); // P76 (PMOD-IRQA) PM7 |= (1 << 7); // P77 (PMOD-IRQB) /* Initialize RDKRL78G14. */ RDKRL78G14_Init(); /* Enable interrupts. */ __enable_interrupt(); /* Initialize timer. */ TIME_Init(); /* Initialize the ST7579 Display. */ ST7579_Init(); /* Initialize ADXL345. */ if(ADXL345_Init(ADXL345_SPI_COMM) == 0) { ADI_Component("ADXL345 OK"); } else { ADI_Component("ADXL345 Error"); } ADXL345_SetTapDetection(ADXL345_SINGLE_TAP | ADXL345_DOUBLE_TAP, // Tap type. ADXL345_TAP_Z_EN, // Axis control. 0x10, // Tap duration. 0x10, // Tap latency. 0x40, // Tap window. 0x10, // Tap threshold. 0x00); // Interrupt Pin. ADXL345_SetFreeFallDetection(0x01, // Free-fall detection enabled. 0x05, // Free-fall threshold. 0x14, // Time value for free-fall detection. 0x00); // Interrupt Pin. /* Set the range and the resolution. */ ADXL345_SetRangeResolution(ADXL345_RANGE_PM_4G, ADXL345_FULL_RES); ADXL345_SetPowerMode(0x1); // Measure mode. while(1) { /* Read and display the output data of each axis. */ ADXL345_GetGxyz(&x, &y, &z); ST7579_String(2, 0, "X data: [g]", 0); ST7579_FloatNumber(2, 42, x, 3, 0); ST7579_String(3, 0, "Y data: [g]", 0); ST7579_FloatNumber(3, 42, y, 3, 0); ST7579_String(4, 0, "Z data: [g]", 0); ST7579_FloatNumber(4, 42, z, 3, 0); intSource = ADXL345_GetRegisterValue(ADXL345_INT_SOURCE); if((intSource & ADXL345_SINGLE_TAP) != 0) { ST7579_String(5, 0, "Single Tap", 0); } if((intSource & ADXL345_DOUBLE_TAP) != 0) { ST7579_String(6, 0, "Double Tap", 0); } if((intSource & ADXL345_FREE_FALL) != 0) { ST7579_String(7, 0, "Free-Fall", 0); } TIME_DelayMs(100); } }