March 27th, 2013, 03:18 AM
Send variable through USART
Hi, I'm having trouble sending a variable through USART... PIC184520 with C18 complier. My goal is to generate a random number and send it over an sms. So I need to send it through USART to the GSM modem...
Right now I'm either getting nothing or garbage values for this. I'm testing it by displaying this over hyperterminal first.
int num1 = rand() % 100;
int z = 0x1a;
OpenUSART(USART_TX_INT_OFF & //Transmit interrupt off
USART_RX_INT_ON & //Receive interrupt on
USART_ASYNCH_MODE & //Asynchronous mode
USART_EIGHT_BIT & //8-bit data
USART_CONT_RX & //Continuous reception
March 27th, 2013, 03:33 PM
Perhaps you should use sprintf to format your number as a string, and then send that string.
Sending any random byte ranging from 0 to 99 (especially when one possible value is the same as int z = 0x1a) is sure to confuse things.