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

out ascii on port b

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



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

out ascii on port b
PostPosted: Wed Jul 26, 2006 12:24 am     Reply with quote

hi all

i need to out charachters on portb and recieve them on other pic (both are 16f874) but its dosent work,,,here is the TX code

Code:

#include <16F877a>
#include "string.h"
#include "lcd_kbd1.c"
#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#byte tris_b =0x00

int f;
int value;
static char MX[6];


void main()
{
   strcpy(MX,"1");
   output_b(0x00);
   //value=0x25;
while(TRUE)

{




   delay_ms(2000);
   output_b (MX);


}//while(true)
}//main





and here is the RX code

Code:


#include <16F877a>
#include "string.h"
#include "lcd_kbd1.c"
#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#byte tris_b =0xff
static char RX[15];
int1 f;
int8 i,value;


void main()

{

   f=0;
   LCD_Init();



while(TRUE) {



//if(f==1) {
   value=input_b();

   LCD_PutCmd ( CLEAR_DISP );
   LCD_SetPosition ( LINE_16_1);
   printf(LCD_PutChar,"RX is");
   LCD_SetPosition ( LINE_16_2);
   printf(LCD_PutChar,"     %d",value);
   delay_ms(1000);

}//while



thanx alot
Ttelmah
Guest







PostPosted: Wed Jul 26, 2006 2:47 am     Reply with quote

There is nothing to synchronise the transactions. You cannot be sure when the PICs actually start, and if one leads the other by a small amount of time, the data will always be corrupted. This is why 'asynchronous' communications (like RS232), have a 'start' bit, to mark where the transaction starts. Seperately, what you are actually 'sending', is the low byte of the address where the array is stored, not the array contents...
Do something like this:
Code:

//TX
//Need processor setup etc., here.

char MX[6];
//You do not need the static declaration for a 'global'.

void main(void)  {
   int8 ctr;
   strcpy(MX,"1234");
   while (TRUE) {
       //output a 'marker'
       output_b(0xAA);
       delay_ms(1);
       //Now switch to the 'start of transmission' marker
       output_b(0x55);
       for (ctr=0;ctr<6;ctr++) {
          //Now send the characters
          output_b (MX[ctr]);
          delay_ms(1);
       } //for
       output_b(0);
       //ensure we are not sending the 'marker' bytes
       delay_ms(1000);
    } //while
}//main

//RX
char RX[6]; //Only needs to be the same size as the TX buffer

void main(void) {
   int8 ctr;
   //On _both_chips, you should add any code to turn off things like
   //the adc here.
   LCD_Init();
   while(TRUE) {
      while (input_b() != 0x55);
      //wait for the first marker
      while (input_b() == 0x55);
      //Now the main code is moving to start sending the data
      delay_us(500);
      //delay long enough for the first byte to be present.
      for (ctr=0;ctr<6;ctr++) {
           //get the bytes at 1mSec pacing
           RX[ctr]=input_b();
           delay_ms(1);
      }//for
      //At this point the 'transaction' has been received
      LCD_PutCmd ( CLEAR_DISP );
      LCD_SetPosition ( LINE_16_1);
      printf(LCD_PutChar,"RX is");
      LCD_SetPosition ( LINE_16_2);
      printf(LCD_PutChar,"     %s",RX);
      //No delay here, need to get back, and start waiting for the next
      //message.
   }//while
}//main


The key is that the receiver waits till it sees the 'AA' character, and then waits for this to change. At this moment, the transmitter will start sending a few uSec latter (the time it takes to setup the counter, and access the array), and will send the characters at just over 1mSec intervals. The receiver waits 500uSec, so the first character should have arrived, and then reads six characters at the same basic pacing. Any slight errors in the timings of the two loops, willbe handled by the fact that we should be just about in the 'middle' of the character time.

Best Wishes
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Jul 26, 2006 10:01 am     Reply with quote

It appears that you might be trying to communicate similar to a parallel port. You would need to have a Strobe signal, from the TX PIC, to tell the RX PIC when to look at it's port. Probably hook it up to an interrupt pin would work.

Ronald
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