PICのRMW問題 投稿者:ノンノ 投稿日:2009/09/27(Sun) 22:31 No.1491
PIC16Fで9bitのデータをRA,RBに分割して出します。 d0→RA0 d1→RA1 d2→RA2 d3→RA3 d4→RB1 d5→RB2 d6→RB3 d7→RB4 d8→RB5 の様にしますが、他のポートに影響しないようにしたいと思います。 一部ですが、上の方で組み替え、「実際 port、tris出力」で一気に出力しています。 もっと気の利いた方法はないでしょうか?
;ポート替え&RMW pta equ 040h ptb equ 041h tra equ 042h trb equ 043h dspd equ 044h sgdt equ 045h dsgdt equ 046dh dgdt equ 047h ddgdt equ 048h zrsp equ 049h dgid equ 04ah fig equ 050h ;
dma equ B'00001111' ;bit移動位置 dmb equ B'00111110' ; ;***************** start: ; movf fig,w movwf sgdt ; movlw 080h ; movwf dgdt ;データを得る xorwf sgdt,w ;データを逆転してL iorwf dgdt,w ; movwf dsgdt ;data仮格納 ;portaの準備 xorwf pta,w ;portaビットマスク andlw dma ; xorwf pta ;porta格納 ;portbの準備 swapf dsgdt ;仮データ上下逆転 rlf dsgdt,w ;仮データー左シフト xorwf ptb,w ;portbビットマスク andlw dmb ; xorwf ptb ;portb格納 ;***************** movf dgdt,w ;H xorwf tra,w ;trisaビットマスク andlw dma ; xorwf tra ;trisa格納 movf dgdt,w ;H xorwf trb,w ;trisbビットマスク andlw dmb ; xorwf trb ;trisb格納 movf sgdt,w ;データを andwf dgdt,w ;tris=Lに btfss status,z ; zが一致して 1=zero >スキップ bcf ptb,5 ;w=1 フロートは,0-on wが 1=H skip: ;w=0 フロートは,1-off ;****************: ;実際 port、tris出力 movf pta,w movwf porta movf ptb,w movwf portb movf tra,w movwf trisa movf trb,w movwf trisb ;***************** end
|