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

Difference between use of USART module and bitbang

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



Joined: 11 Feb 2005
Posts: 24

View user's profile Send private message

Difference between use of USART module and bitbang
PostPosted: Tue Oct 18, 2005 6:59 pm     Reply with quote

Hi,
I found that 16F877 has USART module for serial communication. For this application, I have two options for writing code:
(1) by using USART registers such as BRGH, SPBRG (hardware)
(2) by using #use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2) (software)

I believe there are some major differences. I feel that bitbang is easier to use. Does anyone know about the difference between use of USART module (hardware) and bitbang (software)? What are the advantage and disavantage?

Thank you,
ako
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Oct 18, 2005 8:46 pm     Reply with quote

The #use RS232 statement will use the embedded hardware UART if the tx and rx pins you define are the same as the ones used by the hardware and provided you do not use the force SW flag.

Wherever possible you should use the HW UART. If you use the software UART you have to be continuously calling kbhit() at multiple times the bit rate to ensure you do not lose characters or bits.

If you want to use a Rx interrupt handler then you need to use the HW UART as the SW implementation does not support Rx interrupts.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!


Last edited by asmallri on Wed Oct 19, 2005 2:44 am; edited 1 time in total
akokyaw



Joined: 11 Feb 2005
Posts: 24

View user's profile Send private message

PostPosted: Wed Oct 19, 2005 2:26 am     Reply with quote

Hi,
Thank for reply, Andrew. Now, I understand that bitbang (software) has to use initialization routine while USART module (hardware) has to use interrupt such as (TXIF). Anyway, CCS's printf function is intelligent and useful bitbang.
what condition we must use USART module except we need interrupt?

Regards,
ako
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 19, 2005 2:55 am     Reply with quote

Quote:
Now, I understand that bitbang (software) has to use initialization routine


The bitbang approach requires more software polling. If you think about it the software approach requires the CPU to be able to accurated detect each bit of a serial data stream. The hardware approach means the CPU only has to detect each character. Far fewer CPU cycles are required to reliably receive the data stream.

Quote:
while USART module (hardware) has to use interrupt such as (TXIF)


The Hardware does not HAVE to use Interrupts (although it does read the interrupt flag TXIF) but more accurately it ALLOWS receive interrupts to be used.

Quote:
Anyway, CCS's printf function is intelligent and useful bitbang.
what condition we must use USART module except we need interrupt?


The software UART is half duplex. While it is sending it cannot receive (characters are lost). The hardware UART is full duplex PROVIDED you use a receive interrupt handler
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
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