15 #define HW_REGS_BASE ( ALT_STM_OFST )
16 #define HW_REGS_SPAN ( 0x04000000 )
17 #define HW_REGS_MASK ( HW_REGS_SPAN - 1 )
43long long decimalValue;
65static const char *digitChar(
char A) {
118static char *dectobcd7bin(
char * buf,
int ABCD) {
132 char outputChar[50] =
"";
136 printf(
"ABCD > 999999\n ERROR");
142 sprintf(inputChar,
"%06d", ABCD);
146 for (
int i = 0; i < 6; i++) {
147 strcat(outputChar, digitChar(inputChar[i]));
150 strncpy(buf, outputChar, 50);
174 char outputChar[50] =
"";
177 memset(outputChar, 0, 50);
178 if ((ABCD > 999999) || (ABCD < 0)) {
180 printf(
"FAILURE, input ABCD n dectodec7 is greater than 999999");
182 const char* binaryOutput = dectobcd7bin(outputChar, ABCD);
187 decimalValue = strtoll(binaryOutput, NULL, 2);
220 char arrayLeftTotal[50];
221 memset(arrayLeftTotal, 0, 50);
222 const char* binaryOutput2 = dectobcd7bin(arrayLeftTotal, ABCD);
225 strncpy (arrayLeft, binaryOutput2, 16);
228 decimalValue = strtoll(arrayLeft, NULL, 2);
247void test7segDigitChar() {
250 assert(digitChar(
'0') ==
"00111111");
251 assert(digitChar(
'1') ==
"00000110");
252 assert(digitChar(
'2') ==
"01011011");
253 assert(digitChar(
'3') ==
"01001111");
254 assert(digitChar(
'4') ==
"01100110");
255 assert(digitChar(
'5') ==
"01101101");
256 assert(digitChar(
'6') ==
"01111101");
257 assert(digitChar(
'7') ==
"00000111");
258 assert(digitChar(
'8') ==
"01111111");
259 assert(digitChar(
'9') ==
"01101111");
262 assert(digitChar(
'a') ==
"X");
263 assert(digitChar(
'#') ==
"X");
264 assert(digitChar(
' ') ==
"X");
265 assert(digitChar(
'\n') ==
"X");
266 assert(digitChar(
'-') ==
"X");
269 assert(digitChar(
'9') ==
"01101111");
270 assert(digitChar(
'9' + 1) ==
"X");
281void testDectobcd7bin() {
286 assert(strcmp(dectobcd7bin(
buffer, 999999),
"011011110110111101101111011011110110111101101111") == 0);
289 assert(strcmp(dectobcd7bin(
buffer, 1000000),
"FAILURE") == 0);
293 assert(strcmp(dectobcd7bin(
buffer, 0),
"001111110011111100111111001111110011111100111111") == 0);
296 assert(strcmp(dectobcd7bin(
buffer, 123456),
"000001100101101101001111011001100110110101111101") == 0);
299 assert(strcmp(dectobcd7bin(
buffer, 888888),
"011111110111111101111111011111110111111101111111") == 0);
302 assert(strcmp(dectobcd7bin(
buffer, 1000001),
"FAILURE") == 0);
305 assert(strcmp(dectobcd7bin(
buffer, 5),
"001111110011111100111111001111110011111101101101") == 0);
317 void testDectoDec7() {
324 assert(
dectodec7(123456) == 6989243903357);
328 assert(
dectodec7(999999) == 122524401626991);
332 assert(
dectodec7(111111) == 6622940628486);
340 assert(
dectodec7(100000) == 6868713815871);
343 assert(
dectodec7(359977) == 87331439576839);
353 void testLeftDec2Dec7() {
387 printf(
"All test cases passed successfully within 7-segment\n");
void * LW_virtual
Used to map physical addresses for the light-weight bridge Not made by Erick Grant,...
void * virtual_base
Base for the LCD Used to define the address of the LCD.
int fd
Used to open /dev/mem for access to physical addresses Not made by Erick Grant, copyright Terasic Inc...
long long leftDec2Dec7(int ABCD)
long long dectodec7(int ABCD)