00001 /* 00002 00003 Copyright (c) 2010, Embedded Adventures, www.embeddedadventures.com 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are met: 00008 00009 - Redistributions of source code must retain the above copyright notice, 00010 this list of conditions and the following disclaimer. 00011 00012 - Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in the 00014 documentation and/or other materials provided with the distribution. 00015 00016 - Neither the name of Embedded Adventures nor the names of its contributors 00017 may be used to endorse or promote products derived from this software 00018 without specific prior written permission. 00019 00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00024 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 00030 THE POSSIBILITY OF SUCH DAMAGE. 00031 00032 Contact us at admin@embeddedadventures.com 00033 00034 */ 00035 00041 #include "sure_7seg.h" 00042 00043 void sure_7seg_setup() { 00044 spi_setup(); 00045 } 00046 00047 00048 uns8 sure_7seg_convert(uns8 digit) { 00049 switch (digit) { 00050 case ' ': return 0; 00051 case '0': return 0xfc; 00052 case '1': return 0x60; 00053 case '2': return 0xda; 00054 case '3': return 0xf2; 00055 case '4': return 0x66; 00056 case '5': return 0xb6; 00057 case '6': return 0xbe; 00058 case '7': return 0xe0; 00059 case '8': return 0xfe; 00060 case '9': return 0xf6; 00061 } 00062 } 00063 00064 void sure_7seg_write_str(char *data) { 00065 00066 uns8 count, digit; 00067 char converted[5]; 00068 00069 count = 0; 00070 do { 00071 digit = data[count]; 00072 converted[count] = sure_7seg_convert(digit); 00073 count++; 00074 } while (count < 4); 00075 spi_write_sure(converted[3]); 00076 spi_write_sure(converted[2]); 00077 spi_write_sure(converted[1]); 00078 spi_write_sure(converted[0]); 00079 00080 clear_pin(spi_clk_port, spi_clk_pin); // set to low 00081 set_pin(spi_clk_port, spi_clk_pin); // set to high 00082 00083 } 00084