はじめてPICのアセンブリ言語を書いた。
アセンブリ言語の書き方がいろいろあるようで、どの書き方が正しいのかわからない。
_delay関数の有無がわからなかったので、2重ループで処理。
;-----------------------------------------------------------------
; pic12f683_asm
;
; Lチカ(delay型)
;-----------------------------------------------------------------
#include P12F683.INC
__config _INTOSCIO&_MCLRE_ON&_BOD_ON&_WDT_OFF&_CPD_OFF&_CP_OFF&_PWRTE_ON
count1: equ 0x20 ; delay loop counter1
count2: equ 0x21 ; delay loop counter2
org 0
bsf STATUS,RP0 ; Bank1
movlw 0x60
movwf OSCCON ; 4MHzに設定
bcf STATUS,RP0 ; Bank0
movlw 0x07
movwf CMCON0 ; コンパレータOFF
bsf STATUS,RP0 ; Bank1
clrf ANSEL ; アナログ入力を使わない(デジタルI/Oへ設定)
clrf TRISIO ; GPIOを全部出力に設定
bcf STATUS,RP0 ; Bank0
loop: bsf GPIO,GP2 ; GP2=1
call delay
bcf GPIO,GP2 ; GP2=0
call delay
goto loop
delay: movlw 0xff
movwf count1
wloop1: movlw 0xff
movwf count2
wloop2: decfsz count2 ; count2から1を減算し、0なら次の命令をスキップ
goto wloop2
decfsz count1 ; count1から1を減算し、0なら次の命令をスキップ
goto wloop1
return
end
「久しぶりに8ピンPIC」のソースコードをアセンブリ言語で書き換えた。