; a6276.txt ; ; 20-Jun-2006 Keith Neufeld ; ; Drive an Allegro MicroSystems A6276 constant-current LED driver chip. ; The chip takes three inputs: ; ; A0 serial data in (SDI) ; A1 clock (CK) ; A2 latch enable (L) ;------------------------------------------------------------------------------ ; Debug system ;------------------------------------------------------------------------------ constants [[debug 0]] ;constants [[debug 1]] ;------------------------------------------------------------------------------ ; Section to manipulate A6276. ;------------------------------------------------------------------------------ constants [ [a6276-sdi-port portb] [a6276-sdi-ddr portb-ddr] [a6276-sdi-bit 0] [a6276-ck-port portb] [a6276-ck-ddr portb-ddr] [a6276-ck-bit 1] [a6276-l-port portb] [a6276-l-ddr portb-ddr] [a6276-l-bit 2] ] ; Push one bit into input register. to a6276-bit :bit ; Put bit on data input port. ifelse :bit [ if debug [ prs "setbit ] setbit a6276-sdi-bit a6276-sdi-port ; set 1 output ] [ if debug [ prs "clearbit ] clearbit a6276-sdi-bit a6276-sdi-port ; set 0 output ] ; Clock it. setbit a6276-ck-bit a6276-ck-port ; rising edge clearbit a6276-ck-bit a6276-ck-port ; falling edge end ; Latch input register to output register to a6276-latch setbit a6276-l-bit a6276-l-port ; rising edge clearbit a6276-l-bit a6276-l-port ; falling edge end ; Turn off all LEDs. to a6276-off repeat 16 [ a6276-bit 0 ] a6276-latch end ; Initialize port settings and turn off all LEDs. to a6276-init clearbit a6276-sdi-bit a6276-sdi-port ; zero data input clearbit a6276-ck-bit a6276-ck-port ; zero clock clearbit a6276-l-bit a6276-l-port ; zero latch enable clearbit a6276-sdi-bit a6276-sdi-ddr ; set pins as outputs clearbit a6276-ck-bit a6276-ck-ddr clearbit a6276-l-bit a6276-l-ddr a6276-off ; turn off all LEDs end ;------------------------------------------------------------------------------ ; Routines to tie it all together ;------------------------------------------------------------------------------ to init-all a6276-init end to powerup init-all end to startup init-all end