Em 1/3/2010 08:11, Matt Rhys-Roberts escreveu: > 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 > #include > #include > // #include > > > void main(void) > { > > // config usart, 9600 8n1, Fosc=3D18.432MHz > > // MOVLW b'01000001' > // MOVWF TXSTA1,A > TXSTA1 =3D 0b01000001 ; > > // MOVLW b'11000000' > // MOVWF RCSTA1,A > RCSTA1 =3D 0b11000000 ; > > // MOVLW b'00000000' > // MOVWF BAUDCON1,A > BAUDCON1 =3D 0b00000000 ; > > // CLRF SPBRGH1,A > SPBRGH1 =3D 0 ; > > // MOVLW d'29' > // MOVWF SPBRG1,A > SPBRG1 =3D 29 ; > > > > while(1) > { > printf ("Hello World!\n"); > Delay10KTCYx (0); > > } > > > } > = 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=E7a liga=E7=F5es para outros computadores com o novo Yahoo! Messenger = http://br.beta.messenger.yahoo.com/ = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist