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 CCS Technical Support

how to combine this program ?

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



Joined: 18 Oct 2012
Posts: 10

View user's profile Send private message

how to combine this program ?
PostPosted: Fri Nov 09, 2012 5:32 am     Reply with quote

1. someone help me how to combine this two program to be a single program...
2. help me to join the program tx and rx in one program only
this is my tx program
Code:

#include <18F4550.h>                   // PIC18F4550 HEADER FILE

#fuses PUT, HS, NOWDT, NOLVP, NOBROWNOUT,     // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE PROGRAMMING

#use delay (clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N, errors )                  // 4 MHZ CRYSTAL


#define BUTTON1        PIN_B0               // PRESET BUTTON 1   
#define BUTTON2        PIN_B1               // PRESET BUTTON 2


#define LED1        PIN_B6               // LED 1
#define LED2        PIN_B7               // LED 2




void main ()
{
set_tris_b(0x01);                // SET ALL PORT 0-b3 AS INPUT b4-b7 OUTPUT
//set_tris_d(0x00);   
//set_tris_c(0x80);             // SET ALL PORT d AS OUTPUT PORT(0b 0000 0000)

output_b(0x00);


while(true)
{
   putc('g');
   delay_ms(500);
   putc('y');
   delay_ms(500);
}
}

and this my rx program
Code:

#include <18F4550.h>                   // PIC18F4550 HEADER FILE

#fuses PUT, HS, NOWDT, NOLVP, NOBROWNOUT,     // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE PROGRAMMING

#use delay (clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N, errors )                  // 4 MHZ CRYSTAL



#define LED1        PIN_B6               // LED 1
#define LED2        PIN_B7               // LED 2





void main ()
{
//set_tris_b(0x01);                // SET ALL PORT 0-b3 AS INPUT b4-b7 OUTPUT
//set_tris_d(0x00);   
//set_tris_c(0x80);             // SET ALL PORT d AS OUTPUT PORT(0b 0000 0000)

//output_b(0x00);
char data;


while(true)
{
data = getc();
switch(data)
{
case 'g':output_high(PIN_B6);
         output_low(PIN_B7);
break;
case 'y':output_low(PIN_B6);
         output_high(PIN_B7);
         
break;
default:output_low(PIN_B6);
        output_low(PIN_B7);

break;
}
}
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Nov 09, 2012 7:14 am     Reply with quote

Rather depends on what you're trying to achieve.

The CCS example EX_STR shows how to rx and tx in succession.

If you want to interleave tx & rx you could try EX_SISR which does RS232 interrupts

Mike

EDIT If you don't like the idea of using interrupts, you can loop round, polling for characters then keys.
juanodiy



Joined: 07 Sep 2012
Posts: 17

View user's profile Send private message

PostPosted: Mon Nov 12, 2012 2:07 am     Reply with quote

well, so many things you can do, if you are using rs232 i suppose you want to connect to a PC or something, so for join the programs one solution can be:

Code:


void main()
{
if(kbhit)
{
x=getc();
}
switch(x)
{
case 'g':output_high(PIN_B6);
         output_low(PIN_B7);
break;
case 'y':output_low(PIN_B6);
         output_high(PIN_B7);
         
break;
default:output_low(PIN_B6);
        output_low(PIN_B7);
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Nov 12, 2012 11:29 am     Reply with quote

Your tx code is a loop sending out a "g" then a "y" at 500ms intervals.

Your rx code is looking for "g" to turn ports one way, and a "y" to turn the other.

So with your combined code you could connect rx to tx.


Is this what you want?

1) With the rx-tx connection the ports will toggle at 500ms intervals.

2) Without the rx-tx connection the toggling will stop.


Mike
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