View previous topic :: View next topic |
Author |
Message |
siawjf
Joined: 23 Sep 2010 Posts: 4
|
Uart Comm. |
Posted: Mon Oct 25, 2010 9:30 pm |
|
|
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: 9246 Location: Greensville,Ontario
|
|
Posted: Tue Oct 26, 2010 5:32 am |
|
|
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
|
|
Posted: Tue Oct 26, 2010 6:25 am |
|
|
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
|
|
Posted: Tue Oct 26, 2010 10:41 am |
|
|
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: 1615 Location: Central Illinois, USA
|
|
Posted: Tue Oct 26, 2010 11:06 am |
|
|
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
|
|
Posted: Tue Oct 26, 2010 12:24 pm |
|
|
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: 1615 Location: Central Illinois, USA
|
|
Posted: Tue Oct 26, 2010 4:00 pm |
|
|
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
|
|
Posted: Sun Oct 31, 2010 10:00 am |
|
|
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
|
|
Posted: Sun Oct 31, 2010 1:31 pm |
|
|
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
|
|
Posted: Thu Nov 04, 2010 6:25 pm |
|
|
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? |
|
|
|