Hardware Reference
In-Depth Information
To light the digit on display 7, the voltage at Q H of the digit-select 74HC595 must be driven
to high. To light the digit on display 6, the voltage at Q G of the digit-select 74HC595 must be
driven to high, and so on.
There are four parts in the program to be written.
Part 1. Display table setup
The segment patterns and digit-select values are stored in a table so that the table lookup
method can be used to display the desired pattern.
Part 2. SPI module initialization
Configure the SPI module to shift data at 12 MHz on the rising clock edge and most
significant data bit first.
Part 3. Timer delay function
Include the library function delayby1ms to multiplex the digit per millisecond.
Part 4. SPI data transfer
Include the library function putcspi0.asm (or putcspi0.c ) to output the display patterns and
digit-select data.
The following program will display 87654321 on display 7 through display 0:
#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 X as a pointer to the table
movb
#8,icnt
; set loop count to 8
loop
ldaa
1,x 1
; send the digit-select byte to the 74HC595
jsr
putcspi0
;
ldaa
1,x 1
; 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 1 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”
Search WWH ::




Custom Search