[PIC 5.03 beta 4] Fix USART_INIT() for PIC16 & PIC18(?)

Discuss about beta versions of mikroBasic
compiler.
Post Reply
Author
Message
xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

[PIC 5.03 beta 4] Fix USART_INIT() for PIC16 & PIC18(?)

#1 Post by xor » 28 Aug 2007 03:34

USART_INIT() for mB and mC sets up the TRIS incorrectly for RX and TX pins for PIC16 USART and PIC18 EUSART.

PIC16 from datasheet
Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be
set in order to configure pins RC6/TX/CK and RC7/RX/DT
as the Universal Synchronous Asynchronous Receiver
Transmitter.
Typical ASM for PIC16:

Code: Select all

;usart_c67.ppas,25 :: 		
MOVLW	144
BCF	  STATUS, RP0
MOVWF	RCSTA
;usart_c67.ppas,31 :: 		
BSF	  STATUS, RP0
BSF	  TRISC, 7
;usart_c67.ppas,32 :: 		
BCF	  TRISC, 6
18452 from datasheet:
In order to configure pins RC6/TX/CK and RC7/RX/DT
as the Universal Synchronous Asynchronous Receiver
Transmitter:
• bit SPEN (RCSTA<7>) must be set (= 1),
• bit TRISC<6> must be cleared (= 0), and
• bit TRISC<7> must be set (=1).
18F4520 from datasheet:
The pins of the Enhanced USART are multiplexed
with PORTC. In order to configure RC6/TX/CK and
RC7/RX/DT as a USART:
• bit SPEN (RCSTA<7>) must be set (= 1)
• bit TRISC<7> must be set (= 1)
• bit TRISC<6> must be set (= 1)
Typical ASM for P18:

Code: Select all

$008A	$	_Usart_Init:
BSF	  TXSTA, 5, 0
MOVLW	144
MOVWF	RCSTA, 0
BSF	  TRISC, 7, 0
BCF	  TRISC, 6, 0
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: [PIC 5.03 beta 4] Fix USART_INIT() for PIC16 & PIC18

#2 Post by zristic » 28 Aug 2007 07:46

Thanks xor, we will fix it.

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: [PIC 5.03 beta 4] Fix USART_INIT() for PIC16 & PIC18

#3 Post by srdjan » 04 Sep 2007 14:39

Hi xor,
Have you experienced any kind of problems with our usart routines?! I have tested them with several microcontrollers and they work fine. Please do correct me if I'm wrong.

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#4 Post by xor » 04 Sep 2007 14:57

I used them with the 16F877A a long time ago and it worked fine. In response to someone in the forum I investigated and noticed a difference in the library initialization compared to the datasheet. Comparing datasheets with different PIC/USART's my first reaction is to think the datasheets are in error. In any case I felt it important to bring it to your attention.... in case there are any other reports.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

#5 Post by srdjan » 04 Sep 2007 15:10

xor wrote:I used them with the 16F877A a long time ago and it worked fine. In response to someone in the forum I investigated and noticed a difference in the library initialization compared to the datasheet. Comparing datasheets with different PIC/USART's my first reaction is to think the datasheets are in error. In any case I felt it important to bring it to your attention.... in case there are any other reports.
OK, thanks for that.
A while ago I did the revisions of usart libraries and noticed that with some pic16 mcus when trisc[7:6] are set to "1" usart module does not initialize as it should and therefore does not work. So I began to wonder whether datasheet says that these bits should be set (as set appropriately/correctly) or set (as set to be "1"). As I did not find answer to this question of mine, the library was left as it works.
As far as the pic18 family is concerned, since the library worked with both addressable and enhanced usart module it was left like that to avoid making and maintaining two usart libraries for the same usart pinout.
We will keep these libraries as they are for now. If you or other users should report confirmed problems regarding this issue, we will change them.
Anyway, thank you for reporting this.

Post Reply

Return to “mikroBasic Beta testing”