int get_cursor_pos() { byte_out(SCREEN_CTRL, CLR_HIGH); int offset = byte_in(SCREEN_DATA) << 8; byte_out(SCREEN_CTRL, CLR_LOW); offset += byte_in(SCREEN_DATA); return offset; }
void set_cursor_pos(short x, short y) { int offset = get_screen_offset(x, y); byte_out(SCREEN_CTRL, CLR_HIGH); byte_out(SCREEN_DATA, (unsigned char) ( offset >> 8 ) ); byte_out(SCREEN_CTRL, CLR_LOW); byte_out(SCREEN_DATA, (unsigned char) offset); }
void eeprom_ByteWrite(uint16_t address, uint8_t data) { ACK_Poll(); // Begin ACK polling bstart(); // Generate Start condition byte_out(eeprom_control); // Output control byte byte_out((uint8_t)(address>>8));// Output address MSB byte_out((uint8_t)address); // Output address LSB byte_out(data); // Output data byte bstop(); // Generate Stop condition }
void eeprom_ByteRead(uint16_t address, uint8_t *data) { ACK_Poll(); // Begin ACK polling bstart(); // Generate Start condition byte_out(eeprom_control); // Output control byte byte_out((uint8_t)(address>>8));// Output address MSB byte_out((uint8_t)address); // Output address LSB bstart(); // Generate Start condition byte_out(eeprom_control | 0x01);// Output control byte *data = byte_in(NAKBIT); // Input data byte bstop(); // Generate Stop condition }
void eeprom_PageWrite(uint16_t address, uint8_t *data, uint8_t numbytes) { uint8_t i; // Loop counter ACK_Poll(); // Begin ACK polling bstart(); // Generate Start condition byte_out(eeprom_control); // Output control byte byte_out((uint8_t)(address>>8));// Output address MSB byte_out((uint8_t)address); // Output address LSB for (i = 0; i < numbytes; i++) // Loop through data bytes { byte_out(data[i]); // Output next data byte } bstop(); // Generate Stop condition }
/******************************************************************** * Function: void ACK_Poll(void) * * Description: This function implements Acknowledge polling. *******************************************************************/ void ACK_Poll(void) { uint8_t result; // Polling result result = 1; // Initialize result do { bstart(); // Generate Start condition result = byte_out(eeprom_control); // Output control byte } while (result == 1); bstop(); // Generate Stop condition }
void eeprom_SequentialRead(uint16_t address, uint8_t *data, uint16_t numbytes) { uint16_t i; // Loop counter ACK_Poll(); // Begin ACK polling bstart(); // Generate Start condition byte_out(eeprom_control); // Output control byte byte_out((uint8_t)(address>>8));// Output address MSB byte_out((uint8_t)address); // Output address LSB bstart(); // Generate Start condition byte_out(eeprom_control | 0x01);// Output control byte for (i = 0; i < numbytes; i++) // Loop through data bytes { if (i < (numbytes - 1)) // Check if more data will be read { data[i] = byte_in(ACKBIT); // If not last, input byte & send ACK } else { data[i] = byte_in(NAKBIT); // If last byte, input byte & send NAK } } bstop(); // Generate Stop condition }