|
|
View previous topic :: View next topic |
Author |
Message |
fazreen
Joined: 18 Oct 2012 Posts: 10
|
how to combine this program ? |
Posted: Fri Nov 09, 2012 5:32 am |
|
|
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
|
|
Posted: Fri Nov 09, 2012 7:14 am |
|
|
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
|
|
Posted: Mon Nov 12, 2012 2:07 am |
|
|
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
|
|
Posted: Mon Nov 12, 2012 11:29 am |
|
|
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 |
|
|
|
|
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
|