;
list p=10F200 ; list directive to define processor
#include __CONFIG _MCLRE_OFF & _CP_ON & _WDT_OFF ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. ; Const definition PIN_R EQU 2 PIN_G EQU 1 PIN_B EQU 0 PIN_DATA EQU 3 DEV_ID EQU 0x2 | 0x80 BIT_CNT EQU 0x08 ;***** VARIABLE DEFINITIONS rCnt EQU 0x11 ; red LED value gCnt bCnt ;tick tick IOTemp recvTemp devID bitsCnt ;dataPort dataPort EQU EQU EQU EQU EQU EQU EQU EQU EQU 0x12 0x13 0x13 TMR0 0x16 0x17 0x19 0x1A 0x1D GPIO ; green LED value ; blue LED value ; system tick EQU UpdateLED macro ledCnt,des ;movf tick,w ;subwf ledCnt,w movf ledCnt,w subwf tick,w rlf IOTemp,des endm ; if we use 38400 @ 4MHz 26 cycle per data ;********************************************************************** ORG 0xFF ; processor reset vector movlw 0 ; Internal RC calibration value is placed at location 0xFF by Microchip ; as a movlw k, where the k is a literal value. ORG 0x000 ; coding begins here movwf OSCCAL ; update register with factory cal value movlw DEV_ID ;DEV_ID=0X82送给W movwf devID ;w送给devid=0x82 movwf recvTemp ;w送给recvtemp=0x82 movlw 0x83 ; enalle pull up on input pin, prescaler 1:16 option movlw 0x00 tris GPIO ;00001000,gp3为输入,gp0,1,2为输出 movlw 0x07 movwf GPIO ;00000111,gp3输出0,gp0,1,2输出1. ;movlw 0x51 ;0B01010001 ; For 202/206 ;movwf 0;CMCON0 clrf rCnt clrf gCnt clrf bCnt ;清空单元 bsf FSR,2 btfss dataPort,PIN_DATA call SendID majorLoop btfss dataPort,PIN_DATA call B_WaitHalf UpdateLED gCnt,f nop btfss dataPort,PIN_DATA call R_WaitHalf ;侦测gpio第3位(gpio3)为1则跳过 UpdateLED bCnt,w movwf dataPort nop btfss dataPort,PIN_DATA call G_WaitHalf UpdateLED rCnt,f nop btfss dataPort,PIN_DATA call B_WaitHalf UpdateLED gCnt,f nop btfss dataPort,PIN_DATA call R_WaitHalf UpdateLED bCnt,w movwf dataPort nop btfss dataPort,PIN_DATA call G_WaitHalf UpdateLED rCnt,f goto majorLoop R_WaitHalf movlw 0x08 movwf bitsCnt UpdateLED rCnt,f UpdateLED gCnt,f call Delay4Cyc B_WaitFull UpdateLED bCnt,w movwf dataPort UpdateLED rCnt,f UpdateLED gCnt,f UpdateLED bCnt,w movwf dataPort call Delay4Cyc nop rrf recvTemp,f bcf recvTemp,7 btfsc dataPort,PIN_DATA bsf recvTemp,7 decfsz bitsCnt,f goto R_WaitFull UpdateLED rCnt,f UpdateLED gCnt,f UpdateLED bCnt,w movwf dataPort UpdateLED rCnt,f nop movf recvTemp,w btfsc FSR,2 goto R_ID movwf INDF addwf INDF,f incf INDF,f incfsz INDF,w decf INDF,f incf FSR,f goto Delay4Cyc R_ID subwf devID,w movlw 0xF1 btfss STATUS,Z movlw 0xF5 movwf FSR goto Delay4Cyc G_WaitHalf movlw 0x08 movwf bitsCnt UpdateLED gCnt,f UpdateLED movwf goto nop R_WaitFull UpdateLED UpdateLED UpdateLED movwf UpdateLED bCnt,w dataPort $+1 rCnt,f gCnt,f bCnt,w dataPort rCnt,f call Delay6Cyc ;nop ;call Delay4Cyc ;nop rrf recvTemp,f bcf recvTemp,7 btfsc dataPort,PIN_DATA bsf recvTemp,7 decfsz bitsCnt,f goto G_WaitFull UpdateLED gCnt,f UpdateLED bCnt,w movwf dataPort UpdateLED rCnt,f UpdateLED gCnt,f nop movf btfsc goto movwf addwf incf incfsz decf incf goto recvTemp,w FSR,2 G_ID INDF INDF,f INDF,f INDF,w INDF,f FSR,f Delay4Cyc G_ID subwf devID,w movlw 0xF1 btfss STATUS,Z movlw 0xF5 movwf FSR goto Delay4Cyc B_WaitHalf movlw 0x08 movwf bitsCnt UpdateLED bCnt,w movwf dataPort UpdateLED rCnt,f goto $+1 nop G_WaitFull UpdateLED gCnt,f UpdateLED bCnt,w movwf dataPort UpdateLED rCnt,f UpdateLED gCnt,f call Delay6Cyc ;nop ;call Delay4Cyc ;nop rrf recvTemp,f bcf recvTemp,7 btfsc dataPort,PIN_DATA bsf recvTemp,7 decfsz bitsCnt,f goto B_WaitFull UpdateLED bCnt,w movwf dataPort UpdateLED rCnt,f UpdateLED gCnt,f UpdateLED bCnt,w movwf dataPort movf recvTemp,w btfsc FSR,2 goto B_ID movwf INDF addwf INDF,f incf incfsz decf incf goto B_ID subwf movlw btfss movlw INDF,f INDF,w INDF,f FSR,f Delay4Cyc devID,w 0xF1 STATUS,Z 0xF5 movwf FSR Delay6Cyc goto Delay4Cyc Delay4Cyc retlw 0 ;END SendID bcf dataPort,0 ;gpio0清零 bsf STATUS,C ;进位标志位置1 movlw 0x09 ;w=0x09 movwf bitsCnt ;bitscnt=0x09 loop call Delay10Cyc call Delay10Cyc nop rrf recvTemp ;带进位右移(c=1) rlf dataPort ;循环左移带进位(c=0) decfsz bitsCnt,f goto loop call Delay10Cyc Delay10Cyc goto Delay8Cyc Delay8Cyc goto Delay6Cyc END 因篇幅问题不能全部显示,请点此查看更多更全内容