Missing DEFINES (0.5p)¶
We are working with screen register similar to the one you have seen in Bitwise operations.
We have created a library with two functions: one that writes data to LCD (modify the values of bit 10-3 and clear the R/W bit, that is, set to 0 the bit 1) and other that reset the LCD (hence sets RS bit, that is, put 1 in the bit 0 of the registry). The code is as follows:
#include <stdio.h>
#include <stdint.h>
void write_data_to_LCD(uint16_t* lcd_register, uint8_t data);
void reset_LCD(uint16_t* lcd_register);
// Write data to the LCD
void write_data_to_LCD(uint16_t* lcd_register,uint8_t data) {
// Clear previous data
*lcd_register = *lcd_register & ~DATA_MASK;// 0b0000011111111000
// Set the new data
*lcd_register = *lcd_register | ((uint16_t)data << 3);
// Clear the R/W bit to indicate we are in a writing operation
CLEAR(*lcd_register,RW_BIT);
}
// Reset the LCD. It needs to put to 1 the Reset bit
void reset_LCD(uint16_t* lcd_register) {
SET(*lcd_register,RESET_BIT);
}
// Write data on the LCD and then reset it.
int main() {
uint16_t lcd_register = 0x00C8;
write_data_to_LCD(&lcd_register,0x19);
printf("Writen data to LCD. LCD register contain: %#06X \n",lcd_register);
reset_LCD(&lcd_register);
printf("Resetting register. LCD register contain: %#06X \n",lcd_register);
return 0;
}
We were using an old library, which defined the macros for
CLEAR
, SET
and the constants definitions for DATA_MASK
, RW_BIT
and RESET_BIT
. The library file got corrupted, we cannot open anymore, and we do not have a backup (yes, I know this is a very big neglicence). We would like that you create the missing macros and constants (defines) and add them to the code. We do not mind that you write macro that can be used to set and clear any bit in a register, or macros that are specific for this particular case. The important thing is that the code works.
We have found some notes of the previous developer that might help you:
//SET TO WRITE MODE: CLEAR THE RW bit (RW -> 0) uint16_t MASK_RS = 0x01;0b0000 0000 0000 0001 uint16_t MASK_RW = 0x02;0b0000 0000 0000 0010 uint16_t lcd = 0x024F; lcd = lcd & ~MASK_RW. //I think i could use the &= operator instead.
//RESET THE LCD: SET THE RS BIT (RS -> 1) uint16_t MASK_RS = 0x01;0b0000 0000 0000 0001 uint16_t MASK_RW = 0x02;0b0000 0000 0000 0010 uint16_t lcd = 0x024F; lcd = lcd | MASK_RS // I think I could use the |= operator instead
You must return a file, containing the full code, including the missing macros and constants definitions. You cannot modify anything else in the code. Just create the macros.
HINT: Explore the slides of the course.
Hints
Messages