7 Segment Displays

​   //—– 7 SEGMENT DISPLAYS —– //D0=a | D6=g #define DISPLAY_7_SEG_0 0b00111111 #define DISPLAY_7_SEG_1 0b00000110 #define DISPLAY_7_SEG_2 0b01011011 #define DISPLAY_7_SEG_3 0b01001111 #define DISPLAY_7_SEG_4 0b01100110 #define DISPLAY_7_SEG_5 0b01101101 #define DISPLAY_7_SEG_6 0b01111100 #define DISPLAY_7_SEG_7 0b00000111 #define DISPLAY_7_SEG_8 0b01111111 #define DISPLAY_7_SEG_9 0b01100111 #define DISPLAY_7_SEG_HYPHEN 0b01000000 #define DISPLAY_7_SEG_E 0b01111001 #define DISPLAY_7_SEG_N 0b01010100 #define DISPLAY_7_SEG_0_180 0b00111111 #define DISPLAY_7_SEG_1_180 0b00110000 […]

Read More →

Typedef Union

typedef union _WORD_VAL { WORD val; struct { BYTE LSB; BYTE MSB; } byte; BYTE v[2]; } WORD_VAL; # = ((DWORD_VAL) address).v[1])

Read More →

Typedef For State Machines

typedef enum _SM_USER_MODE { SM_POWERUP, SM_ONLINE, SM_OFFLINE, SM_IDENTIFY } SM_USER_MODE; Example Usage typedef enum _SM_USER_MODE { SM_POWERUP, SM_IDLE } SM_USER_MODE; void my_function (void) { static int user_mode = SM_POWERUP; static int user_mode_last = ~SM_POWERUP; BYTE this_is_new_mode = 0; //—– CHECK FOR THIS IS NEW MODE —– if (user_mode_last != user_mode) { this_is_new_mode = 1; user_mode_last […]

Read More →

Constants

Float A value with decimal places is interpreted as double by default. Use f to specify as float literal, e,g, Unsigned ‘u’ or ‘U’ to indicate an unsigned constant, like 33u‘ul’ or ‘UL’ to indicate an unsigned long constant, like 32767ul

Read More →

AtoD conversion

Converting Direct Voltage Value Converting Based On A Voltage Reference Reading Converting Voltage Value After Potential Divider Resistors

Read More →

Rounding values

rint() Round to nearest integer (int) does not round values correctly!!!!!Converting a value with decimal places to an int using (int) will convert ignoring the decimal places completly. If you want a value of say 5.6 to convert to and int of 6 and not 5 then use: (int)rint() The rint() function rounds a double […]

Read More →

Exponent

^ is the character for Exponent (EXP on a calculator) In C you use pow() pow(base, exponent) In C you can use exponents in two places. Firstly, where numbers are so large or so small that decimal point notation is not human-readable. For instance 100,000,000,000 is best written as 1 * 10 ^11. Secondly where […]

Read More →

Typedef, struct union

Typedef Union For Different Definitions Of The Same Memory Locations typedef union _SYSTEM_CONFIGURATION_TYPEDEF { DWORD dw[25]; WORD w[50]; BYTE b[100]; } SYSTEM_CONFIGURATION_TYPEDEF; SYSTEM_CONFIGURATION_TYPEDEF system_config_buffer; system_config_buffer.b[0] = 1; system_config_buffer.b[1] = 2; system_config_buffer.b[2] = 3; system_config_buffer.b[3] = 4; system_config_buffer.b[4] = 5; //Will give: //system_config_buffer.w = 0x0201 //system_config_buffer.dw = 0x04030201 Typedef Struct typedef struct _TEST_HEADER { WORD source_port; […]

Read More →