> > Newbie looking for code to connect a 16C84 to a Maxim MAX7219. The Data > Sheet appears to be confused when talking about the load line and the > picture that shows the load line, help? > > > Joel R. Simpson > LAN Administrator > King County, Department of Natural Resources > Water and Land Resources Division > (206)296-8375 Page(206)994-4343 Fax(206)296-0192 > > > Hi Joel: Assuming the following connections, the software below initialises (init_maxim) and writes to MAX7219(disp_32). (1) On initialisation, this routine displays a single zero. (2) Note that i put "6-digits" in the scan-limit register, you may want to change this and other variables as necessary. (3) i have not included initialisation code for port-A, which makes it an output register(necessary). (4) For your convenience i have also included a 24bit binary-to-bcd conversion routine , which you probably might need. --ravindra ________________________________________ | | | | | _______________ | _______ ________ | | | | | | ------- |1 18 |------------------------------ |Din | | | | | | |2 17 |------------------------------ |Clk | | | |______________ | | |3 16 | |LOAD | | | | | |4 15 | | | | | | | |5 14 | | | | | | | |6 13 | | | | | | | |7 12 | | | | | | | |8 11 | | | | | | | |9 10 | | | |_______________| |_______ ________| PIC16C84 MAX72 19 ################################################################################ ##################### processor 16C84 ;; Program constants ;; ;; these are special register addresses porta equ h'05' portb equ h'06' trisa equ h'85' trisb equ h'86' intcon equ h'0b' eecon1 equ h'88' eecon2 equ h'89' eedata equ h'08' eeaddr equ h'09' status equ h'03' option_reg equ h'81' FSR equ h'04' INDF equ h'00' ;; ;; ;; these are individual bits in the Special function registers. wren equ h'2' gie equ h'7' wr equ h'1' rd equ h'0' zero equ h'2' eeif equ h'5' carry equ h'0' Clk equ h'0' Din equ h'1' LOAD equ h'2' intf equ h'1' toif equ h'2' reset_button equ h'3' show_button equ h'4' ;; ;; ;; ;; these are RAM locations assigned to various sub-routines. ;; ;; NumT equ h'10' NumH equ h'11' NumL equ h'12' Tmil equ h'13' Mill equ h'14' HunT equ h'15' TenK equ h'16' Thou equ h'17' Hund equ h'18' Tens equ h'19' Ones equ h'1a' tempb2 equ h'12' tempb1 equ h'13' tempb0 equ h'14' accb0 equ h'15' accb1 equ h'16' accb2 equ h'17' accb3 equ h'18' accb4 equ h'19' accb5 equ h'1a' gp_loc0 equ h'1b' gp_loc1 equ h'1c' maxim_hi equ h'1d' maxim_lo equ h'1e' eeptr equ h'1f' aargb0 equ h'20' aargb1 equ h'21' aargb2 equ h'22' aargb3 equ h'23' aargb4 equ h'24' aargb5 equ h'25' bargb0 equ h'26' bargb1 equ h'27' bargb2 equ h'28' init_MAXIM: movlw 00 movwf porta decode_mode: movlw H'09' movwf maxim_hi movlw H'ff' ;; decode for all digits movwf maxim_lo call led_write intensity: movlw H'0a' movwf maxim_hi movlw H'0f' ;; max intensity movwf maxim_lo call led_write scan_limit: movlw H'0b' movwf maxim_hi movlw H'05' ;; 6 digits movwf maxim_lo call led_write disp_test: movlw H'0f' movwf maxim_hi movlw H'00' ;; test movwf maxim_lo call led_write digit1: movlw H'01' movwf maxim_hi movlw H'00' ;; '0' movwf maxim_lo call led_write digit2_6: movlw H'02' movwf gp_loc0 digit_loop: movf gp_loc0,w ;; blank digits2-6 movwf maxim_hi movlw H'0f' movwf maxim_lo call led_write incf gp_loc0,f movlw H'07' subwf gp_loc0,w btfss status,zero goto digit_loop shutdown: movlw H'0c' movwf maxim_hi movlw H'01' ;; turn on display movwf maxim_lo call led_write ;; led_write: movlw h'00' movwf porta movlw h'08' ;; counter movwf gp_loc0 bcf status,carry ;; clear carry loop_hi: rlf maxim_hi,f btfss status,carry goto toggle_clock_hi bsf porta,Din toggle_clock_hi: bsf porta,Clk bcf porta,Clk bcf porta,Din ;; if set,reset it. decfsz gp_loc0,f goto loop_hi ;; movlw h'08' ;; counter movwf gp_loc0 bcf status,carry ;; clear carry loop_lo: rlf maxim_lo,f btfss status,carry goto toggle_clock_lo bsf porta,Din toggle_clock_lo: bsf porta,Clk bcf porta,Clk bcf porta,Din ;; if set,reset it. decfsz gp_loc0,f goto loop_lo ;; toggle_load: bsf porta,LOAD bcf porta,LOAD return; disp_32_: movlw Ones ;; address for "ONES" movwf FSR ;; data-pointer movlw h'06' ;; counter movwf gp_loc0 movlw h'01' ;; first digit reg addr movwf gp_loc1 ;; next_digit: movf gp_loc1,w movwf maxim_hi movf INDF,w movwf maxim_lo call led_write incf FSR,f incf gp_loc1,f decfsz gp_loc0,f goto next_digit return ;; Input is 24 bit binary number in NumT:NumH:NumL. ;; Output is 8-digit BCD in Tmil:Mill:HunT:TenK:Thou:Hund:Tens:Ones bin2bcd_24: movlw 0 movwf Ones movwf Tens movwf Hund movwf Thou movwf TenK movwf HunT movwf Mill movwf Tmil a5: swapf NumT,w andlw h'0f' ; w = a5 movwf Mill ; addwf TenK,f ; subwf Thou,f ; addwf Mill,w ; w = 2*a5 subwf Tens,f addwf Mill,w addwf Mill,w ; w = 4*a5 addwf TenK,f subwf Hund,f subwf Ones,f a4: movf NumT,w andlw h'0f' ; w = a4 movwf gp_loc0 addwf TenK,f addwf gp_loc0,w ; w = 2*a4 addwf TenK,f subwf Tens,f addwf gp_loc0,w addwf gp_loc0,w ; w = 4*a4 addwf TenK,f subwf Thou,f subwf Hund,f subwf Tens,f subwf Ones,f a3: swapf NumH,w andlw h'0f' ; w = a3 movwf gp_loc0 addwf Hund,f rlf gp_loc0,f rlf gp_loc0,w ; w = 4*a3 addwf Thou,f subwf Ones,f movf Ones,f btfsc status,zero goto norm_b1_1 norm_b0_1: movlw d'10' addwf Ones,f decf Tens,f movlw d'246' addwf Ones,w btfsc status,carry goto norm_b0_1 norm_b1_1: movf Tens,f btfsc status,zero goto a2 norm_b1_2: movlw d'10' addwf Tens,f decf Hund,f movlw d'246' addwf Tens,w btfsc status,carry goto norm_b1_2 a2: movf NumH,w andlw h'0f' ; w = a2 movwf gp_loc0 addwf gp_loc0,w addwf Hund,f addwf Tens,f addwf gp_loc0,w addwf gp_loc0,w addwf Tens,f subwf Ones,f a1: swapf NumL,w andlw h'0f' ; w = a1 movwf gp_loc0 addwf gp_loc0,w addwf Tens,f subwf Ones,f subwf Ones,f a0: movf NumL,w andlw h'0f' addwf Ones,f norm: movlw d'20' subwf Ones,f movlw d'128' subwf Tens,f movlw d'47' subwf Hund,f movlw d'64' subwf Thou,f movlw d'183' subwf TenK,f movlw d'19' addwf HunT,f movlw h'0a' norm_b0: decf Tens,f addwf Ones,f btfss status,carry goto norm_b0 norm_b1: decf Hund,f addwf Tens,f btfss status,carry goto norm_b1 norm_b2: decf Thou,f addwf Hund,f btfss status,carry goto norm_b2 norm_b3: decf TenK,f addwf Thou,f btfss status,carry goto norm_b3 norm_b4: decf HunT,f addwf TenK,f btfss status,carry goto norm_b4 norm_b5: movlw d'246' addwf HunT,w btfss status,carry goto norm_b6 movlw d'10' subwf HunT,f incf Mill,f goto norm_b5 norm_b6: movlw d'246' addwf Mill,w btfss status,carry goto done movlw d'10' subwf Mill,f incf Tmil,f goto norm_b6 done: return end