4 digits 7-segement LED display multiplexed using 2x 74hc595. counts 0-F hex on each of the displays sequentially. Program can control up to 8 digits
main.cpp
- Committer:
- hainjedaf
- Date:
- 2016-05-05
- Revision:
- 2:c63fd1eaf215
- Parent:
- 1:a50c12484eb9
- Child:
- 3:131580c6ef9c
File content as of revision 2:c63fd1eaf215:
/* Naam: * SPI_LED_HelloWorld * * Geschreven door: * Marout Yasuo Sluijter-Borms * * Omschrijving: * 8 leds met een schuifregister aansturen op de SPI bus * * Aanmaakdatum: * 3 mei 2016 * Laatste update: * 5 mei 2016 * * Revisie: * 3 mei 2016 * 1 - Basisopzet gemaakt * 5 mei 2016 2 - Definitieve versie * * Copyright (c) 2016, MYSB, The Manhattan Project * Zie einde programma / See end of program. */ /* Libraries en classes insluiten */ #include "mbed.h" /* Declareer seriële poorten */ SPI spi0( P0_9, P0_8, P0_7); // spi0: p5 = mosi, p6 = miso, p7 = scl /* Declareer digitale IO */ DigitalOut ss0( P0_6, 1); // p8 = slave select 0, actief LAAG! Dus pin hoog om chip te deselecteren! /* Declareer Analoge IO */ /* Declareer globale variabelen */ /* Declareer globale constanten */ const int patroon[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; /* Definineer macros */ #define SPI_SPEED 48000000 // max speed #define SPI_MODE 3 // Mode 3: CPOL = 1, CPHA= 1 #define REGISTER_WIDTH 8 // 8-bit register #define REGISTER_COUNT 1 // aantal registers in serie #define LED_ON_TIME 0.02 // tijd dat LED aan is /* Declareer functies */ /* Start hoofprogramma */ int main() { // intellen SPI bus spi0.frequency( SPI_SPEED); // Snelheid bus instellen spi0.format( REGISTER_WIDTH, SPI_MODE); // SPI mode instellen; /* maak schuifregisters leeg */ // selecteer chip ss0 = 0; for( int i = 0; i < REGISTER_COUNT; ++i) { spi0.write( 0x00); // Schrijf leeg byte naar chip } // endfor // deselecteer chip ss0 = 1; /* Schijf patroon naar register */ while(1) { // schrijf patroon for( int i =0; i < 8; ++i) { ss0 = 0; spi0.write( patroon[i]); ss0 = 1; wait( LED_ON_TIME); }; // endfor }; // enwhile }; // endmain /* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */