硬件方面:
pic通過74hc595來位選數碼管.ra0口接595的rclk,ra1口接595的srclk,ra2口接595的ser
pic的d口輸出字型碼.
軟件方面:
list p=16f877 include"p16f877.inc" count equ 34h bits equ 35h inter equ 36h count1 equ 37h bits1 equ 38h org 0x00 nop initial ;初始化 banksel TRISA movlw 0x00 movwf TRISA movwf TRISD banksel PORTD movlw 0x00 movwf PORTD clrf count clrf bits clrf inter movlw 00h movwf bits movlw 08h movwf count bcf PORTA,0 noop bcf PORTA,1 movf PORTA,W andlw 0xfb iorwf bits,w movwf PORTA bsf PORTA,1 rlf bits,1 decfsz count goto noop bsf PORTA,0
main movlw 0x99 movwf PORTD ;段型碼送d口 movlw 04h movwf count1
movlw 08h movwf bits ;位選信號放在bits寄存器中 movwf bits1 ;位選信號送中間寄存器 loop1 movlw 04h ;下面一段程序為串并轉換 movwf count tab rlf bits,1 decfsz count,1 goto tab movlw 08h movwf count bcf PORTA,0 ;為送鎖存信號做準備 loop bcf PORTA,1 ;為送時鐘信號做準備 movf bits,w andlw 04h movwf inter movf PORTA,w andlw 0Xfb iorwf inter,w ;輸出第7位 movwf PORTA bsf PORTA,1 ;發出一脈沖信號 rlf bits,1 decfsz count goto loop bsf PORTA,0 ;送鎖存信號
rrf bits1,1 movf bits1,w movwf bits decfsz count1 goto loop1 goto main end