Rubicon
- 22nd January 2005, 20:48
Hello,
I'm a PBP novice using an old verion and have been having a hard time getting one way serial comminucation between two 16F84A pics to work. I find the manual confusing as to just what happens to numeric value when using SEROUT/SERIN
I've been trying to send a binary number from one PIC to the other where it's compared to the value in a vairable/constant. If there's a B1 then the program goes to a subroutine, if not then it continues on and repeats.
I've tried many different combinations of numeric value, baud rate etc, to no avail and I hope that someone here can post some SEROUT/SERIN sample code. If I can get some code that works then I can experiment to understand the way it works.
The code below is as I left it one frustrating night so please don't take the SEROUT/SERIN sections too seriously!
Any help here is appreciated.
Thankyou,
Rubicon.
'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
'VAIRABLES
B0 VAR BYTE 'Serout vairable
B0 = %11100010 'Vairable value
'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
****************************************
'RECEIVER 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 = %00000001 'Set PORTB to all outputs but RB0
CLEAR 'Clear buffers and registers
'VAIRABLES
B0 VAR BYTE 'SERIN input vairable
B1 VAR BYTE 'B1 vairable
B1 = 226 'B1 vairable value
'MAIN PROGRAM
LOOP1:
SERIN PORTB.0,T1200,20,LED1,B0
IF B0 = B1 THEN LED2
GOTO LOOP1 'Return to main program start
END
'SUBROUTINES
LED1:
PORTB.1 = 1 'Light LED1 on RB1
PAUSE 1000 'Pause for 1 second
PORTB.1 = 0 'Extinguish LED1 on RB1
GOTO LOOP1 'Return to main program start
LED2:
PORTB.2 = 1 'Light LED2 on RB2
PAUSE 1000 'Pause for 1 second
PORTB.2 = 0 'Extinguish LED2 on RB2
GOTO LOOP1 'Return to main program start
I'm a PBP novice using an old verion and have been having a hard time getting one way serial comminucation between two 16F84A pics to work. I find the manual confusing as to just what happens to numeric value when using SEROUT/SERIN
I've been trying to send a binary number from one PIC to the other where it's compared to the value in a vairable/constant. If there's a B1 then the program goes to a subroutine, if not then it continues on and repeats.
I've tried many different combinations of numeric value, baud rate etc, to no avail and I hope that someone here can post some SEROUT/SERIN sample code. If I can get some code that works then I can experiment to understand the way it works.
The code below is as I left it one frustrating night so please don't take the SEROUT/SERIN sections too seriously!
Any help here is appreciated.
Thankyou,
Rubicon.
'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
'VAIRABLES
B0 VAR BYTE 'Serout vairable
B0 = %11100010 'Vairable value
'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
****************************************
'RECEIVER 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 = %00000001 'Set PORTB to all outputs but RB0
CLEAR 'Clear buffers and registers
'VAIRABLES
B0 VAR BYTE 'SERIN input vairable
B1 VAR BYTE 'B1 vairable
B1 = 226 'B1 vairable value
'MAIN PROGRAM
LOOP1:
SERIN PORTB.0,T1200,20,LED1,B0
IF B0 = B1 THEN LED2
GOTO LOOP1 'Return to main program start
END
'SUBROUTINES
LED1:
PORTB.1 = 1 'Light LED1 on RB1
PAUSE 1000 'Pause for 1 second
PORTB.1 = 0 'Extinguish LED1 on RB1
GOTO LOOP1 'Return to main program start
LED2:
PORTB.2 = 1 'Light LED2 on RB2
PAUSE 1000 'Pause for 1 second
PORTB.2 = 0 'Extinguish LED2 on RB2
GOTO LOOP1 'Return to main program start