1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Serial comm between uC and PC...

Discussion in 'Microcontrollers' started by koolguy, Apr 26, 2013.

  1. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    [MODNOTE]Deleted Off Topic[/MODNOTE]
     
    Last edited by a moderator: May 24, 2013
    • Like Like x 1
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    I thought we were talking about a pic16f877a!! Where is the keyboard? Are you trying to send a message to the pic from a PC? If so what language did you settle on...
     
  3. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    OK, once more.....
    i am sending data from PC to uC just single letter like 'A' and the uC will receive the data and test it in if cond and then only uC will send
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland

    I am so glad you finally got it working.. good job!
     
  6. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    yes it is working man since last week and i am working more on it!
     
  7. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I have done some changes in original code for testing but not working now also...

    Code (text):

     #include <pic.h>                // pic specific identifiers
    #define _XTAL_FREQ  20000000        // Xtal speed

    __CONFIG(0x3F72);                // Config bits              
    unsigned char ch;
    unsigned char f;
    unsigned char  HSerin(void);
     void HSerinit(void);
    void HSerout(unsigned char f);
    unsigned char *a= "  Introduction to System Engineering Concepts Open loop and closed loop systems, model classification, performance criterion; Validation and testing of models, mathematical modeling " ;

     void main(void)                        // program entry  
       {    
       int index = 0;  
       ADCON1 = 0x6;                    // Analogue off    
       HSerinit();      
      __delay_ms(150);    
     while(1)                        // endless Loop      
      {

     HSerin();

    if(RCREG=='b');
    {

    f =  'a' ;
         HSerout(f);
    __delay_ms(250);
     
     
      }    
       }
     }  
     
     
     void HSerinit()    
     {    
       TRISC = 0b10000000;                    // should ideally be set  
       SPBRG = 129;                    // 20Mhz xtal 9600 BAUD    
       TXSTA = 0x24;                    // TXEN and BRGH  
       RCSTA = 0x90;                    // SPEN and CREN    
     }  

     void HSerout(unsigned char f)     {  
       while(!TXIF);                    // Wait for module to finish  
      TXREG = f;                        // ready to send  
      }

     unsigned char HSerin()    
     {     while(!RCIF);                    // Wait for a character    
     return RCREG;                    // return character    
      }
     
  8. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    You have to fall back to the code that was working and modify it step by step. That is the (only) way you can find out where the problem is.
     
  9. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    You are not getting me!
    i am saying everything is fine but i am not able to know why if cond is not working on pressing any key it work, but it should work/send data when only 'b' is pressed!
     
  10. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    You are not getting me! You have to test all the parts of your system separately. You have to test that the key is working. Test your code step by step.. are the functions working properly etc. be brave and creative.. you can figure it out!
     
  11. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    Yes key is working on keyboard i have changed to another key and ascii even number is also not working..testing cond is not working
     
  12. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Sound like you need help on debugging. What kind of hardware is that.. point to your previous post if you have already posted a schematic or description. How do you know that the system is not working? What the system should do when it is working?
     
  13. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    I have told full story now you are asking what was that.. :confused:??

    everything is same....only i am sending data (single character) from terminal window..
    there is only pic with UART in it, and PC connected with USB module.
    at starting when i press any key in keyboard through terminal window it will send to PIC uC and code will test the pressed key and display only when if cond character is matched 'a' like this
     
  14. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Sounds good. I can't see any problem there..
     
  15. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    then why it is not working???
    why if cond is not tested and on pressing any key it is working?
     
  16. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    If you are confident that your circuit works. Then all you can do is to strip your code down to minimum and start writing it up step-by-step. After each step you test it. When it stops working you have pin-pointed your problem.
     
  17. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    If circuit is fine then only Data is tx and rx..
    the problem is in code
     
  18. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Are you asking or telling me?
     
  19. koolguy

    koolguy Active Member

    Joined:
    Aug 24, 2010
    Messages:
    2,196
    Likes:
    9
    informing yu that circuit is fine only problem in code i think
     
  20. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Yeah, I think you are right. The problem is in the code.
     
  21. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    Your problem is on this line. It is a very basic problem, so you will find it very easily.
     
    • Like Like x 1

Share This Page