; Written by Ted Salazar ;=======Maxim.asm===========4/2/01 ;This program is a Design Idea for ;cascading two MAX7221 LED display ;drivers using only one SPI port to ;control eight 14 segment Alphanumeric ;Displays. ; This program Displays "MXIM^87.5" ; but can be modified to display ; any text message 8 letters long. ;---------------------------------- list p=16f84 radix hex ;---------------------------------- ; memory map porta equ 0x05 portb equ 0x06 r_scan_hbyte equ 0x0c r_scan_lbyte equ 0x0d r_intensity_hbyte equ 0x0e r_intensity_lbyte equ 0x0f r_code_b_hbyte equ 0x10 r_code_b_lbyte equ 0x11 r_temp equ 0x12 ncount equ 0x13 r_digit0_hbyte equ 0x14 r_digit0_lbyte equ 0x15 r_digit1_hbyte equ 0x16 r_digit1_lbyte equ 0x17 r_digit2_hbyte equ 0x18 r_digit2_lbyte equ 0x19 r_digit3_hbyte equ 0x1a r_digit3_lbyte equ 0x1b r_digit4_hbyte equ 0x1c r_digit4_lbyte equ 0x1d r_digit5_hbyte equ 0x1e r_digit5_lbyte equ 0x1f r_digit6_hbyte equ 0x20 r_digit6_lbyte equ 0x21 r_digit7_hbyte equ 0x22 r_digit7_lbyte equ 0x23 r_digit8_hbyte equ 0x24 r_digit8_lbyte equ 0x25 r_digit9_hbyte equ 0x26 r_digit9_lbyte equ 0x27 r_minus_hbyte equ 0x28 r_minus_lbyte equ 0x29 r_letter_E_hbyte equ 0x2a r_letter_E_lbyte equ 0x2b r_letter_H_hbyte equ 0x2c r_letter_H_lbyte equ 0x2d r_letter_L_hbyte equ 0x2e r_letter_L_lbyte equ 0x2f r_letter_P_hbyte equ 0x30 r_letter_P_lbyte equ 0x31 r_blank_hbyte equ 0x32 r_blank_lbyte equ 0x33 xcount equ 0x34 kcount equ 0x35 mcount equ 0x36 ;---------------------------------------------- ;***** ;Main ;***** org 0x000 start movlw 0x00 ;RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 ; 0 0 0 0 0 0 0 0 ;sclk cs\ X din ( outputs....) tris portb ;all ports b's are outputs movlw 0x40 ;0x40 to w movwf portb ;cs\=1 ;sclk=0 ;din=0 ;X=0 ;RB0-RB3 = 0 call delay1sec ;------------------------------------------------ ;************************************ ;Setting the scan rate for MAX7221 #2 ;************************************ bcf portb,6 ;cs\=0 movlw 0x0b ;0x0b to w movwf r_scan_hbyte ;w to register movf r_scan_hbyte ; to w call spi_8bit_word ; call subroutine movlw 0x07 ;0x07 to w movwf r_scan_lbyte ;w to register movf r_scan_lbyte ; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ; ;cs\=1 call delay200ms ;************************************ ;Setting the scan rate for MAX7221 #1 ;************************************ bcf portb,6 ;cs\=0 movlw 0x0b ;0x0b to w movwf r_scan_hbyte ;w to register movf r_scan_hbyte ; to w call spi_8bit_word ; call subroutine movlw 0x07 ;0x07 to w movwf r_scan_lbyte ;w to register movf r_scan_lbyte ; to w call spi_8bit_word ; call subroutine bsf portb,6 ; ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;************************************ ;Setting the intensity for MAX7221 #2 ;************************************ bcf portb,6 ;cs\=0 movlw 0x0a ;0x0a to w movwf r_intensity_hbyte;w to register movf r_intensity_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x07 ;0x07 to w movwf r_intensity_lbyte;w to register movf r_intensity_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ; ;cs\=1 call delay200ms ;************************************ ;Setting the intensity for MAX7221 #1 ;************************************ bcf portb,6 ;cs\=0 movlw 0x0a ;0x0a to w movwf r_intensity_hbyte;w to register movf r_intensity_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x07 ;0x07 to w movwf r_intensity_lbyte;w to register movf r_intensity_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ; ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;************************************* ;Setting no decode mode for MAX7221 #2 ;************************************* bcf portb,6 ;cs\=0 movlw 0x09 ;0x09 to w movwf r_code_b_hbyte ;w to register movf r_code_b_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x00 ;0x00 to w movwf r_code_b_lbyte ;w to register movf r_code_b_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ; ;cs\=1 call delay200ms ;************************************* ;Setting no decode mode for MAX7221 #1 ;************************************* bcf portb,6 ;cs\=0 movlw 0x09 ;0x09 to w movwf r_code_b_hbyte ;w to register movf r_code_b_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x00 ;0x00 to w movwf r_code_b_lbyte ;w to register movf r_code_b_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ; ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;#1 ;************************************** ;Setting 7seg LED0 to "M" of MAX7221 #2 ;************************************** bcf portb,6 ;cs\=0 movlw 0x01 ;0x01 to w movwf r_letter_H_hbyte;w to register movf r_letter_H_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x28 ;0x28 to w movwf r_letter_H_lbyte;w to register movf r_letter_H_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ; ;cs\=1 call delay200ms ;************************************** ;Setting 7seg LED0 to "M" of MAX7221 #1 ;************************************** bcf portb,6 ;cs\=0 movlw 0x01 ;0x01 to w movwf r_letter_H_hbyte;w to register movf r_letter_H_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x36 ;0x36 to w movwf r_letter_H_lbyte;w to register movf r_letter_H_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ; ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;************************************** ;Setting 7seg LED1 to "X" of MAX7221 #2 ;************************************** bcf portb,6 ;cs\=0 movlw 0x02 ;0x02 to w movwf r_letter_E_hbyte;w to register movf r_letter_E_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x2d ;0x2d to w movwf r_letter_E_lbyte;w to register movf r_letter_E_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ; ;cs\=1 call delay200ms ;************************************** ;Setting 7seg LED1 to "X" of MAX7221 #1 ;************************************** bcf portb,6 ;cs\=0 movlw 0x02 ;0x02 to w movwf r_letter_E_hbyte;w to register movf r_letter_E_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x00 ;0x00 to w movwf r_letter_E_lbyte;w to register movf r_letter_E_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ; ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;*************************************** ;Setting 7seg LED2 to "I" for MAX7221 #2 ;*************************************** bcf portb,6 ;cs\=0 movlw 0x03 ;0x03 to w movwf r_letter_L_hbyte;w to register movf r_letter_L_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x12 ;0x12 to w movwf r_letter_L_lbyte;w to register movf r_letter_L_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ; ;cs\=1 call delay200ms ;*************************************** ;Setting 7seg LED2 to "I" for MAX7221 #1 ;*************************************** bcf portb,6 ;cs\=0 movlw 0x03 ;0x03 to w movwf r_letter_L_hbyte;w to register movf r_letter_L_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x48 ;0x48 to w movwf r_letter_L_lbyte;w to register movf r_letter_L_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ; ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;*************************************** ;Setting 7seg LED3 to "M" for MAX7221 #2 ;*************************************** bcf portb,6 ;cs\=0 movlw 0x04 ;0x04 to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x28 ;0x28 to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ;cs\=1 call delay200ms ;*************************************** ;Setting 7seg LED3 to "M" for MAX7221 #1 ;*************************************** bcf portb,6 ;cs\=0 movlw 0x04 ;0x04 to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x36 ;0x36 to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;*************************************** ;Setting 7seg LED4 to "^" for MAX7221 #2 ;*************************************** bcf portb,6 ;cs\=0 movlw 0x05 ;0x05 to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x05 ;0x05 to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ;cs\=1 call delay200ms ;*************************************** ;Setting 7seg LED4 to "^" for MAX7221 #1 ;*************************************** bcf portb,6 ;cs\=0 movlw 0x05 ;0x05 to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x00 ;0x00 to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;************************************** ;Setting 7seg LED5 to "8" of MAX7221 #2 ;************************************** bcf portb,6 ;cs\=0 movlw 0x06 ;0x06 to w movwf r_letter_E_hbyte;w to register movf r_letter_E_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x40 ;0x40 to w movwf r_letter_E_lbyte;w to register movf r_letter_E_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ; ;cs\=1 call delay200ms ;************************************** ;Setting 7seg LED5 to "8" of MAX7221 #1 ;************************************** bcf portb,6 ;cs\=0 movlw 0x06 ;0x06 to w movwf r_letter_E_hbyte;w to register movf r_letter_E_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x7f ;0x7f to w movwf r_letter_E_lbyte;w to register movf r_letter_E_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ; ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;*************************************** ;Setting 7seg LED6 to "7." for MAX7221 #2 ;*************************************** bcf portb,6 ;cs\=0 movlw 0x07 ;0x07 to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0xc9 ;0xc9 to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ;cs\=1 call delay200ms ;*************************************** ;Setting 7seg LED6 to "7." for MAX7221 #1 ;*************************************** bcf portb,6 ;cs\=0 movlw 0x07 ;0x07 to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0xc1 ;0xc1 to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;*************************************** ;Setting 7seg LED7 to "5" for MAX7221 #2 ;*************************************** bcf portb,6 ;cs\=0 movlw 0x08 ;0x08 to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x40 ;0x40 to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ;cs\=1 call delay200ms ;*************************************** ;Setting 7seg LED7 to "5" for MAX7221 #1 ;*************************************** bcf portb,6 ;cs\=0 movlw 0x08 ;0x08 to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x5b ;0x5b to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ;cs\=1 call delay200ms ;------------------------------------------------ ;------------------------------------------------ ;**************************************** ;Take MAX7221 #2 Out of Shutdown ;**************************************** circle1 bcf portb,6 ;cs\=0 movlw 0x0c ;0x0c to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x0f ;0x0f to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ;cs\=1 ;**************************************** ;Put MAX7221 #1 Into Shutdown ;**************************************** bcf portb,6 ;cs\=0 movlw 0x0c ;0x0c to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x00 ;0x00 to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ;cs\=1 ;----------------------------------------------- ;----------------------------------------------- ;**************************************** ;Put MAX7221 #2 Into Shutdown ;**************************************** bcf portb,6 ;cs\=0 movlw 0x0c ;0x0c to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x00 ;0x00 to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine ; bsf portb,6 ;cs\=1 ;**************************************** ;Take MAX7221 #1 out of Shutdown ;**************************************** bcf portb,6 ;cs\=0 movlw 0x0c ;0x0c to w movwf r_letter_P_hbyte;w to register movf r_letter_P_hbyte; to w call spi_8bit_word ; call subroutine movlw 0x0f ;0x0f to w movwf r_letter_P_lbyte;w to register movf r_letter_P_lbyte; to w call spi_8bit_word ; call subroutine bsf portb,6 ;cs\=1 goto circle1 ;Continuous loop ;----------------------------------------------------- ;----------------------------------------------- ;------------------------------------------------ ;The "spi_8bit_word" subroutine takes the contents of ;the various _hbyte and _lbyte registers and shifts ;them out through the SPI port. This subroutine is ;generic and can be used for any SPI device that ;does not use the DOUT line. ;************ spi_8bit_word ;************ movwf r_temp ;r_temp = w movlw 0x08 ;0x08 to w movwf ncount ;0x08 to ncount btfline btfsc r_temp,7;test bit 7 of r_temp ;skip if clear goto spi_hi ;spi_low rlf r_temp,f nop bsf portb,7 ;sclk=1 nop bcf portb,7 ;sclk=0 decfsz ncount goto btfline out return spi_hi rlf r_temp,f bsf portb,4 ;Din=1 nop bsf portb,7 ;sclk=1 nop bcf portb,7 ;sclk=0 bcf portb,4 ;Din=0 decfsz ncount goto btfline goto out ;----------------------------------------------------- ;Delay Subroutine ;xcount controls the delay time ;i.e. xcount x 200ms = delay ;******** delay1sec ;******** movlw 0x05 ;0x05 to w movwf xcount ;to xcount loadm movlw 0xff ;0xff to w movwf mcount ;to mcount loadk movlw 0xff ;0xff to w movwf kcount ;to kcount deck decfsz kcount,f;dec k goto deck decfsz mcount,f;dec m goto loadk ;jump to loadk decfsz xcount,f;dec x goto loadm ;jump to loadm return ;----------------------------------------------------- ;Delay Subroutine ;xcount controls the delay time ;i.e. xcount x 200ms = delay ;******** delay200ms ;******** movlw 0x01 ;0x01 to w movwf xcount ;to xcount loadm2 movlw 0xff ;0xff to w movwf mcount ;to mcount loadk2 movlw 0xff ;0xff to w movwf kcount ;to kcount deck2 decfsz kcount,f;dec k goto deck2 decfsz mcount,f;dec m goto loadk2 ;jump to loadk decfsz xcount,f;dec x goto loadm2 ;jump to loadm return ;---------------------------------------- ;****** end ;****** ;======================================== ; settings: ; memory unprotected ; watchdog timer disabled (default enabled) ; standard crystal (4Mhz) ; power-up timer on ;========================================