* as11 asciiz.asm -l > asciiz.lst * *** HCCOM Hardware equates RAM EQU $2000 * Start of RAM *** RAM Variable Assignments ORG $6000 * Start variables in EVB RAM (upper half) JMP TESTSTART * Jump over varioables to test program... REGBAS EQU $1000 * Starting address for 68HC11 configuration register block PROGSTART EQU $6000 * Address to load this program PORTD EQU $08 * Port D data register -,-,SS#,SCK,MOSI,MISO,TxD,RxD DDRD EQU $09 * Port D data direction SPCR EQU $28 * SPI control register "SPIE,SPE,DWOM,MSTR;CPOL,CPHA,SPR1,SPR0" SPSR EQU $29 * SPI status register "SPIF,WCOL,-,MODF;-,-,-,-" SPDR EQU $2A * SPI data register On Read-Buffer; On Write-Shifter * The LED Driver chip MAX7219 (or MAX7221) do not naturally * contain a hexadecimal font, so we create a font here. * Each Bit that is set to a "1" causes the LED to be illuminated, and * each Bit that is set to a "0" causes the LED to be extinguished. * * The MAX7219 and MAX7221 are functionally equivalent. The main * difference between them is the MAX7221 will generate less RF/ * electrical noise due to slew rate limiting on its outputs. * Throughout this document we will refer only to the MAX7219 * and you may assume identical operation for the MAX7221. * * The LED Driver chip is controlled using a serial peripheral * interface. We will use the supplied routine to access the * display. * * The bit format used below is: DP,a,b,c,d,e,f,g HEXFONT FCB %01111110 * 0 FCB %00110000 * 1 FCB %01101101 * 2 FCB %01111001 * 3 FCB %00110011 * 4 FCB %01011011 * 5 FCB %01011111 * 6 FCB %01110000 * 7 FCB %01111111 * 8 FCB %01111011 * 9 FCB %01110111 * A FCB %00011111 * b FCB %00001101 * c FCB %00111101 * d FCB %01001111 * E FCB %01000111 * F * * Where the seven-segment display LEDs are labelled as follows: * --a- * f| |b * | | * --g- * e| |c * | | * --d- * (dp) - There is no decimal point in HCCOM displays. * ledIndex rmb 1 * ------------------------------------------------------------------------------------ * SOFTWARE PROGRAMMED 16 BIT SERIAL PERIPHERAL INTERFACE (SPI) TRANSFER * THE 68HC11 can only perform 8 bit SPI natively, so we do SPI in software. * ------------------------------------------------------------------------------------ SDIN EQU #$04 SCLOCK EQU #$08 SENBAR EQU #$10 SDOUT EQU #$20 * LED Data Bit Format: * 15 0 * x x x x ADR3 ADR2 ADR1 ADR0 D7 D6 D5 D4 D3 D2 D1 D0 * ADDRESS = 0 = 0 = NOP * ADDRESS = 1..8 = Digit 0..7 * ADDRESS = 9 = Decode Mode * ADDRESS = 10 = Intensity * ADDRESS = 11 = Scan Limit * ADDRESS = 12 = Shutdown * ADDRESS = 15 = Display Test * * ------------------------------------------------------------------ * Initialise MAX7219 LED DISPLAY DRIVER * Initialise to use a software generated font * Set the brightness tp half intensity (using pulse width modulation) * ------------------------------------------------------------------ initLeds psha pshb * Select 7 Seg decode for all digits, 00=no decode (use HEXFONT above) LDD #$0900 BSR SPI * Intensity Register - Set displays to half brightness using PWM... LDD #$0A07 BSR SPI * Scan limit - Set to 8 LED displays LDD #$0B07 BSR SPI * Shutdown Mode = OFF = Normal Operation LDD #$0CFF BSR SPI * Display Test * LDD #$0FFF * BSR SPI * Exit Display test -> Normal Mode LDD #$0F00 BSR SPI pulb pula RTS * ------------------------------------------------------------------------------------ * Transmit the 16 bit data, passed in Accumulator D, via software SPI * Accumulator D = Accumulator A concatenated with Accumulator B. * Accumulator: A = Address; Accumulator B = Data * Returns: 16 bits from SPI device in D * ------------------------------------------------------------------------------------ SPI: PSHX PSHY * Use X to point to the 68HC11 configuration registers LDX #REGBAS * * Initialise 68HC11 port D directions: * ON HCCOM Interface Adapter The MAX7219 * LED display driver is connected as follows * Port D Pin 0 <- RS485 SCI Receive Data * Port D Pin 1 -> RS485 SCI Transmit Data * Port D Pin 2 <- Pin 24 = Data Out from MAX7219 * Port D Pin 3 -> Pin 13 = Serial Clock - Normally low, rising edge to latch data bit ->MAX7219 * Port D Pin 4 -> Pin 12 = CS# - Active Low Chip Select, so assert high asap -> MAX7219 * Port D Pin 5 -> Pin 1 = Data in to MAX7219 PSHA LDAA #%00111010 STAA DDRD,X * Make sure that 8-bit native SPI is switched off * SPCR config bits: "SPIE,SPE,DWOM,MSTR;CPOL,CPHA,SPR1,SPR0" LDAA #$00 STAA SPCR,X PULA * PERFORM SPI TRANSFER VIA PROGRAM CONTROL * SET MAX7219 CS# active BCLR PORTD,X SENBAR * BCLR = BIT CLEAR * SET MAX7219 SCLOCK to 0 BCLR PORTD,X SCLOCK * We need to send 16 bits, so use a counter... * Use Y as a counter from 16..0 LDY #16 * Y register = 16 * Now Send the data bit by bit NEXT_SPI *** Now set MAX7219 SPI Clock line low on LED Driver BCLR PORTD,X SCLOCK * Set the SPI Clock clock low * Shift D by 1 bit * Acc.B has least significant byte ASLB * 0 -> Least Significant Bit, MSBit ->CF * Acc.A has most significant byte ROLA * CarryIn -> LSB, MSB -> CarryOut * Now carry flag has (next) most significant bit BCC CLR_BIT * if carry clear then goto CLR_BIT * * else Bit is set so send a "1" BSET PORTD,X SDOUT * 1008 = Port D = Write Serial Data Out = 1 BRA SET_BIT * Skip next bit CLR_BIT * * Bit was clear so send a "0" BCLR PORTD,X SDOUT * 1008 = Port D = Write Serial Data Out = 0 SET_BIT * * ENDIF * wait a bit for serial data line to settle NOP * Do nothing NOP * Now strobe Clock line high on MAX7219 to shift the data * Set the SPI Clock clock high BSET PORTD,X SCLOCK * 8 Cycles NOP NOP * and strobe Clock line low on 7219 BCLR PORTD,X SCLOCK * * read the serial data shifted in to the 68HC11 -> Z flag * Data is clocked out of MAX7219 on falling edge BRCLR PORTD,X SDIN NOBITS ORB #1 * Set bit 0=1 if serial data =1 NOBITS * Bit 0 is clear already from the ASLB instruction DEY BNE NEXT_SPI * * DONE_TX: * Now set Clock line low on 7219 NOP NOP BCLR PORTD,X SCLOCK * NOP NOP * SET 7219 CS# inactive BSET PORTD,X SENBAR * * Recover stuff from stack PULY PULX RTS outHexLedA: * ----------------------------------------------------- * A = Hex Byte Data to display, ledIndex=led pair * ----------------------------------------------------- * Save registers on stack... psha pshb pshy tab ldaa ledIndex inc ledIndex * then mult by 2 as they are LED pairs asla * Led registers are 1 through 8 (not 0..7) inca * Get most significant hex nibble psha pshb lsrb lsrb lsrb lsrb * Lookup font table for bits to set ldy #HEXFONT aby ldab 0,y jsr SPI pulb pula * Point to next display bit inca * Get most significant hex nibble andb #%00001111 ldy #HEXFONT aby ldab 0,y jsr SPI * Recover saved registers puly pulb pula rts TESTSTART: JSR initLeds clr ledIndex ldaa #$01 jsr outHexLedA ldaa #$23 jsr outHexLedA ldaa #$45 jsr outHexLedA ldaa #$67 jsr outHexLedA swi