Searching \ for '[PIC] C18 &' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/devices.htm?key=pic
Search entire site for: 'C18 &'.

No exact or substring matches. trying for part
PICList Thread
'[PIC] C18 & PIC18F8627: first printf() destroys SP'
2010\03\01@061510 by Matt Rhys-Roberts

flavicon
face
I'm using printf() to talk directly to EUSART1, without going via the
usart.h library. We decided to avoid this library for now in order to
keep code as direct and simple as possible.

printf() appears to call code in file
c:\MCC18\src\pmc_common\USART\_usartpc.asm , which clears SPBRG when
first run, causing serial timing to fail. However, if I manually re-set
SPBRG in the watch window, it remains uncleared and serial transmission
continues happily.

Q1) Any idea why this has to happen, and what could/should be done about it?
Q2) Does anyone have any optimal examples of setting up printf()
explicitly without using usart.h ?

Many thanks,
Matt

----------------- code follows -------------------------------

#include <p18F8627.h>
#include <stdio.h>
#include <delays.h>
// #include <usart.h>


void main(void)
{

// config usart, 9600 8n1, Fosc=18.432MHz

//     MOVLW    b'01000001'
//    MOVWF    TXSTA1,A
TXSTA1 = 0b01000001 ;

//    MOVLW    b'11000000'
//    MOVWF    RCSTA1,A
RCSTA1 = 0b11000000 ;

//    MOVLW    b'00000000'
//    MOVWF    BAUDCON1,A
BAUDCON1 = 0b00000000 ;

//    CLRF    SPBRGH1,A
SPBRGH1 = 0 ;

//    MOVLW    d'29'
//    MOVWF    SPBRG1,A
SPBRG1 = 29 ;



while(1)
{
printf ("Hello World!\n");
Delay10KTCYx (0);

}


}

2010\03\01@074231 by Isaac Marino Bavaresco

flavicon
face
Em 1/3/2010 08:11, Matt Rhys-Roberts escreveu:
{Quote hidden}

Why don't you copy this file, modify the copy (remove the SPBRG
clearing) and add the copy to your project? A file that is added
directly to the project has precedence over the library functions.

Best regards,

Isaac

__________________________________________________
Faça ligações para outros computadores com o novo Yahoo! Messenger
http://br.beta.messenger.yahoo.com/

2010\03\01@083951 by Matt Rhys-Roberts

flavicon
face
Fixed it...

I'd failed to set TXSTA:TXEN bit to 1 before attempting to transmit
characters.

The _usartpc.asm code simply resets SPBRG if TXEN=0. Why? Beats me!

Thanks especially to Dario G for help via the Microchip forum.

Matt

2010\03\01@084535 by Dario Greggio

face picon face
Matt Rhys-Roberts ha scritto:

> I'd failed to set TXSTA:TXEN bit to 1 before attempting to transmit
> characters.
>
> The _usartpc.asm code simply resets SPBRG if TXEN=0. Why? Beats me!
>
> Thanks especially to Dario G for help via the Microchip forum.

:) thx
I suggest the OpenUSART() thing *before* ...


--

Ciao, Dario
--
Cyberdyne

2010\03\01@110451 by Matt Rhys-Roberts

flavicon
face
Dario Greggio wrote:
> :) thx
> I suggest the OpenUSART() thing *before* ...
>  
Understood. Well, we were just seeing how far we could get without
introducing additional levels of abstraction, trying to keep the code as
direct as possible. (My boss doesn't like unnecessary re-labelling of
things!)

2010\03\01@113150 by Michael Rigby-Jones

flavicon
face


> -----Original Message-----
> From: spam_OUTpiclist-bouncesTakeThisOuTspammit.edu [.....piclist-bouncesKILLspamspam@spam@mit.edu] On
Behalf
{Quote hidden}

re-set
> SPBRG in the watch window, it remains uncleared and serial
transmission
> continues happily.
>
> Q1) Any idea why this has to happen, and what could/should be done
about
> it?
> Q2) Does anyone have any optimal examples of setting up printf()
> explicitly without using usart.h ?

I would suggest that since you are using the printf library function,
it's probably assuming you are also using the supplied functions to open
the USART which is OpenUSART() IIRC.

If you want to keep code simple and direct, then using printf is not a
good start, it's probably one of the most complex functions in the
standard C library.

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

2010\03\01@125932 by Isaac Marino Bavaresco

flavicon
face
Em 1/3/2010 13:31, Michael Rigby-Jones escreveu:
> I would suggest that since you are using the printf library function,
> it's probably assuming you are also using the supplied functions to open
> the USART which is OpenUSART() IIRC.
>
> If you want to keep code simple and direct, then using printf is not a
> good start, it's probably one of the most complex functions in the
> standard C library.
>
> Regards
>
> Mike
>  

It all depends on what part you want to be simple, the source code or
the object code.

Using 'printf' makes the source code much simpler, easier to read and
usually directly portable between platforms.

I see people using 'printchar', 'printstring', printnumber', etc
functions. Although they may think it makes the code simpler, the source
code becomes much less readable, and sometimes even the object code
becomes less compact than using 'printf'.

Yes, 'printf' is sometimes a behemoth, but I prefer using it because my
code gets more 'normal', and I can port it across several platforms. I
have products that the same source code runs on a PIC18, on a desktop PC
and also on an ARM9.


Best regards,

Isaac
__________________________________________________
Faça ligações para outros computadores com o novo Yahoo! Messenger
http://br.beta.messenger.yahoo.com/

More... (looser matching)
- Last day of these posts
- In 2010 , 2011 only
- Today
- New search...