PIC12F1822 >> Assembly

Interrupt On Change(IOC)


1. 設定TRISA輸入
2. 設定WPUA提昇電阻
3. 設定IOCAx正緣、負緣觸發
4. 開啟GPE、IOC中斷
5. 進入中斷後,清除IOC以及IOCA旗標





main.s

  list p=12f1822, r=hex
  #include <p12f1822.inc>
  __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF
  __config _CONFIG2, _LVP_OFF

  #define tmp 0x20

  org 0x0000
  goto start

  org 0x0004
  goto myisr
   
  org 0x0100
myisr:
  banksel INTCON
  bcf INTCON, 7
  bcf INTCON, 0

  banksel IOCAF
  movlw 0xff
  xorwf IOCAF, w
  andwf IOCAF, f
 
  banksel tmp
  btfss tmp, 0
  bcf PORTA, 0
  btfsc tmp, 0
  bsf PORTA, 0
  movlw 0xff
  xorwf tmp, f
  
  banksel INTCON
  bsf INTCON, 7
  retfie

start:
  banksel TRISA
  bcf TRISA, 0
  bsf TRISA, 3

  banksel OPTION_REG
  bcf OPTION_REG, 7

  banksel WPUA
  bsf WPUA, 3

  banksel PORTA
  bsf PORTA, 0

  banksel tmp
  clrf tmp
  
  banksel IOCAN
  bsf IOCAN, 3

  banksel INTCON
  bsf INTCON, 7
  bsf INTCON, 3
  bcf INTCON, 0

  goto $
  end

編譯

$ gpasm main.s

完成


返回上一頁