CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Bit Banging - read serial COM port

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Carlos Q



Joined: 10 Dec 2009
Posts: 5

View user's profile Send private message

Bit Banging - read serial COM port
PostPosted: Tue Oct 18, 2011 10:11 am     Reply with quote

Hi all,

Hi I have an older board and the firmware was developed in ASM. I would like to develop that firmware using CCS but i have problems reading serial communication from several I/O pins using Bit Banging, how can I code that?? Anyone can help me with a little code for do that? Advices are appreciated.

I can't change the GPIO pins that I use for receive serial communication and they don't have interrupts. The board exists and is older.

I´m using PIC16F877A, 9600 bps for serial communication and 20 MHz.

I will appreciate your help,

Thanks a lot.

Regards,

Carlos Q.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 18, 2011 12:13 pm     Reply with quote

The following page tells 3 ways to do a software UART. CCS uses the
3rd method in the list:
http://www.8052.com/faqs.phtml?FAQ=124758

Here is a simple example of a software UART on pins B0 and B1.
You must have a Max232-type chip connected between the xmit and rcv
pins and your PC's COM port.
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B0, rcv=PIN_B1) // Software UART

//==========================================
void main()
{
char c;

while(1)
  {
   c = getc();  // Read character from PC

   putc(c);  // Send it back to the PC
  }

}
Carlos Q



Joined: 10 Dec 2009
Posts: 5

View user's profile Send private message

PostPosted: Tue Oct 18, 2011 2:24 pm     Reply with quote

Thanks PCM, you always help us.

Only that?

To implement Bit Banging in ASM I need to wait for start bit, stop bit and so on.

How can I ask the presence of one byte or how can I wait for the byte pretense?

In your example, with the while statement, generates an loop but how can I manage the synchronization?

Thanks again.

Carlos

PCM programmer wrote:
The following page tells 3 ways to do a software UART. CCS uses the
3rd method in the list:
http://www.8052.com/faqs.phtml?FAQ=124758

Here is a simple example of a software UART on pins B0 and B1.
You must have a Max232-type chip connected between the xmit and rcv
pins and your PC's COM port.
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B0, rcv=PIN_B1) // Software UART

//==========================================
void main()
{
char c;

while(1)
  {
   c = getc();  // Read character from PC

   putc(c);  // Send it back to the PC
  }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 18, 2011 2:30 pm     Reply with quote

Quote:
To implement Bit Banging in ASM I need to wait for start bit, stop bit and so on.

How can I ask the presence of one byte or how can I wait for the byte pretense?

The #use rs232() statement, and the getc() function do all of that for you.
Look at the .LST file to see the ASM code generated by the compiler.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 6:48 am     Reply with quote

getc() will wait forever until a Start bit arrives. You can also use kbhit() to just check and see if a Start bit is present. You should poll kbhit() at least 4x the serial bit rate to make sure you don't call getc() too late.
_________________
The search for better is endless. Instead simply find very good and get the job done.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 7:46 am     Reply with quote

If I'm understanding the requirement, in the list quoted by PCM programmer you would need to select option 1, where the incoming data is polled at some fast rate, at least 4x the baud rate. At 9600Bd that means 38400 samples/sec minimum, and that's pretty fast for a processor at 20MHz. I think you'd have to abandon the official CCS interrupt structure and use a global interrupt where you'd write all the code yourself, which is tedious and risky. It's easiest if the interrupt doesn't do much, so you might read the entire PortB and shove it into a buffer, increment an index and then get out. The challenge then would be to make sure that back in main() your code can read the buffer and process whatever's there at a rate faster than new data can accumulate.

A wild speculation--is this board receiving RFID data? Multiple receive-only serial ports sounds like it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group