Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

problem with reading continuous serial data using pic16f877

Status
Not open for further replies.

kobre98

Full Member level 2
Joined
Sep 18, 2011
Messages
145
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Gaza, Palestine
Activity points
2,523
hi guys,

i want to read this data and store it in an array so that i can handle it any way i want such as showing it in 77seg display ,
this data is coming from weight meter head with rs232 support
the head sends data continuously non-stop
i just want to store 20 digit in an array
i used micocode studio but it didn't work for me,
if any one can help me with any code that can do the trick even in c language i'll be thankful
the data is as follows >> virtual terminal.PNG
 

which micro controller which IDE yo are using .it can easily be done in c coding
 

which micro controller which IDE yo are using .it can easily be done in c coding

Well Mr. kobre98, the data comming in at the receiving end of the data line in a serial data transfer is all 0s and 1s; it is difficult to make sense of the data unless the sender and the reciver agree on a set of rules; a protocol, on how the data is packed, how many bits constitute a character, and when the data begins and ends.
 

Hello

How many usefull wires in the RS232 cable ?
over 3 , Tx,Rx and Gnd ?
maybe you have to manage others pin connections as CTS or DTR to slow down the troughput
and synchronise the exchange of data with Hardware protocole.





Give more details to get help !
 

well if anyone has a c code that can do the job it's ok ?
i already set the protocol and the wires and all other connections and i have double checked them so there is no connection problem
i'm using pic 16f877
 

Capture.PNG

this is my circuit

i tried to use serin and hserin in micrcode studio to read data and store it in array but i couldn't get it to work

if anyone has any code in anylanguage that might help me in recieving continuously flowed data at a known baud rate i would be thankful

B.T.W THE HEAD that give me this continuous serial data is th-t3 head

this is it's manual

**broken link removed**

plz help it's critical issue nd i must find the solution as soon as possible
 

which micro controller which IDE yo are using .it can easily be done in c coding

Ask Aameer

By the way, The picture given by you is not complete. Why are you using RX, TX both?

---------- Post added at 05:42 ---------- Previous post was at 05:41 ----------

What interface you are using? 9 pin socket or 2 pin socket?
 

Using HiTechC, which is free with MPLAB, this should get you going...! The worst bit is getting the baud rate right, but there are settings takeble from the datasheet (that dont always work) to get you going... The 877 needs a crystal so will depend on your timing, but not a lot more than this is needed to get you going... A good debugger will help too.... I've a post about 16F877 comms, have a quick look at that too mate


[codeSnippet]

#include<htc.h> //include MCU head file
__CONFIG(0x1832);
//THE configure of MCU,watchdog OFF,electrify delay OPEN,power down check OFF,
//LOW power programme OFF,encrypt,4M crystal HS surge.

//---------------------------------------------
//main program
unsigned char WeightMeterChars[64];
unsigned char WeightMeterPOS=0;
void main()
{
TRISC=0XFF; // set C PORT all OUTPUT
SPBRG=0XC; //set baud rate 19200BPS
TXSTA=0X24; //enable USART,set band rate is high
RCSTA=0X90; //enable USART continue receive
RCIE=0X1; //enable receive interrupt
GIE=0X1; // enable general interrupt
PEIE=0X1; //enable outside interrupt
while(1) // wait for interrupt
{;}
}

//--------------------------------------------
//interrupt function
void interrupt usart(void)
{
if(RCIE&&RCIF) //judge if COMM receive interrupt
{
WeightMeterChars[WeightMeterPOS]= RCREG;
WeightMeterPOS = (WeightMeterPOS++) & 63;
}
}
[/codeSnippet]
 

i'm using 9 pin connector
i connect the serial connector from the head to the pc directly and run the simulation in Proteus then the numbers or results are showed correctly in the screen but i can't get a way to store a portion of the continuously flowing results

---------- Post added at 01:17 ---------- Previous post was at 01:15 ----------

could u explain the code or write comments since i didn't deal with this language before
i used microcode studio
i'll try it and post reply soon
 

Bascially, the idea behind it is a "scrolling point" buffer (I've had 30 years of using them!)... I am unfamiliar with MCStudio, I only have experience in the MPLAB IDE based system using C really at the moment for my base level programming enviroment. In any languge, if you can create an indexed buffer, keep a pointer of the "next position", then when a character comes in, put it in the buffer and increment the counter... The &=63; of the counter makes it return to zero, never hitting 64, effectively looping round and restarting... Any functions reading the data will need to start at the buffer-scroll position, and work in a similar circular manor, basically you can write code to look for anything in the sequence, but unfortunately I only know a limited range of tools....
:) Best regards, good luck mate
NEAL

---------- Post added at 01:36 ---------- Previous post was at 01:25 ----------

I'm in GMT timezone, it's 1.30AM here ! :) I'll help anytime if I can, but may well be sleeping soon... I'm interested to know how you get on, have fun always!
NEAL
 

hello

following you circuit schematic
I suppose you are working only in simulation mode !
because interface MAX232 is missing beetwen PIC UART and DB9 RS232 port
Also you did'nt connect the Gnd pin 5 of DB9 !

Can you send only one caractere or receive one caractere with your actual circuit ?
 

Bascially, the idea behind it is a "scrolling point" buffer (I've had 30 years of using them!)... I am unfamiliar with MCStudio, I only have experience in the MPLAB IDE based system using C really at the moment for my base level programming enviroment. In any languge, if you can create an indexed buffer, keep a pointer of the "next position", then when a character comes in, put it in the buffer and increment the counter... The &=63; of the counter makes it return to zero, never hitting 64, effectively looping round and restarting... Any functions reading the data will need to start at the buffer-scroll position, and work in a similar circular manor, basically you can write code to look for anything in the sequence, but unfortunately I only know a limited range of tools....
:) Best regards, good luck mate
NEAL

---------- Post added at 01:36 ---------- Previous post was at 01:25 ----------

I'm in GMT timezone, it's 1.30AM here ! :) I'll help anytime if I can, but may well be sleeping soon... I'm interested to know how you get on, have fun always!
NEAL

thanks for the explanation, i'll install mplap software and try it out

---------- Post added at 14:31 ---------- Previous post was at 14:29 ----------

hello


following you circuit schematic
I suppose you are working only in simulation mode !
because interface MAX232 is missing beetwen PIC UART and DB9 RS232 port
Also you did'nt connect the Gnd pin 5 of DB9 !

Can you send only one caractere or receive one caractere with your actual circuit ?

i'm using simulation since i didn't yet make a physical circuit to do this job
but i didn't think there might be a problem with the simulation since i receive continuous reading using hyper terminal or Proteus simulation, the only problem is in how to store these continuously flowing characters and display a portion of them in lcd or 7segment
 

hello,

I think also the principle Posted by LightDiodeDesigns is the good way.
if the flow is contineus, you will have to stop it sometimes, to get time for analysis !
What is the Uart speed and cycle time of MCU .. to evaluate how long time you have for background job.

But even you are able to receive all data of Weightmeter, you must know where is the begining and the end of each messages.
for extracting the value stored in the buffer.
i couldn't open the t3.pdf file ?
maybe the protocole is inside this document .
You said " you allready set the protocol "
Could you sumarise what is the protocol exchange ( not the speed, parity..)
Are they some header caractere ?
 

During the ("While (1)" ;) anything is possible, this is what I'd have in there for fun!

[codeSnippet]
while(1) // wait for interrupt
{
for(uchar cStartPos=0; cStartPos<64;cStartPos++)
{
uchar cLookPos= (cStartPos + cCheckPos);
cLookPos &=63; // (Go in the circle)
if((Buffer[NextBuffPos()]=='2') && (Buffer[NextBuffPos()]=='0') && (Buffer[NextBuffPos()]=='0') && (Buffer[NextBuffPos()]=='K') && (Buffer[NextBuffPos()]=='G') )
{
/// Found string "200KG", output to display
Display("You must be American!);
}
}
}
}
unsigned char NextBuffPos()
{
_BuffPos++; _BuffPos&=63;
return _BuffPos;
}
[/codeSnippet]
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top