you're close... some things need to be modify IMO before...
Code:
'TRANSMITTER PIC 16F84A
'HARDWARE SETUP
DEFINE OSC 4
INCLUDE "MODEDEFS.BAS" 'Serial communication mode definition file
PORTA = 0 'PORTA (133) outputs LOW
TRISA = %00000 'Set PORTA to all outputs
PORTB = 0 'PORTB (134) outputs LOW
TRISB = %00000000 'Set PORTB to all outputs
CLEAR 'Clear buffers and registers
Must be set TRIS before sending 0 to PORT so.
Code:
'TRANSMITTER PIC 16F84A
'HARDWARE SETUP
DEFINE OSC 4
INCLUDE "MODEDEFS.BAS" 'Serial communication mode definition file
TRISA = 0 'Set PORTA to all outputs
TRISB = 0 'Set PORTB to all outputs
PORTB = 0 'PORTB (134) outputs LOW
PORTA = 0 'PORTA (133) outputs LOW
'
'remove CLEAR ... you don't need it
'
I know i don't have to consider your SERIN/SEROUT but...
Code:
'MAIN PROGRAM
LOOP1:
PAUSE 1000 'Pause for 1 second
SEROUT PORTB.0,T1200,[#B0] 'Output decimal equivalent
GOTO LOOP1 'Return to main program start
END
By using # you'll send not decimal value... ASCII representation of the decimal value. In your case you'll send ASCII "2" + ASCII "2" + ASCII "6" wich is not what you want.
Simply remove #.
Code:
PORTA = 0 'PORTA (133) outputs LOW
TRISA = %00000 'Set PORTA to all outputs
PORTB = 0 'PORTB (134) outputs LOW
TRISB = %00000001 'Set PORTB to all outputs but RB0
CLEAR 'Clear buffers and registers
' ...........
'MAIN PROGRAM
LOOP1:
SERIN PORTB.0,T1200,20,LED1,B0
IF B0 = B1 THEN LED2
GOTO LOOP1 'Return to main program start
END
- 1. Change TRIS and PORT like i did before
2. Begin with SERIN PORTB.0,T1200,[B0] and after use SELECT CASE to test B0. If it's work, begin with timeout stuff.
In your case The timeout subroutine is killer, your pauses take too much time. Timeout 20ms... Timeout 1 sec... Synchronisation probleme. If you still want to use a timeout, at least use a bigger timeout period or use flow control pin.
Bookmarks