sending data to pic via max 232 by rs232 not working in proteus

Discussion in 'Embedded Systems and Microcontrollers' started by maxD123, Dec 28, 2013.

  1. maxD123

    Thread Starter New Member

    Dec 28, 2013
    3
    0
    hi guys this is my 1st post in this forum !!
    I need send data between pc and pic so i made this schematic using proteus wrote the very simple ccs c code for pic 18f2550

    Code ( (Unknown Language)):
    1.  
    2. [COLOR=#339933]#include<18f2550.h>[/COLOR] [COLOR=#339933]
    3. #fuses NOWDT,HS,NOPROTECT,NOLVP[/COLOR]
    4. [COLOR=#339933]#use delay(clock=20000000)[/COLOR]
    5.  [COLOR=#339933]#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,INVERT,parity=N,bits=8)[/COLOR]   [COLOR=#993333]
    6. void[/COLOR] main[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]
    7. {[/COLOR]     [COLOR=#993333]char[/COLOR] a[COLOR=#339933];[/COLOR]
    8.     [URL="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"][COLOR=#000066]printf[/COLOR][/URL][COLOR=#009900]([/COLOR][COLOR=#ff0000]"Start typing ...[COLOR=#000099][B]\n[/B][/COLOR]."[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
    9.     [COLOR=#b1b100]while[/COLOR][COLOR=#009900]([/COLOR][COLOR=#0000dd]1[/COLOR][COLOR=#009900])[/COLOR]   [COLOR=#009900]
    10. {
    11. [/COLOR]  a[COLOR=#339933]=[/COLOR][URL="http://www.opengroup.org/onlinepubs/009695399/functions/getc.html"][COLOR=#000066]getc[/COLOR][/URL][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
    12.         [URL="http://www.opengroup.org/onlinepubs/009695399/functions/putc.html"][COLOR=#000066]putc[/COLOR][/URL][COLOR=#009900]([/COLOR]a[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]   [COLOR=#009900]
    13.  
    14. }[/COLOR]    [COLOR=#009900]
    15. }
    16.  
    17. [/COLOR]
    18.  
    and my schematic is goto http://obrazki.elektroda.pl/2276196000_1388233204.jpg
    and when i run the code the result is like this http://obrazki.elektroda.pl/6774018100_1388233383.jpg

    so friend before this i used exsisr.c with little change

    Code ( (Unknown Language)):
    1.  
    2. [COLOR=#339933]#if defined(__PCM__)[/COLOR]
    3. [COLOR=#339933]#include <16F877.h>
    4. [/COLOR][COLOR=#339933]#fuses HS,NOWDT,NOPROTECT,NOLVP[/COLOR] [COLOR=#339933]
    5. #use delay(clock=20000000)
    6. [/COLOR][COLOR=#339933]#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)[/COLOR]  
    7. [COLOR=#339933]
    8. #elif defined(__PCH__)[/COLOR] [COLOR=#339933]
    9. #include <18F2550.h>[/COLOR] [COLOR=#339933]
    10. #fuses HS,NOWDT,NOPROTECT,NOLVP
    11. [/COLOR][COLOR=#339933]#use delay(clock=20000000)
    12. [/COLOR][COLOR=#339933]#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS,INVERT)[/COLOR]  
    13. [COLOR=#339933]
    14. #elif defined(__PCD__)[/COLOR] [COLOR=#339933]
    15. #include <30F2010.h>[/COLOR]
    16. [COLOR=#339933]#fuses HS, NOWDT, NOPROTECT[/COLOR] [COLOR=#339933]
    17. #use delay(clock=20000000)
    18. [/COLOR][COLOR=#339933]#use rs232(baud=9600, UART1A)
    19. [/COLOR][COLOR=#339933]#endif[/COLOR]     [COLOR=#339933]
    20. #define BUFFER_SIZE 32[/COLOR]
    21.  
    22.  BYTE buffer[COLOR=#009900][[/COLOR]BUFFER_SIZE[COLOR=#009900]][/COLOR][COLOR=#339933];
    23. [/COLOR] BYTE next_in [COLOR=#339933]=[/COLOR] [COLOR=#0000dd]0[/COLOR][COLOR=#339933];[/COLOR]
    24.  BYTE next_out [COLOR=#339933]=[/COLOR] [COLOR=#0000dd]0[/COLOR][COLOR=#339933];
    25. [/COLOR][COLOR=#339933]
    26. #int_rda[/COLOR] [COLOR=#993333]
    27.  
    28. void[/COLOR] serial_isr[COLOR=#009900]([/COLOR][COLOR=#009900])
    29. [/COLOR] [COLOR=#009900]{[/COLOR]    [COLOR=#993333]int[/COLOR] t[COLOR=#339933];
    30. [/COLOR]
    31.  buffer[COLOR=#009900][[/COLOR]next_in[COLOR=#009900]][/COLOR][COLOR=#339933]=[/COLOR][URL="http://www.opengroup.org/onlinepubs/009695399/functions/getc.html"][COLOR=#000066]getc[/COLOR][/URL][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]    
    32.  t[COLOR=#339933]=[/COLOR]next_in[COLOR=#339933];
    33. [/COLOR] next_in[COLOR=#339933]=[/COLOR][COLOR=#009900]([/COLOR]next_in[COLOR=#339933]+[/COLOR][COLOR=#0000dd]1[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#339933]%[/COLOR] BUFFER_SIZE[COLOR=#339933];[/COLOR]    
    34. [COLOR=#b1b100] if[/COLOR][COLOR=#009900]([/COLOR]next_in[COLOR=#339933]==[/COLOR]next_out[COLOR=#009900])[/COLOR]      
    35.  next_in[COLOR=#339933]=[/COLOR]t[COLOR=#339933];[/COLOR]           [COLOR=#666666][I]// Buffer full !![/I][/COLOR] [COLOR=#009900]
    36.  
    37.  }
    38. [/COLOR][COLOR=#339933]
    39. #define bkbhit (next_in!=next_out)[/COLOR]  
    40.  
    41. BYTE bgetc[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]
    42. {
    43. [/COLOR]BYTE c[COLOR=#339933];
    44. [/COLOR][COLOR=#b1b100]while[/COLOR][COLOR=#009900]([/COLOR][COLOR=#339933]![/COLOR]bkbhit[COLOR=#009900])[/COLOR] [COLOR=#339933];
    45. [/COLOR]c[COLOR=#339933]=[/COLOR]buffer[COLOR=#009900][[/COLOR]next_out[COLOR=#009900]][/COLOR][COLOR=#339933];
    46. [/COLOR]next_out[COLOR=#339933]=[/COLOR][COLOR=#009900]([/COLOR]next_out[COLOR=#339933]+[/COLOR][COLOR=#0000dd]1[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#339933]%[/COLOR] BUFFER_SIZE[COLOR=#339933];[/COLOR]    [COLOR=#b1b100]
    47. return[/COLOR][COLOR=#009900]([/COLOR]c[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
    48. [COLOR=#009900]}[/COLOR]
    49.  
    50.  
    51.  [COLOR=#993333]void[/COLOR] main[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR]
    52. [COLOR=#009900]{ [/COLOR]      enable_interrupts[COLOR=#009900]([/COLOR]int_rda[COLOR=#009900])[/COLOR][COLOR=#339933];
    53. [/COLOR]   [COLOR=#339933]#if defined(__PCD__)[/COLOR]    
    54.    enable_interrupts[COLOR=#009900]([/COLOR]intr_global[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]    
    55. [COLOR=#339933]   #else
    56. [/COLOR]   enable_interrupts[COLOR=#009900]([/COLOR]global[COLOR=#009900])[/COLOR][COLOR=#339933];
    57. [/COLOR]   [COLOR=#339933]#endif
    58. [/COLOR]  [URL="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"][COLOR=#000066]printf[/COLOR][/URL][COLOR=#009900]([/COLOR][COLOR=#ff0000]"[COLOR=#000099][B]\r[/B][/COLOR][COLOR=#000099][B]\n[/B][/COLOR][COLOR=#000099][B]\R[/B][/COLOR]unning...[COLOR=#000099][B]\r[/B][/COLOR][COLOR=#000099][B]\n[/B][/COLOR]"[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
    59.                  [COLOR=#666666][I]
    60.  
    61. // The program will delay for 10 seconds and then display[/I][/COLOR]                [COLOR=#666666][I]// any data that came in during the 10 second delay[/I][/COLOR]
    62.      [COLOR=#b1b100]do[/COLOR] [COLOR=#009900]
    63. {[/COLOR]       delay_ms[COLOR=#009900]([/COLOR][COLOR=#0000dd]10000[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]      
    64. [URL="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"][COLOR=#000066]  printf[/COLOR][/URL][COLOR=#009900]([/COLOR][COLOR=#ff0000]"[COLOR=#000099][B]\r[/B][/COLOR][COLOR=#000099][B]\n[/B][/COLOR]Buffered data => "[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];
    65. [/COLOR] [COLOR=#b1b100]while[/COLOR][COLOR=#009900]([/COLOR]bkbhit[COLOR=#009900])[/COLOR]
    66.  [URL="http://www.opengroup.org/onlinepubs/009695399/functions/putc.html"][COLOR=#000066]putc[/COLOR][/URL][COLOR=#009900]([/COLOR] bgetc[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900])[/COLOR][COLOR=#339933];
    67. [/COLOR] [COLOR=#009900]}[/COLOR] [COLOR=#b1b100]while[/COLOR] [COLOR=#009900]([/COLOR]TRUE[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR] [COLOR=#009900]
    68. }
    69.  
    70.  
    71.  
    72.  
    73.  
    74.  
    75.  
    76.  
    77.  
    78. [/COLOR]
    79.  
    so proteus result for this is http://obrazki.elektroda.pl/5680434400_1388234039.jpg

    SO in the both above cases i clicked on rx vir: terminal pressed keyboard buttons but they(the characters i pressed) did not appear in output terminal
    if i say clearly in first case (according to my little code) i pressed keys buttons but output is like in image ("start typing" then nothing..)
    in second case the long code i keep pressing keys for 10s but output like the image i added ( bufferd data..bufferd data.. as in there)

    And also i Used hyperterminal with virtual serial port software in second experiment but same results came as in image..
    I'm using proteus 7.8


    Think u clearly got my problem and show me how to fix this...
    please help me guyssss!!
    thankzz
     
    Last edited by a moderator: Dec 28, 2013
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    In Proteus, you can connect directly to the serial port from the MCU. No need for a max232
     
  3. maxD123

    Thread Starter New Member

    Dec 28, 2013
    3
    0
    ya but i want to use max 232 in my project ..
     
  4. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,553
    2,375
    Do you have a PC with a proper 9pin D RS232 port for a test?
    Max.
     
  5. maxD123

    Thread Starter New Member

    Dec 28, 2013
    3
    0
    thankz for replying
    now i'm using my laptop for this work and it does not have any rs232 port thats why i created virtual port using software when i work with hyperterminal.
    And i have mentioned the results in my comment.
    But i have pc that has com ports rs232
    but i don't have other components pic and other stuff now at this moment..
    I spend two days to fix this problem but unable to fix it
    so what you guys suggest me to do?
     
Loading...