Serial comm using pic16f877a....

tshuck

Joined Oct 18, 2012
3,534
OK, i have edited the code..is this fine now???
I have installed PIC oshon simulator can't we test in it?

Rich (BB code):
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
#define NINE 0     /* Use 9bit communication? FALSE=8bit */

#define BAUD 9600  

    #define RX_PIN TRISB2
    #define TX_PIN TRISB5
#define DIVIDER ((int)(_XTAL_FREQ/(16UL * BAUD) -1))
#if NINE == 1
#define NINE_BITS 0x40
#else
#define NINE_BITS 0
#endif
#if HIGH_SPEED == 1
#define SPEED 0x4
#else
#define SPEED 0
#endif
    Initialize ();





/*    TRISC=0X00;
TX9=0;
TXEN=1;
SYNC=0;
BRGH=0;
SPEN=1
RX9=0;
CREN=0;
FERR=0;
OERR=0;
SPBRG=31;*/

void main ()
{
    Initialize ();    //initialize device
    while(1)
    {
        putch('H');   //print the letter 'H'
        putch('i');   //print 'i'
        putch('\r');  // return to beginning of line
        putch('\n');  //new line
    }
}    












/* Serial initialization */
Initialize (){
    RX_PIN = 1;    
    TX_PIN = 1;          
    SPBRG = DIVIDER;         
    RCSTA = (NINE_BITS|0x90);
    TXSTA = (SPEED|NINE_BITS|0x20);
}
Have you gotten your interface module yet? You can check it that way...
 

tshuck

Joined Oct 18, 2012
3,534
Hi,

I need USART for one uC to another uC also plaese tell what changes to be done ??
How many variables would you like to work with? Stick to getting one communicating to the computer, then you can rest assured you have one working interface before trying to add another device...
 

tshuck

Joined Oct 18, 2012
3,534
WHat are trying to say?
please tell fast i have to ordered it!
Stick to trying to get a single PIC communicating with a computer, then move on to getting two PICs talking to each other. That way when you do move to two PICs communicating, you can know that at least one PIC is operating properly, and know a problem, if one exists, lies with the other PIC.
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
Stick to trying to get a single PIC communicating with a computer, then move on to getting two PICs talking to each other. That way when you do move to two PICs communicating, you can know that at least one PIC is operating properly, and know a problem, if one exists, lies with the other PIC.
OK, then this code is fine and how to test in any simulator like oshon


Rich (BB code):
#include <htc.h>
 __CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS); 
#define _XTAL_FREQ 20000000 
#define NINE 0     /* Use 9bit communication? FALSE=8bit */ 
 #define BAUD 9600       
 #define RX_PIN TRISB2  
   #define TX_PIN TRISB5 
#define DIVIDER ((int)(_XTAL_FREQ/(16UL * BAUD) -1)) 
#if NINE == 1 
#define NINE_BITS 0x40 
#else #define NINE_BITS 0 
#endif #if HIGH_SPEED == 1 
#define SPEED 0x4 
#else #define SPEED 0 
#endif     Initialize ();      /*    
TRISC=0X00; 
TX9=0;
 TXEN=1; 
SYNC=0; 
BRGH=0; 
SPEN=1 RX9=0; 
CREN=0; 
FERR=0; 
OERR=0
SPBRG=31;*/  void main () { 
    Initialize ();    //initialize device 
    while(1)     {       
  putch('H');   //print the letter 'H'      
   putch('i');   //print 'i'      
   putch('\r');  // return to beginning of line   
      putch('\n');  //new line     } }
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
I have ordered it it will take 1/2 days .....

and now please tell how to connect two uC for serial data transfer wireless....?
will this will work or not??
1. low cost
2. expensive
3. or this
OK, i will work with it later at least can you suggest me which one will be fine ??
can i use that low cost Rx and Tx Rs 350/. pair ??
My Aim is to control Speed of PMDC motor wireless...!!
 

tshuck

Joined Oct 18, 2012
3,534
OK, i will work with it later at least can you suggest me which one will be fine ??
can i use that low cost Rx and Tx Rs 350/. pair ??
My Aim is to control Speed of PMDC motor wireless...!!
The first ones are one-way communication and have no encoding scheme, so you'd have to provide one. These are pretty hard to use outright, so I would suggest another module.

The second seems doable, but the third is the best in my opinion. Zigbees are quite nice and there are many tutorials on using them.

So, I would say go with the Zigbees...
 

t06afre

Joined May 11, 2009
5,934
Stick to trying to get a single PIC communicating with a computer, then move on to getting two PICs talking to each other. That way when you do move to two PICs communicating, you can know that at least one PIC is operating properly, and know a problem, if one exists, lies with the other PIC.
I could not agree more. I would start setting up the PIC to just send some well known strings in an endless loop to a terminal program in a PC. Then this is working 100% It is time to do the receive part on the PIC. Use the terminal program and set the PIC up to echo any char typed in on the terminal program. Then you have those part working and ONLY then. You are ready for more complicated work. Then you try to run before you can walk. You will only stumble, and then come crying to the forum asking for comfort. Then this happen to often. The forum will get weary and ignore you
 

Thread Starter

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
The first ones are one-way communication and have no encoding scheme, so you'd have to provide one. These are pretty hard to use outright, so I would suggest another module.
I had buy that Tx and Rx module i only need to send the ADC result to another uC.....!!
how?
 

tshuck

Joined Oct 18, 2012
3,534
I would suggest looking into Manchester encoding (that's a pretty common one), for use in the transmitters. By using these, you've made considerably more work for yourself. I have only heard of people getting up to 4800 baud, but it seems 2400 baud is more typical.

Like I had said before, these are not newbie friendly, you will struggle quite a bit with these.
 

tshuck

Joined Oct 18, 2012
3,534

Remember post # 18?
1.) buy the module suggested
2.) plug the module in to the PIC. Rx of module to TX of PIC and TX if module to Rx of PIC

3.) write program that will use the PIC's UART module to send data, with the correct configuration (baud rate, stop bits, parity, etc.) to be compatible with the USB to TTL module.

4.) use a terminal program (i.e. hyperterminal or TeraTerm) to connect to the virtual COM port that is created for the USB to TTL-again, with the same configuration add both the PIC and USB to TTL module are using and watch the data stream.
 

tshuck

Joined Oct 18, 2012
3,534
If you are referring to the code from post # 48, you haven't defined the body of "Initialize", remove the semicolon and replace with open curly bracket, uncomment the initialization routine, and add a closing curly bracket.

At a glance, the rest seems okay...
 
Top