Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
bitmask2
//gcc 7.4.0 #include <stdio.h> #include <stdbool.h> typedef struct { bool bit7:1; bool bit6:1; bool bit5:1; bool bit4:1; bool bit3:1; bool bit2:1; bool bit1:1; bool bit0:1; } bitmask; int main(void) { unsigned int voltage_word = 0; unsigned char reg13 = 0; unsigned char reg14 = 0; unsigned char new_high_byte = 0; unsigned char new_low_byte = 0; enum byte {bit0_pos, bit1_pos, bit2_pos, bit3_pos, bit4_pos, bit5_pos, bit6_pos, bit7_pos} ; printf("bit2_pos %i \r\n", bit2_pos); // calculate voltage word voltage_word = 0x02A5; printf("voltage_word: [0x%04X] \r\n", voltage_word); // shift left 1 bit printf("voltage_word_shifted: [0x%04X] \r\n", (voltage_word << 1) ); // break word into high byte and low byte printf("voltage high/low bytes: [0x%02X] [0x%02X]\r\n", ((voltage_word << 1) >> 8), (((voltage_word << 1) << 8) >> 8) ); // read current high byte & 0x07 to mask off correct bits then | calculated high byte reg13 = 0xA0; // current high byte new_high_byte = (reg13 & 0xF8) | ((voltage_word << 1) >> 8); // read current low byte & 0x01 to mask off correct bits then | calulated low byte reg14 = 0x0D6; // current low byte new_low_byte = (reg14 & 0x01) | ((voltage_word << 1) << 8) >> 8; printf("current value: [0x%02X] [0x%02X]\r\n", reg13, reg14); printf("new value: [0x%02X] [0x%02X]\r\n", new_high_byte, new_low_byte); return 0; }
run
|
edit
|
history
|
help
0
B_141205_funciones
Day 2 String Manipulation
B_141202_funcionesString
Busqueda binaria version recursiva
quicksort guía 4
PointerFunct
FUNTION 2
pruebapi2
polymorphism simulation in plain C with a simple structures
CpointfunProd