7-Segment LED display using SPI

Download new library modules and examples to use with Astrobe for Cortex-M. Forum members can also upload their own source code examples.
Post Reply
cfbsoftware
Site Admin
Posts: 525
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

7-Segment LED display using SPI

Post by cfbsoftware » Sat Jun 09, 2012 1:11 am

Code: Select all

MODULE LedSeconds;
(* =========================================================================  
   Example Cortex-M3 Oberon Program  
 
   Description:
     Counting seconds on a 7-segment LED   
      
   Target: 
     LPC13xx systems with an 7-segment led display
     connected to the SPI0/SSP0 bus

   Tested on:
     LPCXpresso LPC1343
     
   Refs: 
     NXP LPC13xx User Manual 
     Oberon for Cortex-M3 Microcontrollers
   
   (c) 2009-2012 CFB Software   
   http://www.astrobe.com  
   
   ========================================================================= *)

IMPORT Main, MCU, SPI, SYSTEM, Timer;

CONST
  chipSelect = {11};
  
VAR
  iTo7Segment: ARRAY 10 OF SET;

PROCEDURE SelectLow();
VAR
  port1: SET;
BEGIN
  SYSTEM.GET(MCU.GPIO1DATA, port1);
  SYSTEM.PUT(MCU.GPIO1DATA, port1 - chipSelect)
END SelectLow;
  
PROCEDURE SelectHigh();
VAR
  port1: SET;
BEGIN
  SYSTEM.GET(MCU.GPIO1DATA, port1);
  SYSTEM.PUT(MCU.GPIO1DATA, port1 + chipSelect)
END SelectHigh;


PROCEDURE Display(n: INTEGER);
BEGIN
  ASSERT(n IN {0..9}, 100);
  SPI.SendChar(SYSTEM.VAL(CHAR, iTo7Segment[n]));
END Display;


PROCEDURE ConfigurePins;
VAR
  s: SET;
BEGIN
  (* Pin 1.11 is used for chip select *)
  SYSTEM.PUT(MCU.IOCONPIO111, 0D0H); 
  (* Output pin *)
  SYSTEM.GET(MCU.GPIO1DIR, s);
  SYSTEM.PUT(MCU.GPIO1DIR, s + chipSelect)
END ConfigurePins;
 

PROCEDURE Run();
CONST
  SPIPort = 0;
  nBits = 8;
  useSSEL = TRUE;
VAR
  i: INTEGER;
BEGIN
  ConfigurePins();
  SPI.Init(SPIPort, nBits, ~useSSEL);  
  WHILE TRUE DO
    FOR i := 0 TO 9 DO
      SelectLow();
      Display(i);
      Timer.MSecDelay(500);
      SelectHigh();
      Timer.MSecDelay(500)
    END  
  END
END Run;

BEGIN
(*
      3
     ---
  7 |   | 4
    |   | 
    - 2 - 
    |   | 
  1 |   | 6
     ---
      0   * 5
*)
     
  iTo7Segment[0] := -{0, 1, 3, 4, 6, 7}; 
  iTo7Segment[1] := -{4, 6};
  iTo7Segment[2] := -{0..4};
  iTo7Segment[3] := -{0, 2, 3, 4, 6};
  iTo7Segment[4] := -{2, 4, 6, 7};
  iTo7Segment[5] := -{0, 2, 3, 6, 7};
  iTo7Segment[6] := -{0, 1, 2, 6, 7};
  iTo7Segment[7] := -{3, 4, 6};
  iTo7Segment[8] := -{0..4, 6, 7};
  iTo7Segment[9] := -{2, 3, 4, 6, 7};
  Run()
END LedSeconds.
Attachments
LedSeconds.zip
LedSeconds.mod
(1020 Bytes) Downloaded 1795 times

Post Reply