Blinkies

The home of MSP430xxxx blinkies.

Fading Cosine, 96 bytes

Matthias new fading cosine tinyblinky for MSP430F2012 in only 96 bytes!

For the complete package (7.2 kB) see https://sourceforge.net/projects/mecrisp-across-folkdoc/files/Tinyblinky-Cosine-MSP430.tar.gz


; -----------------------------------------------------------------------------
;   Terries tinyblinky challenge goes MSP430
; -----------------------------------------------------------------------------

; Challenges: Blinky, binary as small as possible, no strange electrical states on other pins.

  cpu msp430

  include "mspregister.asm"
  include "registers-classic.asm"

; -----------------------------------------------------------------------------
  org 0FF00h  ; 256 Bytes to go.
; -----------------------------------------------------------------------------

Reset:

  mov #WDTPW+WDTHOLD, &WDTCTL  ; Stop watchdog timer
  mov.b #1, &P1DIR             ; Set LED pin(s) as output
  
  mov.b &CALBC1_8MHZ, &BCSCTL1 ; 8 MHz --> DCO
  mov.b &CALDCO_8MHz, &DCOCTL  ;
  
  ; Register usage:
  ;
  ;  r5 : Minsky sine
  ;  r6 : Minsky cosine
  ;  r7 : Scratch
  ;  r8 : Exponential brightness
  ;  r9 : Repetition counter, rolls over
  ; r10 : Sigma delta modulator phase

  ; Start values for Minsky circle algorithm
  
  mov #0, r5
  mov #70, r6
    
Blinky:

  ; Minsky circle algorithm
  
  mov r6, r7  ; x' = x + y  >>> 4
  rra r7
  rra r7
  rra r7
  rra r7
  add r7, r5
  
  mov r5, r7  ; y' = y - x' >>> 4        
  rra r7
  rra r7
  rra r7
  rra r7
  sub r7, r6
    
  ; Adjust circle coordinates to bitexp input values
  
  mov r6, r7    ; Select sine/cosine here
  add #78h, r7
  
  ; Modified bitexp function
  
  mov r7, r8
  and #0Fh, r8  
  bis #10h, r8
  
  rra r7
  rra r7
  rra r7
  rra r7
  
;  jz + ; No check necessary, as minimum input value always requires a shift
- add r8, r8
  sub #1, r7
  jnz -  
;+ 
  
  ; Display current brightness step for a while

- add r8, r10   ; Sigma-Delta-Modulation
  rrc.b &P1OUT  ; Shift carry into position
  add #2, r9    ; Add until register rollover - adjust blink speed here
  jnc -
  
  jmp Blinky    ; Next brightness step
  
; -----------------------------------------------------------------------------
; Vector table
; -----------------------------------------------------------------------------

  org 0FFFEh
  .word Reset

  end

; How to assemble:  asl tinyblinky.asm && p2hex tinyblinky.p -r 0x0000-0xFFFF
; How to flash:     mspdebug rf2500 "prog tinyblinky.hex"