CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

RS232 Question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jahan



Joined: 04 Apr 2005
Posts: 63

View user's profile Send private message Send e-mail

RS232 Question
PostPosted: Sun May 15, 2005 7:13 pm     Reply with quote

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.
PhilWinder



Joined: 16 Apr 2005
Posts: 23

View user's profile Send private message

PostPosted: Sun May 15, 2005 9:50 pm     Reply with quote

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. Smile

phil
jahan



Joined: 04 Apr 2005
Posts: 63

View user's profile Send private message Send e-mail

Let's try again.
PostPosted: Sun May 15, 2005 10:51 pm     Reply with quote

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);
        }
       }
     }
   }
}

Ttelmah
Guest







PostPosted: Mon May 16, 2005 5:05 am     Reply with quote

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
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

Re: Let's try again.
PostPosted: Mon May 16, 2005 8:01 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group