Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

[SOLVED] PIC16F877A controlled 74HC595 by serial command

sherryliu

Member level 1
Joined
Jan 17, 2011
Messages
32
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,535
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!
 

Attachments


betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,195
Helped
4,688
Reputation
9,391
Reaction score
4,442
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
121,200
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.
 

baileychic

Advanced Member level 3
Joined
Aug 2, 2017
Messages
728
Helped
54
Reputation
108
Reaction score
54
Trophy points
28
Activity points
7,033
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.
 

sherryliu

Member level 1
Joined
Jan 17, 2011
Messages
32
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,535
Hi all

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

Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top