Microcontroller › 8051 › gsm module interface › Hi,I’m posting the following
Hi,
I’m posting the following code just to show you how can we make use of the printf function in microcontroller coding. The uart_print () code has been written for AVR actually, but you can refer the file initialization and the function prototype.
//==============================================================/
FILE uart_out = FDEV_SETUP_STREAM(uart_print, NULL,
_FDEV_SETUP_WRITE);
int uart_print(char c, FILE *stream)
{
//
this much code is written for avr
//
if (c == ‘n’)
uart_print(‘r’, stream);
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
return 0;
//
this much code is written for avr
//
}
int main ()
{
unsigned char adc_val;
usart_init ();
adc_init ();
adc_val = adc_get ();
stdout = &uart_out;
printf ( “nTemp:%d C”, adc_val );
}
//==============================================================/
Hope this helps you.