Thanks for all the help but I was looking at Bruce's remote example,
http://www.picbasic.co.uk/forum/showthread.php?t=12554
I thought I could also use the timer portion that could be helpful to jump out of the SERIN2 if no data is received, But ASM??? This is why I bought PicBasic Pro...
From what I understand, very little, I need to add this to my code:
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
SYMBOL TMR1IF = PIR1.0 ' Timer1 overflow interrupt flag (reset in int handler)
SYMBOL TMR1IE = PIE1.0 ' Timer1 interrupt enable bit
' 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 initialize ' Jump over int handler
ASM
RESET_VT
; 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
DON'T KNOW ABOUT THE NEXT TWO LINES, SO I COMMENTED THOSE OUT. I BEEN READY THE DATASHEET FOR THE 16F628A, AND AT BEST GUESS TO CLEAR A SINGLE BIT ON PORTA, WHAT I SEEN IN THE DATASHEET REFERENCING WOULD BE PORTA, 1 OR PORT??1. DOESN'T COMPILE, HOW COULD I CLEAR PARTICULAR BITS HERE FOR PORTA AND PORTB?
;clrf portb ; Clear outputs on button release (or timeout)
;clrf porta ; Clear outputs on button release (or timeout)
bsf T1CON,TMR1ON ; Re-enable Timer1 before exiting interrupt handler
retfie ; Return from the interrupt
ENDASM
And then here is my serial in:
' 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,mydata3,mydata4,mydata5,mydata6]
T1CON.0 = 0 ' Stop Timer1 once we've received data
TMR1L = 0 ' Clear low byte
TMR1H = 0 ' Clear high byte
I compiled this with the rest of my code and it seems to be working fine, but am waiting for the gremlins to pop out.
Thanks a million for all the recommendations already.
I've been following this to see where it ended up... If you don't mind me asking; what kind of data are you transmitting? What speed?
I'm using the same modules for RF control of hardware.
Thanks for all the Help everyone,
Mtripoli, I am just sending the value of the button being pressed and have the modules set up for 9600. I don't know for sure if they're running at that speed but it is working great.
What has me fascinated, is the piece of code, I mentioned in my last response, the timeout for the receiver. I am not familiar with asm and have done some research on the datasheet for the 16f628a where it goes in to the instruction set. Instead of "clrf PORTA", I would just like to clear certain bits on PORTA and PORTB instead of clearing them all. At this moment I have not found anything on that but am about to use google to try to find that answer. Right now I am using the timeout feature of serin2, but I have taken a recommendation from a previous post on using:
while flag < 1 '1*100ms =.001
serin2, and so forth
flag = flag + 1
wend
I don't see any problems yet using this, but I guess time will tell. Would like to understand how the timer portion actually works in PICBASIC PRO but it must be one of those ASM things.
Thanks again
The Timer1 interrupt is just to exit the SERIN2 line and clear the decoder output pins if
no data has been received before Timer1 times-out.
Without the interrupt, it would just sit & spin on the SERIN2 line due to noise on the RF
receivers data output pin.
If data IS received, it drops to the next line after the SERIN2 and disables the timer until
it's needed again.
If you need to put certain values on PORTB or PORTA just use something like;
movlw b'11000010' ; <-- value to place on port
movwf PORTB ; <-- put it on the port
Not much tougher than PORTB = %11000010 in PBP...;o)
Thanks Bruce,
What I have is two outputs on PORTA, and eight outputs on PORTB, so if no data is received, or shall I say no valid data is received, then all of my outputs would then clear.
Again, Thank you all for your help and support, especially for the education that I have received from you all.
Bookmarks