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

uart pic18F pic16F
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mariemee12



Joined: 16 Apr 2014
Posts: 7

View user's profile Send private message

uart pic18F pic16F
PostPosted: Wed Apr 16, 2014 8:33 am     Reply with quote

hi
please i need help ....
Sad
well i am using pic c compiler for the first time ...
i made a usb communication between pc and pic18F4550 but .. i can't made the uart communication between pic 16F877 and the pic18F .. do you have some examples even a simples ones .. like reading 8 inputs from 16F and and display their statements in the hyperterminal ..

waiting any help thnx Smile))))
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Apr 16, 2014 9:57 am     Reply with quote

Hi,

Your request is a bit confusing? You mention 'uart communication between pic 16F877 and the pic18F', but later also mention 'display their statements in the hyperterminal', which is a bit contradictory......

What do you want to do, (1) send data back and forth between the 16F and the 18F using the UART's, or (2) send data back and forth between the 16F (or the 18F) and the PC using the UART? Big difference, hardware-wise, in your request.

On a hunch, what version of Proteus are you using?

John
mariemee12



Joined: 16 Apr 2014
Posts: 7

View user's profile Send private message

PostPosted: Wed Apr 16, 2014 11:07 am     Reply with quote

well .. firstly thank you so much for your interest .

Secondly , i gonna explain to you my project in general ..
i must create a communication between pc and machines by using 2 cards :
master card (18F) communicate with{ pc(by usb) , and slave card (16F) by uart } and i gonna create a gui in vb.net .

So at this stage am using hyperterminal to display the result and until now I failed to make the communication uart between the 2 pic Sad Sad

mariem
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Apr 16, 2014 11:34 am     Reply with quote

you need to show your code as a starting point.
mariemee12



Joined: 16 Apr 2014
Posts: 7

View user's profile Send private message

PostPosted: Wed Apr 16, 2014 11:52 am     Reply with quote

Here are the two codes. But excuse me if there are many mistakes because like i told you it's my first code with pic c compiler.
Code:
#include <16F877.h>
#FUSES HS,NOWDT,NOLVP
// Fuses ??
// HS High Speed donc quartz > 4 Mhz ds notre cas 20 M
// MCLR on va utiliser la pin 1 comme entrée de reset
// NOWDT watch Dog Timer Désactivé
// NOLVP No Low voltage programming ( ce pic se programme a 13.1v)


#use delay(clock=20M) // frequence 20 Mhz


#include <math.h>
#use rs232(uart1,baud=9600, bits=8, parity=N,xmit=pin_c6,rcv=pin_c7)
#include <string.h>
int8 data;

void main()
{
   delay_ms(100);
   while(true)
   {
    input_d();
    data = get_tris_D();
     puts ( data );
}}



*****
Code:

#include <18F4550.h>
#FUSES HS,MCLR,NOWDT,NOLVP
// Fuses ??
// HS High Speed donc quartz > 4 Mhz ds notre cas 20 M
// MCLR on va utiliser la pin 1 comme entrée de reset
// NOWDT watch Dog Timer Désactivé
// NOLVP No Low voltage programming ( ce pic se programme a 13.1v)

#use delay(clock=20M) // frequence 20 Mhz
#include <math.h>
#include <usb_cdc.h> // framework USB Microchip
#use rs232(uart1,baud=9600, bits=8, parity=N,xmit=pin_c6,rcv=pin_c7)

int8 data;
void main(void){
 while(true)
 {
  while(true)
    {
    if (kbhit()) //wait until a character has been received
   data = getc();
 
     printf (data);
             
    }   
     }}
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Apr 16, 2014 4:20 pm     Reply with quote

Hi,

I realize that English is probably not your native language, but the 'clarification' of your earlier post raises more questions than it answers! So, let me ask you several direct questions:

1. You want your 18F device to communicate with the PC via USB, right?
2. You want your 16F device to communicate with the PC via serial communications using the UART, right?
3. There is no 18F to 16F communications directly, or vice versa, correct? It's all PIC <> PC, but never PIC <> PIC, is that right??

John
mariemee12



Joined: 16 Apr 2014
Posts: 7

View user's profile Send private message

PostPosted: Thu Apr 17, 2014 1:26 am     Reply with quote

yes .. sorry coz my french is better than my english Sad

1. yes i want my 18F device to communicate with the PC via USB (done) Wink
2. and i want my 18F device (master) to communicate with the 16F device (slave) via UART .

16F device cant comunicate with pc directly ..

i wish that it is clear now ..
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Apr 17, 2014 8:29 am     Reply with quote

Hi,

Frankly, it's not much more clear Sad !

So, this is what you want to do? I'll try a graphic:

PC <USB> 18F <Serial> 16F <Serial> PC

So, reading the graphic from left to right:

The PC communicates with the 18F via USB
The 18F communicates directly (PIC to PIC) with the 16F via serial
The 16F communicates with the PC via serial

Is that correct? If so, why in the world are you doing this? Please tell us in detail your 'concept'.....

John
temtronic



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

View user's profile Send private message

PostPosted: Thu Apr 17, 2014 8:57 am     Reply with quote

John

I've read and re-read this and here's what I get.

The 18F PIC is the 'master' and talks to the 16F PIC to get 'data'. It then transfers that 'data' to a PC via the USB peripheral.

so...

PC<---USB---> PIC18F <---RS-232---> PIC16F

I'm only using 'RS-232' as one method of interPIC communications, though it would be the easiest to code/test/confirm...


Jay
mariemee12



Joined: 16 Apr 2014
Posts: 7

View user's profile Send private message

PostPosted: Thu Apr 17, 2014 12:21 pm     Reply with quote

exactly like Jay say
PC<---USB---> PIC18F <---RS-232--RS485---> PIC16F <--->industrial machine
my problem now is how to create a communication between PIC16F and PiC18F ..
please help :( :(
jeremiah



Joined: 20 Jul 2010
Posts: 1345

View user's profile Send private message

PostPosted: Thu Apr 17, 2014 12:42 pm     Reply with quote

For serial input:
Look at the file ex_sisr.c in your examples folder in the PICC install directory. This provides interrupt driven serial data that you can process at your leisure.

For serial output:
You can simply send the serial data using putc, printf, etc. The manual has descriptions and examples on how to use these.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Apr 17, 2014 2:04 pm     Reply with quote

Hi,

Physically, how far apart will the 18F and the 16F be located?

John
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 1:31 am     Reply with quote

Yes.

Ezflyr's question is critical.

First, understand what RS232 is (and isn't....). The PIC does not use RS232!....

The PIC chips talk async serial TTL. Attach a MAX232, and this becomes 'RS232' signalling, but it is not what the chips themselves talk...
RS232 is a voltage signalling standard over which you can _send_ async serial data. You can equally well (better in many cases), use other standards like RS485 etc..
Now if the two chips are inches or feet apart, you don't want/need to get involved in 'RS232' at all. Just directly connect the async TTL signal.
If distances are longer, then RS485 is superior, but requires more wires, or only half duplex (one way at a time) communication.

You need to start as a 'multi step' process.

First decide how far you need to send, and at what speed?.
Half duplex, full duplex?.
Then from this decide what signalling standard needs to be used.
Then with that decided, start by getting the PIC's themselves talking 'on the bench' without any signalling hardware between (just connect the async serial directly).
Only once you have this working, move on to adding the signalling hardware, and stretching the distance involved.

Single steps at each point.

Best Wishes
mariemee12



Joined: 16 Apr 2014
Posts: 7

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 2:24 am     Reply with quote

thank you all for your interesting..

well i want to send for about 1300 m.
baud=9600
Half duplex.
now i start by getting the PIC's themselves talking 'on the bench' without any signalling hardware between. my problem is here because like i told you it's my first program with picC compiler.

thank you jeremiah i gonna take a look at the file ex_sisr.c Smile)
temtronic



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

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 5:55 am     Reply with quote

I seriously doubt you can go 9600 baud for 1.3 kilometers, though I haven't checked the data sheet for newer RS-485 devices.
The actual wire you use has a BIG impact upon the speed vs distance, so you MUST read the datasheets, follow mfr. guidelines about material/devices.
That being said, since the PIC 18F is the 'master', it's easy to use RS-485 for your project. Examples are in the examples folder that CCS supplies. I suggest getting the code to work 'on the bench' with say, 3-6 meters of wiring.
Once you've confirmed it does, then add wire as required. Typically a spool of 4C telco is 305 meters.4 spools = 1300M.
There are other ways of building 'long distance - hard wired' serial links, the one I did 20 years ago (still in operation), was about 15 miles on good old solid copper wires. Speed was only 24 Baud. Yes, that's 24 bits per second. There is a tradeoff of speed vs distance, something you must figure out.

hth
jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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