Skip to content

Instantly share code, notes, and snippets.

@caiorss
Forked from crabmusket/7-segment.hs
Last active August 29, 2015 14:23
Show Gist options
  • Save caiorss/56598892dcef6f45f9a1 to your computer and use it in GitHub Desktop.
Save caiorss/56598892dcef6f45f9a1 to your computer and use it in GitHub Desktop.
-- 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