⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 receiver.asm

📁 pic mcu received demo program , this progam must be used with the pic_trasmit.rar file !
💻 ASM
字号:
   
;~~~~~~~~~~~~~~~~~~~~~~~~~ -- --- ~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;		   
;			   Hardware Settings
;
;	I/O   Active	Functional Description		    
;
;	GP0	1	LED1	  				
;	GP1	1	LED2					
;	GP2	1	LED3			        	
;	GP3	1	signal in			
;	GP4	1	LED4					
;	GP5	1	receive signal LED						
;

 processor 12CE519
 include <P12ce519.inc>

;********************* USER DEFINED Register definitions ******************

W_STK		equ	0x7  	;backup W value
STATUS_STK	equ	0x8	;backup	STATUS reg.
PCLATH_STK	equ	0x9	;backup Page flag
TIMES		equ	0xa	;apply to count
TIMESd		equ	0xb	;apply to count
TIMESp		equ	0x1b
countp		equ	0xc 	;apply to count
countd		equ	0xd	;apply to count

recCODE		equ	0xe	
recBIT		equ	0xf
first		equ	0x10	;[0]
FAN		equ	0x11	;[1]

INITcode	equ	0x12
DEVNOcode	equ	0x13
INSTcode	equ	0x14
ENDcode		equ	0x15

rINITcode	equ	0x16	;learn code
rDEVNOcode	equ	0x17
rINSTcode	equ	0x18
rENDcode	equ	0x19

GPIO_STK	equ	0x1a


; end USER DEFINED Register definitions

;**************************************************************************
; program start and interupt definition
;**************************************************************************
	org	0x00

power_on_and_reset
	call	InitPorts	;[21]
	
ss	btfsc	STATUS,7
	goto	int_handler	;if weak up from sleep

sp	
	call	delay01
	call	delay01
	bcf	GPIO,5
	sleep
	nop

;**************************************************************************

;This routine will define all initial value of PORTS and Registers.

;**************************************************************************

InitPorts

	movlw	B'001000'	;Port direction
	TRIS	GPIO
	movlw	B'000000'	;Port initial value
	movwf	GPIO
	movlw	B'00000000'
	OPTION	
	
InitRegs			
	clrf	INITcode
	clrf	DEVNOcode
	clrf	INSTcode
	clrf	ENDcode	
	
	movlw	B'11000011'
	movwf	rINITcode
	movlw	B'00001001'
	movwf	rDEVNOcode
	clrf	rINSTcode
	movlw	B'01100000'
	movwf	rENDcode

	return

;**************************************************************************

learn
	nop
	bsf	GPIO,5		;switch on LED

	movlw	D'8'		;INIT code bit
	movwf	recBIT
	call	receive		;get code
	movf	recCODE,0	;store the code
	movwf	rINITcode
	
	movlw	D'8'		;DEVNO code bit
	movwf	recBIT
	call	receive		;get code
	movf	recCODE,0	;store the code
	movwf	rDEVNOcode
	
	movlw	D'8'		;INST code bit
	movwf	recBIT
	call	receive		;get code
	movf	recCODE,0	;store the code
	movwf	rINSTcode
	
	movlw	D'8'		;END code bit
	movwf	recBIT
	call	receive		;get code
	movf	recCODE,0	;store the code
	movwf	rENDcode
	bsf	first,0		;set not first time anymore
	bcf	GPIO,5		;switch off LED
	goto	sp		;finish	

;**************************************************************************	

int_handler
	bsf	GPIO,5		;switch on LED

	movlw	D'8'		;INIT code bit
	movwf	recBIT
	call	receive		;get code
	movf	recCODE,0	;store the code
	movwf	INITcode
	
	movlw	D'8'		;DEVNO code bit
	movwf	recBIT
	call	receive		;get code
	movf	recCODE,0	;store the code
	movwf	DEVNOcode
	
	movlw	D'8'		;INST code bit
	movwf	recBIT
	call	receive		;get code
	movf	recCODE,0	;store the code
	movwf	INSTcode
	
	movlw	D'8'		;END code bit
	movwf	recBIT
	call	receive		;get code
	movf	recCODE,0	;store the code
	movwf	ENDcode
		
	call	Decode		;[16]
	goto 	testrc		;for check received code


;**************************************************************************

receive
	clrf	recCODE
reclp	
	call	delayf
	btfss	GPIO,3		;received code is 0 or 1?	=[31]
	goto	rec0		;if the code is 0
	goto	rec1		;if the code is 1
	
rec0	nop
	bcf	STATUS,C
	goto	rrcode
rec1	bsf	STATUS,C
	goto	rrcode

rrcode	rlf	recCODE,1	
	decfsz	recBIT,1	;finished?
	goto	reclp		;if no
	return

;**************************************************************************

Decode
	bcf	GPIO,5		;switch off LED
	movf	rINITcode,0	;check INIT code[18]
	subwf	INITcode,0
	btfss	STATUS,Z
	return			;if wrong

	movf	rENDcode,0	;check END code
	subwf	ENDcode,0
	btfss	STATUS,Z
	return			;if wrong

	movf	rDEVNOcode,0	;check DEVNO code
	subwf	DEVNOcode,0
	btfss	STATUS,Z	;
	return			;if wrong

DN1
	movlw	B'00000001'	;check INST code is cycle?
	subwf	INSTcode,0
	btfss	STATUS,Z
	goto	DN2		;if wrong
E1	clrf	GPIO
	bsf	GPIO,0
	return

DN2
	movlw	B'00000010'	;check INST code is cycle?
	subwf	INSTcode,0
	btfss	STATUS,Z
	goto	DN3		;if wrong
E2	clrf	GPIO
	bsf	GPIO,1
	return

DN3
	movlw	B'00000011'	;check INST code is cycle?
	subwf	INSTcode,0
	btfss	STATUS,Z
	goto	DN4		;if wrong
E3	clrf	GPIO
	bsf	GPIO,2
	return

DN4
	movlw	B'00000100'	;check INST code is cycle?
	subwf	INSTcode,0
	btfss	STATUS,Z
	goto	NF		;if wrong
E4	clrf	GPIO
	bsf	GPIO,4
	return

NF
	movlw	B'01000010'	;check INST code is On or Off?
	subwf	INSTcode,0
	btfss	STATUS,Z
	return			;if wrong

	btfss	FAN,1		;FAN on?
	goto	Fon		;if no
	goto	Foff			

Fon	bsf	FAN,1
	movf	GPIO_STK,0
	movwf	GPIO
	return

Foff	bcf	FAN,1
	movf	GPIO,0
	movwf	GPIO_STK
	movlw	B'00001111'
	andwf	GPIO_STK,1
	clrf	GPIO
	return

;**************************************************************************

testrc				;test receive code
	movlw	D'8'		;INIT code bit
	movwf	recBIT
	movf	INITcode,0
	movwf	recCODE
	call	Print

	movlw	D'8'		;DEVNO code bit
	movwf	recBIT
	movf	DEVNOcode,0
	movwf	recCODE
	call	Print

	movlw	D'8'		;INST code bit
	movwf	recBIT
	movf	INSTcode,0
	movwf	recCODE
	call	Print

	movlw	D'8'		;END code bit
	movwf	recBIT
	movf	ENDcode,0
	movwf	recCODE
	call	Print
	goto	sp		;finish


Print
	bcf	GPIO,5
	call	delay01
	call	delay01
	call	delay01
	call	delay01
printlp	
	call	delay01
	call	delay01
	call	delay01
	call	delay01
	bcf	GPIO,5
	call	delay01
	call	delay01
	call	delay01
	call	delay01

	bsf	GPIO,5
	rlf	recCODE,1
	btfsc	STATUS,C
	goto	on
	goto	off
	
on	bsf	GPIO,4
	goto	ckkbit
off	bcf	GPIO,4
	goto	ckkbit

ckkbit
	decfsz	recBIT,1
	goto	printlp
	call	delay01
	call	delay01
	call	delay01
	call	delay01
	bcf	GPIO,5
	call	delay01
	call	delay01
	call	delay01
	call	delay01
	return

;**************************************************************************

delayf				;apply to frequency of receive signal
	movlw	D'1'
	movwf	TIMESd
	movlw	D'10'		;F=12+[(X-1)x3]  X=10  (14+(12+27)=53us)about 20kHz
	movwf	countd
	goto	dlyloop2

dlyloop2
	decfsz	countd,1
	goto	dlyloop2	;no,check again
	decfsz	TIMESd,1	;TIMES-1=0?
	goto	dlyloop2	;no,loop again
	return

delay01				;apply to key
	movlw	D'155'
	movwf	TIMESd
	clrf	countd
	goto	delayloop

delayd				;apply to receive delay time
	movlw	D'1'
	movwf	TIMESd
	movlw	D'2'		;D=12+[(X-1)x3]  X=2
	movwf	countd
	goto	delayloop

delay04			
	movlw	D'20'
	movwf	TIMESd
	clrf	countd
	goto	delayloop

delay255			;apply to reset	
	movlw	D'255'
	movwf	TIMESd
	clrf	countd
	goto	delayloop

delayloop
	decfsz	countd,1
	goto	delayloop	;no,check again
	decfsz	TIMESd,1	;TIMES-1=0?
	goto	delayloop	;no,loop again
	return

;**************************************************************************

;This routine will start TMR0 to count time.

;**************************************************************************

StartTMR0
	clrf	TMR0
	return

;**************************************************************************

	end	




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -