I'm having major problems trying to get the TX program to do what I want it to, namely TX after a timing loop executes. Just for information, if I comment out the timing loop the program TX's no problem and sends and receives a test WORD.
Here's the setup:
Code:INTCON = %00001000 ' Enable port change wakeup from sleepIt's GPIO.4 we're looking at here. That's the pin that will receive the input from a 555 timer / potential divider using an ldr to detect that it's dark and therefore TX the days count over.Code:WPU = %00010000 ' pull-up on for GPIO.4 (external pull-up already on GPIO.3)
Here's the main body of the program. it's a little bit of a mess because I've commented out the GPIO.3 COUNTS part of the program and also added then commented out INTCON.0 = 0 in various places to try and get it to do the timer loop / COUNT then TX.Code:OPTION_REG = %00001111 'Watch_Dog_Timer ON with a 128 prescaler
I think the problem maybe that the COUNTER loop never gets completed because the IOC which comes from GPIO.4 isn't reset and the counter loop is using @SLEEP but never gets that far.Code:IF GPIO.3= 1 AND GPIO.4= 1 THEN ' Nothing has happened so SLEEP E_OUT=0 ' Disable transmitter INTCON.0 = 0 ' No Inputs detected or it's still light so clear int on change flag @ SLEEP ' and start snoozin..zzzzzzzzzzz indefinatly @ NOP ' Do nothing for 1st instruction on wake-up ELSE 'IF GPIO.3=0 THEN GOSUB COUNTS 'Bird detected at box - GOTO LABEL COUNTS IF GPIO.4=0 THEN DARK 'It's got dark? or just cloudy - GOTO LABEL DARK ENDIF GOTO MAIN 'Back to sleep / continue counting 'COUNTS: ' VISITS = VISITS +1 'Bird at box so increment counter ' INTCON.0 = 0 ' Clear int on change flag 'RETURN ' Then back to sleep.... DARK: 'INTCON.0 = 0 ' Clear int on change flag ' It could be night time...It might only be a cloud though... ' so back to sleep / wake / sleep for half an hour..zwzwzw COUNTER=0 ' clear before entry WHILE COUNTER < 2 ' 4.608sec Loop time (Loop for 30 mins = 781) @ SLEEP COUNTER=COUNTER+1 'IF GPIO.3= 0 THEN COUNTS 'Bird at box (it's not dark) so continue counting WEND if GPIO.4= 0 then ENCODE ' It really ia dark so carry on and transmit VISITS 'IF GPIO.4= 1 THEN Main '(changed from return) It's not dark after all so carry_on_sleeping_counting Encode: E_OUT=1 ' Turn transmitter on pauseus 25 ' Let transmitter settle DAT_OUT = %10101001 'INTCON.0 = 0 ' Clear int on change flag 'Build checksum of 2 data bytes CHK_SUM = (DAT_OUT * 2) Transmit: 'LET VISITS = VISITS / 2 'Just VISITS too not from the box LET VISITS = 300 'Test data number SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM,VISITS.highbyte,VISITS.lowbyte] PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc. INTCON.0 = 0 ' Clear int on change flag - moved here from above GOTO Main END
Any ideas greatfully received.
Dave


						
					
				
				
				
				
			

Bookmarks