From f57da717c82b46fe32dfdbe3c220a08e51c24f43 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 17 May 2008 16:33:31 +0000 Subject: seven-segment display --- 7seg.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 6 +++++ 2 files changed, 82 insertions(+) create mode 100644 7seg.c create mode 100644 Makefile diff --git a/7seg.c b/7seg.c new file mode 100644 index 0000000..1339065 --- /dev/null +++ b/7seg.c @@ -0,0 +1,76 @@ +/* $Id$ */ +/* + * Copyright (c) 2005 Dimitri Sokolyuk + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +/* + * _ a + * |_| bcd + * |_| efg + * + * ~abcdefg ~gfedcba + * 0 01101111 0x6F 01111011 0x7B + * 1 00001001 0x09 01001000 0x48 + * 2 01011110 0x5E 00111101 0x3D + * 3 01011011 0x5B 01101101 0x6D + * 4 00111001 0x39 01001110 0x4E + * 5 01110011 0x73 01100111 0x67 + * 6 01110111 0x77 01110111 0x77 + * 7 01001001 0x49 01001001 0x49 + * 8 01111111 0x7F 01111111 0x7F + * 9 01111011 0x7B 01101111 0x6F + * + */ + +const char seg[] = { + 0x7B, 0x48, 0x3D, 0x6D, 0x4E, + 0x67, 0x77, 0x49, 0x7F, 0x6F +}; + +const char sym[] = "_|_||_|"; + +int +main(int argc, char **argv) +{ + int i, j; + char *c; + + if ((c = argv[1]) == NULL) + return(-1); + + for (i = 0; i < 3; i++) { + do { + if (*c < '0' || *c > '9') + continue; + if (i == 0) + putchar(' '); + for (j = 0; j < 3; j++) { + putchar(seg[*c - '0'] & 1 << i * i + j ? + sym[i * i + j] : ' '); + if (i == 0) { + putchar(' '); + break; + } + } + } while (*++c); + putchar('\n'); + c = argv[1]; + } + putchar('\n'); + + return(0); +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef9d3ad --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +# $Id$ + +PROG= 7seg +NOMAN= + +.include -- cgit v1.2.3