View previous topic :: View next topic |
Author |
Message |
jahan
Joined: 04 Apr 2005 Posts: 63
|
RS232 Question |
Posted: Sun May 15, 2005 7:13 pm |
|
|
if a system is sending out the following values:
int go = 254 //start trasmit signal
int RN = 1 // as the relay number from 1 to 12
int SN = 1 // as the status of relay 0 or 1
putc(go);
putc(RN);
putc(SN);
the baud rate on the transmit side is as follow:
#use rs232(baud=2400,parity=N,bits=8,xmit=PIN_A4,INVERT)
The transmitter is fine and working OK.
Now I want to read these values on another controller using CCS.
Can somebody help figure out how to read these values on the receiving side?
the receiving side wait for 254 and then reads the next 2 values as Relay Number and Relay status. |
|
![](templates/subSilver/images/spacer.gif) |
PhilWinder
Joined: 16 Apr 2005 Posts: 23
|
|
Posted: Sun May 15, 2005 9:50 pm |
|
|
Try doing some examples first, since they are not too hard to get working (assuming your harware is correct). Take a look at getc() in the manual. Once you have, then apply them to this task. If you figure something out, you will have a much greater understanding and a great sense of achievment.
phil |
|
![](templates/subSilver/images/spacer.gif) |
jahan
Joined: 04 Apr 2005 Posts: 63
|
Let's try again. |
Posted: Sun May 15, 2005 10:51 pm |
|
|
Thank you for your reply.
I've tried many hours to figure this out.
here is what I've done so far:
Code: |
#include <16F84A.h>
#fuses XT,NOPROTECT,NOWDT,NOPUT
#use delay(clock=4000000)
#use rs232(baud=2400,parity=N,bits=8,xmit=PIN_A4,INVERT)
void main (void) {
set_tris_b(0b00000000);
set_tris_a(0b00010000);
while (true) {
k = getc();
m = getc();
n = getc();
if (k == 254) {
if (m == 1) {
if (n == 2) {
output_high(PIN_B0);
}
}
}
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon May 16, 2005 5:05 am |
|
|
You don't say what chip you are using?. Are you dead sure the transmit is 'OK'. The reason I ask, is that pin A4, on a lot of the newer chips, is an 'open collector' drive, only able to pull the signal low, and requiring a pull-up resistor to work as a drive to another logic input....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
Re: Let's try again. |
Posted: Mon May 16, 2005 8:01 am |
|
|
Pin B0 is not going to do much if it is not an output. If you are using standard IO you don't need the tris statements. For a test try this:
Code: |
#include <16F84A.h>
#fuses XT,NOPROTECT,NOWDT,NOPUT
#use delay(clock=4000000)
#use rs232(baud=2400,parity=N,bits=8,xmit=PIN_A4,INVERT)
void main (void) {
set_tris_b(0b00000011);
set_tris_a(0b00010000);
while (getc() != 254); //wait for 254
output_high(PIN_B1);
if (getc() == 1) { // test that the next character is 1
if (getc() == 2) {
output_high(PIN_B0);
}
}
output_low(PIN_B1);
}
|
_________________ The search for better is endless. Instead simply find very good and get the job done. |
|
![](templates/subSilver/images/spacer.gif) |
|