+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Member level 1
    Points: 1,749, Level: 9
    Achievements:
    7 years registered

    Join Date
    Jan 2011
    Posts
    32
    Helped
    1 / 1
    Points
    1,749
    Level
    9

    PIC16F877A controlled 74HC595 by serial command

    Hi all

    I have a project need controlled 74hc595 by serial port send command such as send"0xEA 0xFC 0x01 55"controlled Q0,and send"0xEA 0xFC 0x02 55"controlled Q1,
    but i have a problem when i send first command is right,then send second command or third command MCU was stuck,as snapshot,who can help me fixed it ,thanks in advance!

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 81,321, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,334
    Helped
    4454 / 4454
    Points
    81,321
    Level
    69

    Re: PIC16F877A controlled 74HC595 by serial command

    I cannot use Proteus but looking at the code it seems you overflow the receive buffer after a few characters have arrived fro the USART.
    You use
    Code:
    char buf[]={0x00,0x00,0x00,0x00}; ......
    
           buf[rxcount]=RCREG;
           rxcount++;
    but you do not check that "rxcount" has got bigger than 3. Remember you need a zero at the end of the characters to mark the end of the data so "buf" has to be at least one character bigger than your expected input.
    There should be something to reset "rxcount" to zero again (maybe "rxcount = 0; buff[0] = 0;") when you have finished processing it.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  3. #3
    Advanced Member level 2
    Points: 3,128, Level: 13
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    622
    Helped
    49 / 49
    Points
    3,128
    Level
    13

    Re: PIC16F877A controlled 74HC595 by serial command

    I can help you with your project. You really need to use a delimiter at the end of each UART command transmission which controls the output of the 74HC595. A 0x0D delimeter will be fine. If you use delimiters like '\r\ or '\n' that is ENTER key then Proteus Virtual Terminal will not handle it and it will not send those characters to your PIC.

    It is better if you can use COMPIM model without MAX232 in Proteus and link Proteus with any Serial Terminal software which can send delimiters like '\r' or '\n' at the end of each 4-byte command that you are using.

    I will check your code today but I can't help much with MPLAB Hi-Tech PICC code because it is very old and I don't have it installed.

    Tell me which delimiter you can use at the end of your 4-byte commands and I will tell you how to fix the code.

    Once the end delimiter is received or if the byte lenght exceeds your 4-byte command then you have to reset the buffer index to 0 and set a flag which will be tested for true in the main loop and HC595 controlled in the main loop and then flag creared so that UART can receive new commands after processing the previous one.



    •   AltAdvertisement

        
       

  4. #4
    Member level 1
    Points: 1,749, Level: 9
    Achievements:
    7 years registered

    Join Date
    Jan 2011
    Posts
    32
    Helped
    1 / 1
    Points
    1,749
    Level
    9

    Re: PIC16F877A controlled 74HC595 by serial command

    Hi all

    Thank for all comment,I have been fixed it,thanks!!



--[[ ]]--