7segtst.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 by Rittal GmbH & Co. KG,
00003  * Ulrich Prinz <prinz.u@rittal.de>
00004  *
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. Neither the name of the copyright holders nor the names of
00017  *    contributors may be used to endorse or promote products derived
00018  *    from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00027  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00028  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00029  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00030  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * For additional information see http://www.ethernut.de/
00034  */
00035 
00036 /*
00037  * \verbatim
00038  * $Id: 7segtst.c 3108 2010-09-15 21:11:15Z Astralix $
00039  * \endverbatim
00040  */
00041 
00042 /*
00043  * Revision 1.0  2009/04/13 ulrichprinz
00044  * First checkin, new twi driver for AS1108 3 Digit 7-Segment driver
00045  * (currently SAM7X256 is tested only)
00046  *
00047  */
00048 
00055 #include <cfg/os.h>
00056 #include <io.h>
00057 #include <stdio.h>
00058 
00059 #include <dev/board.h>
00060 #include <dev/spi_7seg.h>
00061 
00062 /* 7-Segment connection definition
00063  * correct these to the port and bus you use
00064  */
00065 
00066 /* SPI-Chipselect of the Display driver */
00067 #define NUT_CONFIG_7SEG_CS 1
00068 
00069 /* SPI-Bus the driver is connected to */
00070 #define NUT_CONFIG_7SEG_SPIBUS spiBus0At91
00071 
00072 /* FILE handle for display */
00073 FILE *disp;
00074 
00075 /*
00076  * Main application routine.
00077  *
00078  * Nut/OS automatically calls this entry after initialization.
00079  */
00080 /******************************************************************/
00081 int main(void)
00082 /******************************************************************/
00083 {
00084     uint32_t baud = 115200;
00085     uint8_t rc;
00086     unsigned int count=0;
00087 
00088     /*
00089      * Register the UART device, open it, assign stdout to it and set
00090      * the baudrate.
00091      */
00092     NutRegisterDevice(&DEV_DEBUG, 0, 0);
00093     freopen(DEV_DEBUG_NAME, "w", stdout);
00094     _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
00095 
00096     /*
00097      * Register 7-Segment chip at the SPI bus.
00098      */
00099     printf("initSPI_disp7seg... ");
00100 
00101     rc = NutRegisterSpiDevice(&devSpi7SEG,&NUT_CONFIG_7SEG_SPIBUS,NUT_CONFIG_7SEG_CS);
00102     if (rc != 0){
00103         /* If it fails, leave a message and end here */
00104         printf("FAILED\n");
00105         fflush(stdout);
00106         while(1);
00107     }
00108     printf("OK\n");
00109 
00110     /* The driver implements simple printf support for the display
00111      * so it can be opened as a file and used by fprintf()
00112      */
00113     disp = fopen( devSpi7SEG.dev_name, "w");
00114 
00115     for (;;)
00116     {
00117         /* Lets run a counter for a simple demo */
00118         fprintf( disp, "%3d\n", count++);
00119         if(count >999)count=0;
00120         NutSleep(200);
00121     }
00122     return 0;
00123 }

© 2000-2010 by contributors - visit http://www.ethernut.de/