void display_init(void) { SPI_set_sample_rising_edge(); /* Disable shutdown mode */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_SHUTDOWN); SPI_send(0x1); SPI_deselect(SPI_CS_MAX7221); /* Disable display test mode */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_DISPLAY_TEST); SPI_send(0x0); SPI_deselect(SPI_CS_MAX7221); /* Set the decoding mode to Code-B font for all digits */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_DECODE_MODE); SPI_send(0xFF); SPI_deselect(SPI_CS_MAX7221); /* Set the display intensity */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_INTENSITY); SPI_send(0xF); SPI_deselect(SPI_CS_MAX7221); /* Set the scan limit to include all 8 digits */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_SCAN_LIMIT); SPI_send(0x07); SPI_deselect(SPI_CS_MAX7221); }
/** Transforms the humidity value given in percent relative humidity into decimal digits and sends the information to the 7-segment display controller. The display is updated when the chip select signal is deactivated. \param humidity Integer that represents relative humidity in percent. */ void display_humidity(uint8_t humidity) { SPI_set_sample_rising_edge(); /* Values of each of the 3 digits */ uint8_t digit [3]; /* Determine the value of each digit */ int8_t tmp; tmp = humidity / 10; digit[2] = humidity - 10 * tmp; humidity = tmp; tmp = humidity / 10; digit[1] = humidity - 10 * tmp; humidity = tmp; tmp = humidity / 10; digit[0] = humidity - 10 * tmp; /* Eliminate leading zeros */ if (digit[0] == 0) { digit[0] = DISPLAY_CODE_B_BLANK; if (digit[1] == 0) { digit[1] = DISPLAY_CODE_B_BLANK; } } /* Send the SPI commands */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_DIGIT_5); SPI_send(digit[0]); SPI_deselect(SPI_CS_MAX7221); SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_DIGIT_6); SPI_send(digit[1]); SPI_deselect(SPI_CS_MAX7221); SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_DIGIT_7); SPI_send(digit[2]); SPI_deselect(SPI_CS_MAX7221); }
void SPI_select(int dev) { SPI_deselect(); switch(dev) { case MEMCS: ClearPin(PORTB, MEM_SEL); break; case VSXCS: ClearPin(PORTD, VS_XCS); break; case VSXDCS: ClearPin(PORTD, VS_XDCS); break; } }
// Initializes mem card char MEM_init() { char val; mem_bus_granted = 0; // acquire the SPI bus and other necesary signals val = MEM_acquireControl(); if(val) return(val); // reset to known idle state // assert reset, wait and deassert reset ClearPin(PORTC, MEM_RESET); delay(1); SetPin(PORTC, MEM_RESET); // get memory status // select memory SPI_select(MEMCS); // read status register SPI_send(READ_STATUS_REGISTER); // get return value val = SPI_receive(0x00); SPI_deselect(); if(((val >> 2) & 0x0f) == 0x0f) { if(!(val & 0x01)) { MEM.mem_size = 8650752; MEM.page_size = 1056; } else { blinkLED(10); } MEM.fbell_offset = MEM.page_size; MEM.rbell_offset = MEM.mem_size / 2; } else
/** Transforms the given temperature that is represented as degrees Celsius times 100 into decimal digits in preparation for display. Then it transfers the information to the 7-segment display controller. The display is updated as soon as the chip select signal is deactivated. \param temperature Integer that represents temperature in Celsius multiplied by the factor 100. */ void display_temperature(int16_t temperature) { SPI_set_sample_rising_edge(); /* Values of each of the 5 digits */ uint8_t digit [5]; /* Test for negativity */ if (temperature < 0) { temperature = -temperature; digit[0] = DISPLAY_CODE_B_MINUS; } else { digit[0] = DISPLAY_CODE_B_BLANK; } /* Determine the value of each digit */ int16_t tmp; tmp = temperature / 10; digit[4] = temperature - 10 * tmp; temperature = tmp; tmp = temperature / 10; digit[3] = temperature - 10 * tmp; temperature = tmp; tmp = temperature / 10; digit[2] = temperature - 10 * tmp; digit[2] |= DISPLAY_CODE_DECIMAL_POINT; temperature = tmp; tmp = temperature / 10; digit[1] = temperature - 10 * tmp; /* Eliminate leading zeros */ if (digit[1] == 0) { /* The 0th digit may contain a minus sign */ digit[1] = digit[0]; digit[0] = DISPLAY_CODE_B_BLANK; } /* Send the SPI commands for digit 0 */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_DIGIT_0); SPI_send(digit[0]); SPI_deselect(SPI_CS_MAX7221); /* Send the SPI commands for digit 1 */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_DIGIT_1); SPI_send(digit[1]); SPI_deselect(SPI_CS_MAX7221); /* Send the SPI commands for digit 2 */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_DIGIT_2); SPI_send(digit[2]); SPI_deselect(SPI_CS_MAX7221); /* Send the SPI commands for digit 3 */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_DIGIT_3); SPI_send(digit[3]); SPI_deselect(SPI_CS_MAX7221); /* Send the SPI commands for digit 4 */ SPI_select(SPI_CS_MAX7221); SPI_send(DISPLAY_REG_DIGIT_4); SPI_send(digit[4]); SPI_deselect(SPI_CS_MAX7221); }