Dear All,
From last some years i am trying to make rf base remote control. i have got Circuit daigram, programming ( .ASM ) file. so i purches PIC programmer & make RF remote control & program it.
Now its working but its operation is latch type ( the channel output state is toggled each time its button is pressed: when the corresponding transmitter button is pressed, the output is turned on. By pressing the same button again, the channel output is turned off )
Actualy i have require Momentery type operation ( the channel output is turned ON while the corresponding transmitter button is pressed, and turned OFF when the button is released )
So anybody help me for change the program?
i am attaching both RX & TX .ASM file.
( My English Is Poor So plz unsderstand it )
================================================================
Program For RX
list p=16c72a
#include <p16c72a.inc>
__config _BODEN_ON & _CP_OFF & _PWRTE_ON & _WDT_ON & _XT_OSC
;****************** VARIABLE DEFINITIONS *****************************
cblock 0x20
DATA0 ; 1st byte of received data
DATA1 ; 2nd byte of received data
DATA2 ; 3rd byte of received data
DATA3 ; 4th byte of received data
DATA4 ; 1st byte of received data
DATA5 ; 2nd byte of received data
DATA6 ; 3rd byte of received data
DATA7
RA11
RA12
RA13
RA14
REGA
REGB
REGC
ORIGIN ; a reference used to increment TMRLOW
SX1TMR ; LED timer (low order)
SX2TMR ; LED timer (high order)
TMRLOW ; pulse width timer (low order)
TMRHIGH ; pulse width timer (high order)
HIGHWDTH ; high pulse width
LOWWDTH ; low pulse width
STATECNTR ; program state counter
BITCNTR ; data stream bit counter
FLAGS ; flags
ROLL_TEMP
endc
COUNTR equ BITCNTR ; misc. counter
;************************ DEFINE STATEMENTS **************************
; input and output definitions
#define STREAM PORTA,4 ; DATA stream
#define LED PORTA,5 ; LED
; Lables for the status counter
#define BEGN 0x00
#define BEGN1 0x01
#define HEADR 0x02
#define HEADR1 0x03
#define HIGHP 0x04
#define LOWP 0x05
#define RECRD 0x06
#define WAIT 0x07
#define VALID 0x08
#define IMPLMNT 0x09
; FLAGS is parced as follows
#define TOGGLE FLAGS, 0
#define HIGHLOW FLAGS, 1
;******************** Start of Program *******************************
;***********************************
;************************************
org 0x000 ; coding begins here
GOTO RESET
RESET
MOVLW H'01'
MOVWF RA11
MOVLW H'02'
MOVWF RA12
MOVLW H'03'
MOVWF RA13
clrf FLAGS ; clear flags
clrf PORTB ; initialize inputs and outputs
movlw BEGN ; setup the state counter to call BEGIN
movwf STATECNTR
call INITIAL
CLRF REGA
CLRF REGB
CLRF REGC
goto MAIN ; goto MAIN
;*********************************************************************
; MAIN
; The program continually loops in MAIN, calling out the
; necessary functions when needed.
;
; Input Variables:
; LRN -- learn button
; Output Variables:
; none
;*********************************************************************
MAIN
call TIMER
call CLOCK
movf STATECNTR, W ; Mask out the high order bits of
andlw B'00001111' ; STATECNTR (a noise guard)
addwf PCL, F ; The program clock (PCL) is incre-
goto BEGIN ; mented by STATECNTR in order
goto BEGIN1 ; to go to the appropiate routine
goto HEADER
goto HEADER1
goto HIGHPLSE
goto LOWPULSE
goto RECORD
goto WAIT4END
goto VALIDATE
goto IMPLEMNT
goto RESET ; These RESET commands correct
goto RESET ; erronious values of STATECNTR
goto RESET ; not caught by the mask above.
goto RESET
goto RESET
goto RESET
;*********************************************************************
; INITIAL
; This routine is continually called, initializing the OPTION
; and GPIO registers in addition to clearing the watchdog timer.
; This is done to insure that over the lifetime up the chip,
; these vital registers will never change due to noise.
;
; Output Variables: none
; Input Variables: none
;*********************************************************************
INITIAL
CLRWDT
clrf PORTA
clrf PORTB
CLRF PORTC
bcf STATUS,RP1 ;bank1 initialization
bsf STATUS,RP0 ;bank1
movlw H'10'
movwf TRISA
CLRF TRISC
clrf TRISB ;make PORTB all outputs
MOVLW H'81'
MOVWF OPTION_REG & 0x07F
bcf STATUS,RP0 ;select bank0
retlw 0
;*********************************************************************
; SETWATCH
; Initialize the pulse width timer registers.
;
; Input Variables:
; none
; Output Variables:
; ORIGIN
;*********************************************************************
SETWATCH
movf TMR0, W ; record TMR0's value in ORIGIN
movwf ORIGIN
clrf TMRLOW ; clear the low and high order timers
clrf TMRHIGH
retlw 0
;*********************************************************************
; CLOCK
; Continually updates TMRLOW and TMRHIGH.
;
; Input Variables:
; ORIGIN
; Output Variables:
; TMRLOW
; TMRHIGH
;*********************************************************************
CLOCK
clrwdt
movf ORIGIN, W ; TMRLOW is updated based on time
subwf TMR0, W ; passed since ORIGIN was set.
addwf TMRLOW, F ; TMRLOW resolution ~= 4us (like TMR0)
btfsc STATUS, C ; TMRLOW overflow ~= 1ms (2^8*4ms)
incf TMRHIGH, F ; TMRHIGH resolution ~= 1ms
nop ; TMRHIGH overflow ~= 0.24sec (2^8*1ms)
nop ;
nop ; Nop and subtraction commands ensure
movlw 2 ; ORIGIN equals TMR0 as called upon
subwf TMR0, W ; in line 2 of CLOCK. (ORIGIN must
movwf ORIGIN ; be updated to equal the value
retlw 0 ; of TMR0 at time of operation with
; ORIGIN.)
;*********************************************************************
; TIMER
; Continually updates two higher order timers (SX1TMR and
; SX2TMR) for use in LED timing.
;
; Input Variables:
; none
; Output Variables:
; SX1TMR
; SX2TMR
;*********************************************************************
TIMER
clrwdt
btfss TOGGLE ; TOGGLE forces this routine to spend
goto TIMER1 ; 1/2 of TMR0 in TIMER and 1/2 in
movlw B'01111111' ; TIMER1.
addwf TMR0, W ; TOGGLE toggles back and forth to a
btfss STATUS, C ; one the rate TMR0 overflows.
retlw 0 ; TMR0 overflow ~= 1ms (2^8*4us)
bcf TOGGLE ;
incfsz SX1TMR, F ; SX1TMR resolution ~= 1ms
retlw 0 ; SX1TMR overflow ~= 0.25sec (2^8*1ms)
incf SX2TMR, F ; SX2TMR resolution ~= 0.25sec
retlw 0 ; SX2TMR overflw ~= 1min (2^8*0.23sec)
TIMER1
movlw B'01111111' ; Timer routine spends half its time
addwf TMR0, W ; in TIMER1 waiting to set TOGGLE
btfsc STATUS, C ; to one again
retlw 0
bsf TOGGLE
retlw 0
;*********************************************************************
; BEGIN
; This function looks for a possible start to the data stream.
;
; Input Variables:
; STREAM
; Output Variables:
; none
;*********************************************************************
BEGIN
btfsc STREAM
incf STATECNTR, F ; Make state BEGIN1
goto MAIN
BEGIN1
btfsc STREAM
goto MAIN
call SETWATCH
incf STATECNTR, F ; Make state HEADER
goto MAIN
;*********************************************************************
; HEADER
; Detects a valid header.
;
; Input Variables:
; STREAM
; Output Variables:
; none
;*********************************************************************
HEADER
btfsc STREAM ; The program loops here until 1.25ms
goto RESTART ; passes and if the data is still
btfss TMRHIGH, 0 ; low. If both hold true -> HEADER1.
goto MAIN ; 1.25ms occurs when:
movlw D'64' ; TMRHIGH = 1 ~= 2^8*4us = 1ms
andwf TMRLOW, W ; TMRLOW = 64 ~= 64*4us = 0.25ms
btfsc STATUS, Z
goto MAIN
incf STATECNTR, F ; Make state HEADER1
goto MAIN
HEADER1
movlw D'6' ; If the data goes high before 6ms
subwf TMRHIGH, W ; then the header is valid, else
btfss STATUS, C ; restart.
goto HEADER2 ; TMRHIGH = 6 = 6*1ms = 6ms
goto RESTART
HEADER2
btfss STREAM
goto MAIN
call SETWATCH
movlw D'64' ; Initiate BITCNTR to 32 in order to
movwf BITCNTR ; receive 32 bits of the data stream.
incf STATECNTR, F ; Make state HIGHPLSE
goto MAIN
;*********************************************************************
; HIGHPLSE
; Times the width of high pulses.
;
; Input Variables:
; STREAM
; Output Variables:
; none
;*********************************************************************
HIGHPLSE
btfsc TMRHIGH, 0 ; If TMRLOW overflows then RESTART
goto RESTART
btfsc STREAM
goto MAIN
movf TMRLOW, W ; Move the pulse width value to
movwf HIGHWDTH ; HIGHWDTH for later calculations.
call SETWATCH
incf STATECNTR, F ; Make state LOWPULSE
goto MAIN
;*********************************************************************
; LOWPULSE
; Times the width of low pulses.
;
; Input Variables:
; none
; Output Variables:
; none
;*********************************************************************
LOWPULSE
btfsc TMRHIGH, 0 ; If TMRLOW overflows then make
goto LOW2 ; state HEADER.
btfss STREAM
goto MAIN
movf TMRLOW, W ; Move the pulse width value to
movwf LOWWDTH ; LOWWDTH for later calculations.
call SETWATCH
incf STATECNTR, F ; Make state RECORD
goto MAIN
LOW2
movlw HEADR
movwf STATECNTR ; Make state HEADER if lowpulse is too
goto MAIN ; long.
;*********************************************************************
; RECORD
; Records each bit as it comes in from the data stream.
;
; Input Variables:
; STREAM
; Output Variables:
; DATA0
; DATA1
; DATA2
; DATA3
;*********************************************************************
RECORD
movf HIGHWDTH, W
subwf LOWWDTH, W ; The state of the carry bit after
rrf DATA7, F
rrf DATA6, F
rrf DATA5, F
rrf DATA4, F
rrf DATA3, F ; this operation reflects the data
rrf DATA2, F ; logic. This is then rotated
rrf DATA1, F ; into the storage bytes.
rrf DATA0, F
movlw HIGHP
movwf STATECNTR
decfsz BITCNTR, F
goto MAIN
movlw D'8' ; Starting here and including RECORD1
movwf COUNTR ; a check is made to make sure that
movlw DATA0 ; the data is not composed entirely
movwf FSR ; of 1s.
RECORD1
movlw 0xFF
xorwf INDF, W ; Use indirect referencing (see the
btfss STATUS, Z ; 12CE518 data sheet) to point to
goto RECORD2 ; DATA0 -- DATA3 on subsequent loops
incf FSR, F ; in RECORD1.
decfsz COUNTR, F
goto RECORD1
goto RESTART
RECORD2
movlw WAIT
movwf STATECNTR ; Make state WAIT4END
goto MAIN
;*********************************************************************
; WAIT4END
; Wait for the guard time at the end of the code word before
; attempting to receive another code word.
;
; Input Variables:
; STREAM
; Output Variables:
; none
;*********************************************************************
WAIT4END
btfsc HIGHLOW ; HIGHLOW is set to indicate that the
goto WAIT1 ; data has transitioned from a high
btfsc STREAM ; to a low.
goto MAIN
call SETWATCH
bsf HIGHLOW
WAIT1
btfss STREAM
goto WAIT2
bcf HIGHLOW
goto MAIN
WAIT2
btfss TMRHIGH, 3 ; If the low period is greater than
goto MAIN ; 8ms (2^3*1ms) then the guard time
bcf HIGHLOW ; has been reached.
incf STATECNTR, F ; Make state VALIDATE
goto MAIN
;*********************************************************************
; VALIDATE
; Checks that the transmission received is from the valid
; transmitter.
;
; Input Variables:
; DATA0
; DATA1 (only the first two bits)
; Output Variables:
; none
;*********************************************************************
VALIDATE
MOVF DATA4,W
XORWF RA11,0
BTFSS STATUS,Z
GOTO RESTART
TT
incf STATECNTR, F ; Make state IMPLEMENT
goto MAIN
;*********************************************************************
; IMPLEMNT
; Implements the outputs specified by the received code word.
;
; Input Variables:
; DATA1
; Output Variables:
; S0
; S1
; S2
;*********************************************************************
IMPLEMNT
MOVF DATA1,W
XORWF ROLL_TEMP,0
BTFSC STATUS,Z
GOTO RESTART
MOVF DATA1,W
MOVWF ROLL_TEMP
MOVF DATA7,W
ANDLW H'0F'
MOVWF DATA7
SUBLW H'07'
BTFSC STATUS,C
GOTO PC1
MOVF DATA7,W
CALL PIN_DATA
MOVWF DATA7
MOVF REGB,W
IORWF DATA7,0
XORLW H'FF'
BTFSS STATUS,Z
GOTO NOTFF
MOVF DATA7,W
ANDWF REGB,1
GOTO XX
NOTFF
COMF DATA7,0
IORWF REGB,1
XX
MOVF REGB,W
MOVWF PORTB
clrf SX1TMR ; initialize the timers for the
clrf SX2TMR ; outputs
goto RESTART
PC1
MOVF DATA7,W
CALL PIN_DATA
MOVWF DATA7
MOVF REGC,W
IORWF DATA7,0
XORLW H'FF'
BTFSS STATUS,Z
GOTO NOTFF1
MOVF DATA7,W
ANDWF REGC,1
GOTO XX1
NOTFF1
COMF DATA7,0
IORWF REGC,1
XX1
MOVF REGC,W
MOVWF PORTC
clrf SX1TMR ; initialize the timers for the
clrf SX2TMR ; outputs
goto RESTART
PIN_DATA
ADDWF PCL,1
RETLW B'11111110'
RETLW B'11111101'
RETLW B'11111011'
RETLW B'11110111'
RETLW B'11101111'
RETLW B'11011111'
RETLW B'10111111'
RETLW B'01111111'
RETLW B'11111110'
RETLW B'11111101'
RETLW B'11111011'
RETLW B'11110111'
RETLW B'11101111'
RETLW B'11011111'
RETLW B'10111111'
RETLW B'01111111'
;*********************************************************************
; RESTART
; Sets the State Counter to BEGIN so that the receive sequence
; is restarted.
;
; Input Variables:
; none
; Output Variables:
; none
;*********************************************************************
RESTART
movlw BEGN ; restart receive sequence and return
movwf STATECNTR ; to MAIN
goto MAIN
;*********************************************************************
end ; directive 'end of program'
===============================================================
===============================================================
===============================================================
===============================================================
Program For TX
list p=16F628
#include <p16f628.inc>
__CONFIG _PWRTE_ON & _WDT_OFF & _CP_ALL & _LVP_OFF & _MCLRE_OFF & _BODEN_ON & _INTRC_OSC_NOCLKOUT
; ------------------------------------------------
cblock 0x20
DATA0
DATA1
DATA2
DATA3
DATA4
DATA5
DATA6
DATA7
RA11
RA12
RA13
RA14
TEMP
DATA_TEMP
TEMP_CNT
COUNT
KEYCODE
KEYS
endc
;************************ DEFINE STATEMENTS **************************
; PIC12CE518 setup parameters
; input and output definitions
#define ROW1 PORTB,0
#define ROW2 PORTB,1
#define ROW3 PORTB,2
#define ROW4 PORTB,3
#define COL1 PORTB,4
#define COL2 PORTA,5
#define COL3 PORTB,6
#define COL4 PORTB,7
#define TDATA PORTA,0
;******************** Start of Program *******************************
org 0x0000 ; processor reset vector
goto RESET
RESET
MOVLW H'01'
MOVWF DATA4
MOVLW H'02'
MOVWF DATA5
MOVLW H'03'
MOVWF DATA6
MOVWF DATA0
MOVWF DATA1
MOVWF DATA2
MOVWF DATA3
MOVLW H'FF'
MOVWF DATA7
MOVLW H'01'
MOVWF RA11
CLRF RA12
CLRF RA13
CLRF RA14
CALL INITIAL
goto MAIN ; goto MAIN
;*********************************************************************
; MAIN
; The program continually loops in MAIN, calling out the
; necessary functions when needed.
;
; Input Variables:
; LRN -- learn button
; Output Variables:
; none
;*********************************************************************
MAIN
MOVLW H'00'
MOVWF PORTA
CALL SCAN
MOVF KEYCODE,W
XORLW H'FF'
BTFSC STATUS,Z
GOTO MAIN
MOVF KEYCODE,W
MOVWF DATA7
INCF DATA0,1
INCF DATA1,1
KEYOFF
CALL TRANSMITT
CALL SCAN
MOVF KEYCODE,W
XORLW H'FF'
BTFSS STATUS,Z
GOTO KEYOFF
GOTO MAIN
;*****************************
;*********************************************************************
; INITIAL
; This routine is continually called, initializing the OPTION
; and GPIO registers in addition to clearing the watchdog timer.
; This is done to insure that over the lifetime up the chip,
; these vital registers will never change due to noise.
;
; Output Variables: none
; Input Variables: none
;*********************************************************************
INITIAL
clrf PORTA
clrf PORTB
movlw b'00000111' ; disable comparators
movwf CMCON
bsf STATUS,RP0
movlw B'00000000'
movwf TRISA
movlw B'00001111'
MOVWF TRISB
MOVLW H'01'
MOVWF OPTION_REG & 0x07F
bcf STATUS,RP0
retlw 0
;------****************
TRANSMITT
MOVLW .12
MOVWF COUNT
PREAMB
BCF TDATA
CALL DLY400
BSF TDATA
CALL DLY400
DECFSZ COUNT , 1
GOTO PREAMB
BCF TDATA
MOVLW .10
MOVWF COUNT
HEAD
CALL DLY400
DECFSZ COUNT , 1
GOTO HEAD
; MOVLW .16
; CALL HOP
MOVLW .8
MOVWF TEMP_CNT ; BYTES
MOVLW DATA0
MOVWF FSR
MOVF INDF,W
MOVWF DATA_TEMP
BYTES
MOVLW .8
MOVWF COUNT ; BITS
BITS BSF TDATA
CALL DLY400
RRF DATA_TEMP ,1
BTFSC STATUS,C
BCF TDATA
CALL DLY400
BCF TDATA
CALL DLY400
DECFSZ COUNT , 1
GOTO BITS
INCF FSR,1
MOVF INDF,W
MOVWF DATA_TEMP
DECFSZ TEMP_CNT , 1
GOTO BYTES
MOVLW .1
CALL HOP
MOVLW .39
MOVWF COUNT
GURD
CALL DLY400
DECFSZ COUNT , 1
GOTO GURD
RETLW 0
HOP MOVWF COUNT
HOP1 BSF TDATA
CALL DLY400
CALL DLY400
BCF TDATA
CALL DLY400
BSF TDATA
CALL DLY400
BCF TDATA
CALL DLY400
CALL DLY400
DECFSZ COUNT , 1
GOTO HOP1
RETURN
;-------------------------------------------
DLY400
MOVLW .90
GOTO MICRO4
;*** 1 millisecond delay routine ***
ONEMSEC MOVLW D'249' ; 1 microsec for load W
; loops below take 248 X 4 + 3 = 995
MICRO4
MOVWF TEMP
MICRO41
NOP
DECFSZ TEMP,1
GOTO MICRO41
RETURN
;**********-----------------********************
SCAN
MOVLW H'FF'
MOVWF KEYCODE
BCF PORTB,4
MOVF PORTB,W
BSF PORTB,4
ANDLW B'00001111'
MOVWF KEYS
XORLW B'00001111'
BTFSC STATUS,Z
GOTO ROW22
CALL TABLE1
MOVWF KEYCODE
RETLW 0
ROW22 BCF PORTB,5
MOVF PORTB,W
BSF PORTB,5
ANDLW B'00001111'
MOVWF KEYS
XORLW B'00001111'
BTFSC STATUS,Z
GOTO ROW33
CALL TABLE2
MOVWF KEYCODE
RETLW 0
ROW33 BCF PORTB,6
MOVF PORTB,W
BSF PORTB,6
ANDLW B'00001111'
MOVWF KEYS
XORLW B'00001111'
BTFSC STATUS,Z
GOTO ROW44
CALL TABLE3
MOVWF KEYCODE
RETLW 0
ROW44 BCF PORTB,7
MOVF PORTB,W
BSF PORTB,7
ANDLW B'00001111'
MOVWF KEYS
XORLW B'00001111'
BTFSC STATUS,Z
RETLW 0
CALL TABLE4
MOVWF KEYCODE
RETLW 0
TABLE1
BTFSS KEYS,3
RETLW H'0C'
BTFSS KEYS,2
RETLW H'08'
BTFSS KEYS,1
RETLW H'04'
BTFSS KEYS,0
RETLW H'00'
RETLW H'FF'
TABLE2
BTFSS KEYS,3
RETLW H'0D'
BTFSS KEYS,2
RETLW H'09'
BTFSS KEYS,1
RETLW H'05'
BTFSS KEYS,0
RETLW H'01'
RETLW H'FF'
TABLE3
BTFSS KEYS,3
RETLW H'0E'
BTFSS KEYS,2
RETLW H'0A'
BTFSS KEYS,1
RETLW H'06'
BTFSS KEYS,0
RETLW H'02'
RETLW H'FF'
TABLE4
BTFSS KEYS,3
RETLW H'0F'
BTFSS KEYS,2
RETLW H'0B'
BTFSS KEYS,1
RETLW H'07'
BTFSS KEYS,0
RETLW H'03'
RETLW H'FF'
END
===============================================================