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

Uart Comm.

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



Joined: 23 Sep 2010
Posts: 4

View user's profile Send private message

Uart Comm.
PostPosted: Mon Oct 25, 2010 9:30 pm     Reply with quote

Hi guys....I new in this....so wanna ask for help....I wanna use 2 PIC16F877A to communicate via UART Comm.....but i dunno what should include inside the code and have no idea to start it...help....
temtronic



Joined: 01 Jul 2010
Posts: 9202
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Oct 26, 2010 5:32 am     Reply with quote

do while ( not sure)

step 1 ..read the CCS C manual

step 2.. re read the manual, what you need is there in plain, old English.

step 3... cut code and try

loop
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Oct 26, 2010 6:25 am     Reply with quote

step 1a .. Look through the example code that comes with the compiler.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Oct 26, 2010 10:41 am     Reply with quote

step 1b... Start with an easy project, for example blinking a LED.

step 1c... Once you had aquire the skill in order to know how real things behave:
+ Hardware issues + Compiler issues + Your code issues,
try adding a pushbutton to your LED blinking project and learn how to read it with an MCU.

step 1d... Add an RS232 IC transceiver to your project, and with the help of a virtual terminal running in your
PC (Teraterm, Procomm, Putty,etc) try sending a string of char to a PC.

step 1e... Try to communicate 2 PIC16F877A via UART Comm.

After that, if you need some help, we gladly will help you.
And as said, a lot of members of this forum -me included- we feel comfortable reading plain Old English.

Regards
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Oct 26, 2010 11:06 am     Reply with quote

I read a Forbes article once that stated from many in business who say it takes 10,000hrs to become an expert at anything.

And having done so many things in my life, I'd have to say that's not too far off.

So, you have 9,999hrs and 45mins to go. ;)

Good luck!

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Oct 26, 2010 12:24 pm     Reply with quote

That is 5 years at 2000 hours/year. That Forbes article sounds about right.

If I have ANY doubts about my serial communications my FIRST debugging tool is my oscilloscope. I wouldn't consider programming a micro controller project without a scope or at least a logic analyzer. You can get a decent used one on Ebay for $100, or a new USB based one for a few hundred.
_________________
The search for better is endless. Instead simply find very good and get the job done.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Oct 26, 2010 4:00 pm     Reply with quote

SherpaDoug wrote:
That is 5 years at 2000 hours/year. That Forbes article sounds about right.


Yep!

Quote:

If I have ANY doubts about my serial communications my FIRST debugging tool is my oscilloscope. I wouldn't consider programming a micro controller project without a scope or at least a logic analyzer. You can get a decent used one on Ebay for $100, or a new USB based one for a few hundred.


I agree -- a scope is essential. In fact, when you buy, your best bet is to get something digital because of the intermittent duty cycle of what we're testing.. analog tends to be "now you see it, now you don't" (unless it's analog storage. I remember those!)

I don't know what your budget is or how long term you are looking to stay in microcontroller land, but consider at least 2 channels, 4 is better.

My favorites at the high end are Agilent (although the price is worth it, they are just that, pricey), at the low end, lots of old tek DSO's can be found that would service you nicely.

Actually, I have an HP 54601B that works great too. ebay will definitely be your friend.

I will say this though, there's definitely a tradeoff between price and functionality/reliability. Cheap stuff is --- cheap. Expensive stuff is expensive but is awesome.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
siawjf



Joined: 23 Sep 2010
Posts: 4

View user's profile Send private message

PostPosted: Sun Oct 31, 2010 10:00 am     Reply with quote

The master code
Code:

#include <16F877A.h>
#fuses  PUT, HS, NOWDT, NOLVP, NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N, errors)

void main()
{ set_tris_b(0b00111111);
   output_b(0b00000000);
while (true)
{
   if (input(pin_b0))
   {
      putc('a');
      delay_ms(1000);
   } 
   if (input(pin_b1))
   {
    putc('b');
      delay_ms(1000);
   } 
   if (input(pin_b2))   
   {
    putc('c');
      delay_ms(1000);
   }
}
}

Slave code
Code:

#include <16F877A.h>
#fuses  PUT, HS, NOWDT, NOLVP, NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N, errors)

char data;
void main()
{
   set_tris_b(0b00000000);
   output_b(0b00000000);
 
   while(true) 
          { if(kbhit())
             data = getc();
             
             switch(data)
             {
             case 'a':output_high(PIN_b7);
                       delay_ms(5000);
                      output_low(PIN_b7);
                     
             break;
             case 'b':output_high(PIN_b6);
                     delay_ms(5000);
                      output_low(PIN_b6);

             break;
             case 'c':output_high(PIN_b5);
                     delay_ms(5000);
                     output_low(PIN_b5);

             break;
              default:output_low(PIN_b7);
                      output_low(PIN_b6);
                      output_low(PIN_b5);
             break;

             }
           }
    }
 

This is how I write my code...but the problem is the LED will always light up alternately in the slave PIC, and I didn't push my push button in order to send the input to the master code.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Oct 31, 2010 1:31 pm     Reply with quote

Quote:

...but the problem is the LED will always light up alternately in the slave PIC, and I didn't push my push
button in order to send the input to the master code.

It is not the problem! that means that it is running!

The point is how is wired the pushbuttons in the PIC inputs.
The C code expects the push buttons were wired like this:

http://www.nastypixel.com/instantsoup/tools-ingredients-tecniques/tecniques/pull-up-resistor/

Step 1c . DONE !!!

Regards
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Thu Nov 04, 2010 6:25 pm     Reply with quote

Do you have resistors in series with the LED's?
If not, and the LED turned on it may be causing a reset.
Is MCLR pin tied high?

Do all of the LEDs flash on and off or just one?
Does it do it with the master disconnected?
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