/***************************************************************************//** * @brief Sends a string to ST7579 controller. * * @param yPosition - Y address of RAM. * @param xPosition - X address of RAM. * @param string - The string. * @param bigFont - Big font selection. * * @return None. *******************************************************************************/ void ST7579_String(unsigned char yPosition, unsigned char xPosition, unsigned char* string, unsigned char bigFont) { while(*string) { /* Send each character of the string. */ ST7579_Char(yPosition, xPosition, *string++, bigFont); xPosition += 6 + (bigFont * 12); } }
/***************************************************************************//** * @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); } } }