LIST p=16F819
include "P16F819.inc"
__config _INTRC_IO & _WDT_OFF & _LVP_OFF
org 0x0000
init
BANKSEL TRISA ;select bank 1
clrf TRISA ;PORTA all outs
movlw b'00000010'
movwf TRISB
BANKSEL PORTA ;select bank 0
clrf PORTA
clrf PORTB
spiinit bsf PORTB,0 ;CS high
BANKSEL SSPSTAT ;select bank 1
movlw b'11000000' ;init SPI Master
movwf SSPSTAT
BANKSEL SSPCON ;select bank 0
clrf SSPCON
movlw b'00000010'
movlw SSPCON
bsf SSPCON,SSPEN
main bsf PORTB,3 ;LED on
bcf PORTB,0 ;CS low
movlw 0x0a ;intensity register
call spisend
movlw 0x0f ;full brightness
call spisend
bsf PORTB,0 ;CS high
bcf PORTB,0 ;CS low
movlw 0x0b ;scan limit register
call spisend
movlw 0x03 ;display digits 0-3
call spisend
bsf PORTB,0 ;CS high
bcf PORTB,0 ;CS low
movlw 0x09 ;decode mode register
call spisend
movlw 0x0f ;code B decode for digits 3-0
call spisend
bsf PORTB,0 ;CS high
bcf PORTB,0 ;CS low
movlw 0x0c ;shutdown register
call spisend
movlw 0x01 ;normal operation
call spisend
bsf PORTB,0 ;CS high
display bcf PORTB,0 ;CS low
movlw 0x01 ;digit 0
call spisend
movlw 0x04 ;4
call spisend
bsf PORTB,0 ;CS high
bcf PORTB,0 ;CS low
movlw 0x02 ;digit 1
call spisend
movlw 0x03 ;3
call spisend
bsf PORTB,0 ;CS high
bcf PORTB,0 ;CS low
movlw 0x03 ;digit 2
call spisend
movlw 0x02 ;2
call spisend
bsf PORTB,0 ;CS high
bcf PORTB,0 ;CS low
movlw 0x04 ;digit 3
call spisend
movlw 0x01 ;1
call spisend
bsf PORTB,0 ;CS high
bcf PORTB,3 ;LED off
bleh goto bleh
spisend movwf SSPBUF
BANKSEL SSPSTAT
spiloop btfss SSPSTAT,BF
goto spiloop
BANKSEL SSPBUF
movf SSPBUF,W
return
end