Skip to content

Instantly share code, notes, and snippets.

@crabmusket
Last active December 18, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save crabmusket/5754669 to your computer and use it in GitHub Desktop.
Save crabmusket/5754669 to your computer and use it in GitHub Desktop.
A 7-segment display controller for the LaunchPad written in Atom.
-- http://hackage.haskell.org/package/atom
-- http://hackage.haskell.org/package/atom-msp430
module Main where
import Data.Word
import Data.Bits
import Language.Atom.MSP430
main = mspCompile "g2231" $ mspProgram {
setupFn = Just setup,
timerAISR = Just isr
}
isr = do
counter <- word8 "counter" 0
digits <- array "digits" sevenSeg
period 30 $ atom "write_digit" $ do
port1Out <== digits !. value counter
counter <== mod_ (value counter + 1) (Const 10)
sevenSeg = [0x40, 0xF3, 0x09, 0x21, 0x32, 0x24, 0x04, 0xF1, 0x00, 0x30] :: [Word8]
setup = do
atom "settings" $ do
watchdog <== Const (wdtPassword .|. wdtHold)
port1Dir <== Const 0xFF
port1Out <== Const 0xFF
timerAControl <== Const (taUpMode .|. taSourceSMCLK .|. taSourceDiv8)
timerACCC0 <== Const taCCRInterrupt
timerACCR0 <== Const 4096
call "__enable_interrupt"
atom "poweroff" $ inline "_BIS_SR(LPM0|GIE)"
inline s = action (\_ -> s) []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment