I've compiled and ran this but it still hangs meaning the output is still on then a few seconds later goes off. As I noted PORTA needs to be cleared but with the exception of PORTA.0 ( my serin pin). By adding clrf PORTB for a split second they come on and go off immediately while still transmitting. I wonder if if by timing out after receiving is causing PORTB to now act that way. Is this to fast "at 4MHz Timer1 overflows in 65536 * 1uS (~65.5mS)" ? and how could I adjust this?
@ DEVICE PIC16F628a,XT_OSC
@ DEVICE pic16F628a, WDT_OFF
@ DEVICE pic16F628a, PWRT_ON
@ DEVICE pic16F628a, MCLR_ON
@ DEVICE pic16F628a, BOD_ON
@ DEVICE pic16F628a, LVP_OFF
@ DEVICE pic16F628a, CPD_OFF
@ DEVICE pic16F628a, PROTECT_OFF
DEFINE OSC 4
DEFINE NO_CLRWDT 1 ' Watchdog timer is disabled, so we don't need to reset it
DEFINE INTHAND RESET_VT ' Interrrupt on Timer1 overflow to reset outputs in 65.5mS
' if no serial data received in this time period
TMR1IF var PIR1.0 ' Timer1 overflow interrupt flag (reset in int handler)
TMR1IE var PIE1.0 ' Timer1 interrupt enable bit
CMCON=%00000111
vrcon=0
trisa = %00000001
trisb = %00000000
PORTA = 0
PORTB = 0
serpin VAR porta.0 'serial input pin
address con %0010000000000001
add1 VAR WORD
address1 var byte
address2 var byte
address3 var byte
address4 var byte
addA var byte '0-7
addB var byte '8-15
addC var byte '0-7
addD var byte '8-15
chkcrc var byte
crcA var byte
crcB var byte
chksum2 var byte bank0 system
chksum3 var byte
i var byte
mydata var byte
mydata1 VAR byte
mydata2 var byte
mydata3 var byte
mydata4 var byte
rf var porta.4
'Variables for saving state in interrupt handler
wsave VAR BYTE $70 system ' Saves W
ssave VAR BYTE bank0 system ' Saves STATUS
psave VAR BYTE bank0 system ' Saves PCLATH
fsave VAR BYTE bank0 system ' Saves FSR
' Setup Timer1 for resets after ~65.5mS
T1CON = %00000000 ' Internal clock, 1:1 prescale, Timer1 off for now
TMR1L = 0
TMR1H = 0 ' Timer1 low & high bytes cleared
TMR1IF = 0 ' Clear Timer1 overflow flag before enabling interrupt
TMR1IE = 1 ' Enable Timer1 overflow interrupt
INTCON = %11000000 ' Global & peripheral ints enabled
chksum2 = 0 ' Clear match count
GOTO cycle ' Jump over int handler
ASM
RESET_VT
movwf wsave ; Save W
swapf STATUS, W ; Swap STATUS to W (swap avoids changing STATUS)
clrf STATUS ; Clear STATUS
movwf ssave ; Save swapped STATUS
movf PCLATH, W ; Move PCLATH to W
movwf psave ; Save PCLATH
movf FSR, W ; Move FSR to W
movwf fsave ; Save FSR
; Do interrupt stuff here
bcf T1CON,TMR1ON ; Stop Timer1
clrf TMR1L ; Clear low byte
clrf TMR1H ; Clear high byte
bcf PIR1,TMR1IF ; Clear Timer1 interrupt flag bit
;clrf GPIO ; Clear outputs on button release (or timeout)
;clrf PORTA ; Clear outputs on button release (or timeout)
From what I understand from the datasheet I can clear selected outputs by:
bcf PORTA, 2
bcf PORTA, 3
bcf PORTB, 0
bcf PORTB, 1
bcf PORTB, 2
bcf PORTB, 3
bcf PORTB, 4
bcf PORTB, 5
bcf PORTB, 6
bcf PORTB, 7
;I REALLY NEED TO CLEAR PORTA WITH THE EXCEPTION OF PORTA.O (SERIN PORT)
clrf PORTB ; Clear outputs on button release (or timeout)
clrf chksum2 ; Clear match variable
; Restore FSR, PCLATH, STATUS and W registers
movf fsave, W ; retrieve FSR value
movwf FSR ; Restore it to FSR
movf psave, W ; Retrieve PCLATH value
movwf PCLATH ; Restore it to PCLATH
swapf ssave, W ; Get swapped STATUS value (swap to avoid changing STATUS)
movwf STATUS ; Restore it to STATUS
swapf wsave, F ; Swap the stored W value
swapf wsave, W ; Restore it to W (swap to avoid changing STATUS)
bsf T1CON,TMR1ON ; Re-enable Timer1 before exiting interrupt handler
retfie ; Return from the interrupt
ENDASM
PAUSE 1000 'SETTLE INPUTS
start:
high rf
'ZERO VARIABLES
ADD1=0
adda = 0
addb = 0
addc = 0
addd = 0
address1 = 0
address2 = 0
address3 = 0
address4 = 0
mydata=0
chkcrc = 0
i = 0
mydata = 0
mydata1 = 0
mydata2 = 0
mydata3 = 0
mydata4 = 0
porta.1 = 0
porta.2 = 0
porta.3 = 0
portb = 0
pause 50
cycle:
high rf
repeat
ADD1=0
adda = 0
addb = 0
addc = 0
addd = 0
address1 = 0
address2 = 0
address3 = 0
address4 = 0
chkcrc = 0
i = 0
mydata = 0
mydata1 = 0
mydata2 = 0
mydata3 = 0
mydata4 = 0
'************************************************* *****************************
' Fire up Timer1 before entry to serial input routine
T1CON.0 = 1
' at 4MHz Timer1 overflows in 65536 * 1uS (~65.5mS) if no Synch byte
' and serial data arrive on time. SERIN2 timeout & label options
' are useless with a noisy RF receiver output - as noise continually
' resets the timeout period causing it to hang forever.
' Wait for Synch byte, then get new inbound data & checksum
SERIN2 serpin,16468,[wait(254),address1,address2,address3,address4,_
mydata1,mydata2,crca,crcb]
T1CON.0 = 0 ' Stop Timer1 once we've received data
TMR1L = 0 ' Clear low byte
TMR1H = 0 ' Clear high byte
' / **** Begin data validation **** /
As I mentioned earlier after making changes the output will quickly come on and go off.
Thanks




Bookmarks