#include "c:\miniide\hcs12.inc" org $1000 icnt ds.b 1 ; loop count org $1500 lds #$1500 ; set up stack pointer bset DDRK,$80 ; configure the PK7 pin for output jsr openspi0 ; configure SPI0 forever ldx #disp_tab ; use Y as a pointer to the table movb #8,icnt ; set loop count to 8 loop ldaa 1,x+ ; send the digit select byte to the 74HC595 jsr putcspi0 ; " ldaa 1,x+ ; send segment pattern to 74HC595 jsr putcspi0 ; " bclr PTK,BIT7 ; transfer data from shift register to output bset PTK,BIT7 ; latch ldy #1 ; display the digit for one ms jsr delayby1ms ; " dec icnt ; bne loop ; if not reach digit 1, then next bra forever ; start from the start of the table ; ******************************************************************************** ; The following function configures the SPI module properly. ; ******************************************************************************** openspi0 movb #0,SPI0BR ; set baud rate to 12 MHz movb #$50,SPI0CR1 ; disable interrupt, enable SPI, SCK idle low, ; latch data on rising edge, transfer data msb first movb #$02,SPI0CR2 ; disable bidirectional mode, stop SPI in wait mode movb #0,WOMS ; enable Port S pull-up rts #include "c:\miniide\delay.asm" #include "c:\miniide\spi0util.asm" ; ************************************************************* ; Each digit consists of two bytes of data. The first byte is ; digit select, the second byte is the digit pattern. ; ************************************************************* disp_tab dc.b $80,$7F,$40,$70,$20,$5F,$10,$5B dc.b $08,$33,$04,$79,$02,$6D,$01,$30 end