I,,
I was looking at your receiving code, and I could not see any serial in command. What are you using instead ?
ken
I,,
I was looking at your receiving code, and I could not see any serial in command. What are you using instead ?
ken
Anyway here is the code I am using at the receiver:
I will be putting a lcd on the circuit to see how the pic is reading the input.
Beside the test led input at the begining the rest is not functioning, I suppose it has to do with the data coming is in one format and I am treating it in another.
DEFINE OSC 20 '20Mhz Oscillator was used
Include "modedefs.bas" ' Include serial modes
ADCON0 = 0 'AD MODULE OFF & CONSUMES NO CURRENT
ADCON1=7
CMCON = 7 'COMPARATORS OFF
TRISA = 0 'outpu
TRISB = 1 'input
B0 var byte
porta.0 =1 'testing leds output
pause 500
porta.1 =1
pause 500
porta.2 =1
pause 500
porta.3 =1
pause 500
start:
serin PORTB.3,n2400,[B0]
pause 1
if B0 = $aa then led1
if B0 = $aa then led2
if B0 = $5a then led3
if B0 = $5a then led4
goto loop
led1:
porta.0 =1
pause 200
goto start
led2:
porta.1 =1
pause 200
goto start
led3:
porta.2 =1
pause 200
goto start
led4:
porta.3 =1
pause 200
goto start
loop:
porta.0 =1
pause 200
goto start
end
A couple of notes:
TRISA = 0 'outpu <------ might only set porta.0 as an output(?)
use TRISA = %00000000 to make sure
TRISB = 1 'input <------ will only set portb.0 as an input
use TRISB = %11111111 to make sure all
of port B is set to input
start:
serin PORTB.3,n2400,[B0]
pause 1 <------ don't pause here, you want to read the serial
and get done what you want done and get
back to reading the serial port as quick as
possible
if B0 = $aa then led1
if B0 = $aa then led2
if B0 = $5a then led3
if B0 = $5a then led4
goto loop
led1:
porta.0 =1
pause 200 <----------- take out all these pause 200 lines
goto start
led2:
porta.1 =1
goto start
led3:
porta.2 =1
goto start
led4:
porta.3 =1
goto start
loop:
porta.0 =1
goto start
end[/QUOTE]
And you last post, 'where is the serin command?'. I'm using the hardware serial port driven by the 'on interrupt' command. Read the PBP manual a bit on it, then read the datasheets on the serial port and interrupts.
Give me a few minutes. I'll rework your code into something useful.
JDG
Last edited by skimask; - 2nd December 2006 at 17:53.
wow, ok some improvements to be done.
I will try this tonight when I get home, I might leave early...
ken
Ok, this should work. Ingest the code, understand the manchester encoding method.
And your other program only turned LEDs on, it never turned them off. And it never cleared B0.
'RECEIVER CODE
DEFINE OSC 20 '20Mhz Oscillator was used
Include "modedefs.bas" ' Include serial modes
ADCON0 = 0 : ADCON1 = 7 'AD MODULE OFF & CONSUMES NO CURRENT
CMCON = 7 'COMPARATORS OFF
TRISA = $00 : TRISB = $FF 'all porta is outputs, all portb is inputs
B0 var byte
'testing led outputs
porta.0 = 1 : pause 200 : porta.0 = 0
porta.1 = 1 : pause 200 : porta.1 = 0
porta.2 = 1 : pause 200 : porta.2 = 0
porta.3 = 1 : pause 200 : porta.3 = 0
start:
B0 = 0 'empty B0 because the program doesn't
serin PORTB.3,n2400,[B0] 'if n2400 doesn't work, try t2400
if B0 = $aa then training 'manchester encoded $f
if B0 = $55 then training 'manchester encoded $0
if B0 = $56 then led1toggle 'manchester encoded $1
if B0 = $59 then led2toggle 'manchester encoded $2
if B0 = $5A then led3toggle 'manchester encoded $3
if B0 = $65 then led4toggle 'manchester encoded $4
if B0 = $66 then ledson 'manchester encoded $5
if B0 = $69 then ledsoff 'manchester encoded $6
if B0 = $6A then ledswing 'manchester encoded $7
'still have $8-$e free to use
goto start
led1toggle:
if porta.0 = 1 then
porta.0 = 0
else
porta.0 = 1
endif
goto start
led2toggle:
if porta.1 = 1 then
porta.1 = 0
else
porta.1 = 1
endif
goto start
led3toggle:
if porta.2 = 1 then
porta.2 = 0
else
porta.2 = 1
endif
goto start
led4toggle:
if porta.3 = 1 then
porta.3 = 0
else
porta.3 = 1
endif
goto start
ledson:
porta.0 = 1 : porta.1 = 1 : porta.2 = 1 : porta.3 = 1
goto start
ledsoff:
porta.0 = 0 : porta.1 = 0 : porta.2 = 0 : porta.3 = 0
goto start
ledswing:
porta.0 = 1 : pause 10 : porta.0 = 0
porta.1 = 1 : pause 10 : porta.1 = 0
porta.2 = 1 : pause 10 : porta.2 = 0
porta.3 = 1 : pause 10 : porta.3 = 0
goto start
end
Redo your transmitter code to match the receiver code. Put a few buttons on it to transmit the codes above needed to turn your leds on and off, etc.
Do you have a couple of buttons on the transmitter or is it just a free running PIC without any outside input?
JDG
I just have a pot command as input, from memory
port portb.1,50,bo
if bo >0 and bo <150 then output1
if bo > 150 and bo <255 the output 2
output1
serout ......
something like that , just two different outputs for now,
I will use the a/d converter when I get the first working.
k
'posted to the wrong thread!!!!
didn't realize this thread has gone to 2 pages!
Last edited by skimask; - 2nd December 2006 at 18:40.
'after you've got everything else set up
led1toggle = $56 : led2toggle = $59 : led3toggle = $5a : led4toggle = $65
ledson = $66 : ledsoff = $69
ledswing = $6a
START:
gosub trainreceiver : serout portb.2, n2400, [ ledsoff ] : pause 1000
gosub trainreceiver : serout portb.2, n2400, [ ledson ] : pause 1000
goto start
trainreceiver:
serout portb.2, n2400, [ $aa, $aa, $aa, $aa, $aa ] : return
end
See that? Every time you send a command you have to train the receiver because there is more than about 5ms between commands. If you were to continuously send commands or data, you probably wouldn't need to train the receiver. But in any case, you MUST use manchester encoding! You'll get garbage at the output if you don't!
As this code is setup, all your LEDs should come on for a second, turn off for a second, come on for a second, etc.etc...
Let me know what happens...
JDG
Ok, I just saw the post about using the pot. So use the pot to turn the LEDs on and off. Then after that works, use the POT to turn the LEDs on in sequence to match the pot's rotation.
gosub trainreceiver : serout portb.2, n2400, [ ledsoff ]
if b0 < 64 then gosub trainreceiver : serout portb.2, n2400, [ led1toggle ]
if ( b0 > 63 ) and ( b0 < 128 ) then gosub trainreceiver : serout portb.2, n2400, [ led2toggle ]
if ( b0 > 127 ) and ( b0 < 192 ) then gosub trainreceiver : serout portb.2, n2400, [ led3toggle ]
if ( b0 > 191 ) then gosub trainreceiver : serout portb.2, n2400, [ led4toggle ]
Last edited by skimask; - 2nd December 2006 at 18:44.
I had time to analyze the code:
A few questions came up:
For the ledtoggle, why would you want to bit the pin high to low and then put it high, why not put it high right away. The way you have it, if its high, you put it to low, then to high, there must be a reason why and its flying 100 feet over my head.
Also, the led will stay on until you call the ledsoff right?
as far as the manchester coding goes, I understand, but there is decoder done here, you are simply pointing the coded values to their function. right?
k
Originally Posted by lerameur
LedToggle --- It's not the way describe it.
Read the IF...ELSE....ENDIF statement... work it through in your head.
If it's on, turn it off, otherwise turn it on (implying that it was off in the first place).
Encoder/Decoder - yes, I am assuming you don't have either the encoder or the decoder in the circuit. As far as I'm concerned, you don't need it. Yes, it's a handy piece of hardware to have around. The sooner you figure out how to do things without it, the better.
JDG
HI
I was not refering to the hardware encoder and decoder.
The program I have below works, but always gives me zero on the lcd.
k
By the way , the command gosub trainreceiver :... gives an eror while compiling , wrong Label..
X VAR BYTE 'VARIABLE TO incoming VALUE
pause 100
mainloop:
X =0
serin PORTB.3,n2400,[X]
Lcdout $fe, 1, "Value in: ", dec X
pause 100
Goto mainloop
End
Last edited by lerameur; - 3rd December 2006 at 20:37.
that was wrong, it was supposed to be this:Originally Posted by skimask
if B0 = $aa then start 'manchester encoded $f
if B0 = $55 then start 'manchester encoded $0
$F and $0 are for 'training' the receiver and aren't to be used for sending data until the receiver is trained....
Also in your RX4.bas (maybe it was RX6.bas), you have
Serin PortB.3, 16780, [B0]
----shouldn't that be serin2?
JDG
O k starting from scratches..
I manages to do 2 different programs which dont work.
here: http://www3.sympatico.ca/lerameur/
do I need to configure SSPCON, or the RCSTA registers ?
Also in your RX4.bas (maybe it was RX6.bas), you have
Serin PortB.3, 16780, [B0]
----shouldn't that be serin2?
I tried both , so many combinations....
k
Last edited by lerameur; - 5th December 2006 at 02:51.
Originally Posted by lerameur
Did you get the LEDs to light up in sequence as described in the earlier post?
And if you didn't, then why are you worried about the SSPCON or RCSTA registers... and why are you worried about those 2 registers in the first place? You're using a software-based serial commands, not hardware.
Priorities, man, priorities....
And after further checking.....................
If you'd check your ttt program and read the PIC datasheet, you'll notice that RA.4 is an open-drain output...you'll never get a high logic level from it...
If you'd check your rrr program and read the PIC datasheet, you'll notice that the TRIS statements are wrong...
Don't assume something is broke when you just plain haven't looked hard enough... Come on,,, get on it... Get this thing working by tomorrow!!!or else!!!
Last edited by skimask; - 5th December 2006 at 03:05.
Bookmarks