LIST P=PIC16F648A include p16f648a.inc __config _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _CP_OFF & _MCLRE_ON ;test ;SW control work mem definition inreg equ 0x20 ;input reg data save outreg equ 0x21 ;output reg data save nucnt1 equ 0x22 ;nutral cont flag reg nucnt2 equ 0x23 ;nutral cunter swtim1 equ 0x24 ;SW timer work1 swtim2 equ 0x25 ;SW timer work2 lopcnt1 equ 0x30 ;prg work loop counter1 lopcnt2 equ 0x31 ;prg work loop counter2 ;input pin data define swinl equ 0x0 ;input sw low swinh equ 0x1 ;input sw high swinp equ 0x2 ;input sw postion swinn equ 0x3 ;input sw nutral ;output pin data define poutll equ 0x4 ;out low_l poutlr equ 0x5 ;out low_r(p on) pouthi equ 0x6 ;out high ; org 0 ;Reset Vector goto init org 4 ;Interrupt Vector goto init ;**************** Initial Process ********************* org 5 init bsf STATUS,RP0 ;Change to Bank1 movlw h'0f' ;Set input(LOW4bit) mode data movwf TRISB ;Set PORTB to Input mode clrf TRISA ;Set PORTA to Output mode bcf STATUS,RP0 ;Change to Bank0 movlw h'ff' ;Set portA out H (NO use pin) movwf PORTA ;Output NO use pin H clrf outreg ;output init status light off movf PORTB,w ;input init SW status movwf inreg ;save input data clrf swtim1 ;clear tim1 clrf swtim2 ;clear tim2 clrf nucnt1 ;clear nut_control clrf nucnt2 ;clear nut_counter main nop movlw 0x14 ;loop counter1(10ms) movwf lopcnt1 mloop2 movlw 0xff ;loop counter2(0.5ms) movwf lopcnt2 mloop1 decfsz lopcnt2 ;count down cunter2 goto mloop1 decfsz lopcnt1,f ;Count down cunter1 goto mloop2 ;wait goto loop ; movf PORTB,w ;get input data movwf inreg ;save in data btfss inreg,swinn ;nutral test NOT logic goto mnucnt ;nutral count prossece clrf nucnt1 ;clear nutral flg clrf nucnt2 ;clear nutral count goto mchek2 mnucnt incf nucnt2,1 ;+1 movf nucnt2,w xorlw 0xf0 ;Nutral wait timer 2.5s btfsc STATUS,Z ;if = set nutcnt flg on bsf nucnt1,0 ;set nucnt flg ; mchek2 btfsc inreg,swinh goto mhigh ;goto ligth high on btfsc inreg,swinl ;*test point goto mlow ;goto ligth low on btfsc inreg,swinp goto mpos ;goto postin on clrf outreg mend movfw outreg movwf PORTB goto main ; mhigh movlw 0x40 ;bit6 on high movwf outreg goto mend ; mlow movlw 0x30 ;bit5,4 on low r,l movwf outreg goto mposnu ; mpos movlw 0x20 ;bit4 on low_r movwf outreg ;nutral control procces mposnu btfsc nucnt1,0 ;nutral flg check bcf outreg,5 ;clera bit4 low_r goto mend end