

         DEVICE   PIC16C84,HS_OSC,WDT_OFF,PROTECT_OFF



;this is a test source for PicSim (device=16C84)
;the commands are from Microchip, the assembler from parallax
;Copyright 04.02.97 Dirk Düsterberg





START	ADDWF	0Ch,0	; C,DC,Z    add w and fileregister to w
	ADDWF	0Ch,1	; C,DC,Z    add w and fileregister to fileregister


	ANDLW	115	; Z         literal and w to w

	
	ANDWF	0Ch,0	; Z	    fileregister and w to w
	ANDWF	0Ch,1	; Z	    fileregister and w to fileregister


	BCF	0Ch,7	;	    clear bit from fileregister
	BSF	0Ch,7	;	    set bit from fileregister


	BTFSC	0Ch,4	;	    skip next command if bit 0
	BTFSS	0Ch,5	;	    skip next command if bit 1


	CALL	LABEL	;	    call subroutine


	CLRF	0Ch	; Z	    clear fileregister
	CLRW		; Z	    clear w
	CLRWDT		; TO,PD	    clear watchdogtimer

	
	COMF	0Ch,0	; Z	    complement from fileregister to w
	COMF	0Ch,1	; Z	    complement from fileregister to fileregister


	DECF	0Ch,0	; Z	    count fileregister down to w
	DECF	0Ch,1	; Z	    count fileregister down to fileregister


	DECFSZ	0Ch,0	;	    count fileregister down to w and springe falls 0
	DECFSZ	0Ch,1	;	    count fileregister down to fileregister and springe falls 0


	INCF	0Ch,0	; Z	    count fileregister up to w
	INCF	0Ch,1	; Z	    count fileregister up to fileregister

	
	INCFSZ	0Ch,0	;	    count fileregister up to w and springe falls 0
	INCFSZ	0Ch,1	;	    count fileregister up to fileregister and springe falls 0

	
	IORLW	115	; Z	    write literal or w in w


	IORWF	0Ch,0	; Z	    write fileregister or w to w
	IORWF	0Ch,1	; Z	    write fileregister or w to fileregister


	MOVF	0Ch,0	; Z	    write fileregister to w
	MOVF	0Ch,1	; Z	    write fileregister to fileregister

	
	MOVLW	115	;	    write literal to w


	MOVWF	0Ch	; 	    write w to fileregister


	NOP		; 	    no operation


	OPTION		;	    write w in optionregister


	RLF	0Ch,0	; C	    rotate fileregister left to w
	RLF	0Ch,1	; C	    rotate fileregister left to fileregister

	
	RRF	0Ch,0	; C	    rotate fileregister right to w
	RRF	0Ch,1	; C	    rotate fileregister right to fileregister


	SLEEP		; TO,PD     do the sleep mode


	SUBWF	0Ch,0	; C,DC,Z    substract w from fileregister to w
	SUBWF	0Ch,1	; C,DC,Z    substract w from fileregister to fileregister


	SWAPF	0Ch,0	;	    swap nibbles from fileregister to w
	SWAPF	0Ch,1	;	    swap nibbles from fileregister to fileregister


	TRIS	ra	;	    write w in tristate Register from port b
	TRIS	rb	;	    write w in tristate Register from port b


;	XORLW	#15	; Z	    write literal exclusiv oder w to w

	
	XORWF	0Ch,0	; Z	    write w exclusiv oder fileregister to w
	XORWF	0Ch,1	; Z	    write w exclusiv oder fileregister to fileregister

	
	
	GOTO	START










LABEL	MOV	RA,#05h	;          write literal to port
	MOV	RB,#0aah		 


	MOV	!RA,#0h	;          write literal ins tristate register
	MOV	!RB,#45

	
	MOV	w,RA	;          write port to w
	MOV	w,RB




	SETB	RA.0	;          set bit 0 from Port A
	clrb	RA.0	;          clear bit 0 from Port A


	XOR	RA,#00000010b	;  toggle (exclusive or) bit 1 from port A

	BTFSC	RA.1	;          skip next command if not bit

	RETW	127 	;	   jump back from subroutine and write literal to w
	RETW	63 	;	   jump back from subroutine and write literal to w
         
	




;indirect file addressing (clear fileregister betwen 0Ch and 1fh)


	mov	FSR,#0Ch	;file adress pointer to 10h
	

milka	clr	INDIRECT	;clear the indirect address
	inc	FSR		;next register
	sb	FSR.5		;all done ? (FSR >= 20h ?)
	jmp	milka		;do it
	







;Data EEProm access

witedat mov     EEADR,0eh	;0e is my address
        
        mov     EEDATA,0fh	;0f is my data
        

        setb    STATUS.5	;select PAGE1

        setb    EECON1.2	;set EEPROM write enable

	mov     EECON2,#55h
	mov     EECON2,#0AAh
        
        setb    EECON1.1	;init a write cycle





wait    sb	EECON1.4	;wait for write to finish
        jmp	wait
	clr	EECON1		;EEPROM write disable & int accept

        clrb	STATUS.5	;select PAGE0
        




readdat clrb	STATUS.5
	mov	EEADR,W
        setb    STATUS.5            ;select PAGE1

        setb    EECON1.0            ;EEPROM read
        clrb    STATUS.5            ;select PAGE0
 
        mov	w,EEDATA
        
	GOTO	START

