I am struggling with the following code:
#include <xc.h>
#include "config.h"
void Init(void);
void uart_send(char*);
void main(void)
{
char arr[2]= {'a','b'};
char i=0;
Init();
uart_send(arr+i);
i++;
uart_send(arr+i);
while(1);
}
void uart_send(char* c)
{
while(PIR1bits.TXIF < 1);
TXREG= *c;
}
void Init(void)
{
OSCCON = 0xef;
TRISBbits.RB7 = 0;
ANSELHbits.ANS11 = 0;
PORTBbits.RB5 = 0;
TRISBbits.RB5 = 1;
BAUDCON = 0x00;
BAUDCONbits.BRG16= 1;
SPBRGH = 0x03;
SPBRG = 0x40;
TXSTA= 0x24;
RCSTA= 0x90;
PIE1 = 0x00;
INTCON = 0x00;
RCSTAbits.CREN = 1;
}
In the first case, I call the function uart_send and I receive 'a'. In the second case, when I call the function again, I also receive 'a' instead of 'b'. I can't figure it out Why. If I modify the code, to use value instead of address:
void uart_send(char);
void main(void)
{
char arr[2]= {'a','b'};
char i=0;
Init();
uart_send(*(arr+i));
i++;
uart_send(*(arr+i));
while(1);
}
void uart_send(char c)
{
while(PIR1bits.TXIF < 1);
TXREG= c;
}
Then, in both cases I receive 0x03.
I use MPLAB X v3.30, XC8 1.37, PIC18F14K50
Please, if You have any idea what do I wrong, share it. Thank you.
UPDATE:
I checked the disassy and it should work. Maybe my mcu partly died or something magic...
i
of typeuintptr_t
(the type should be defined instdint.h
). It's possible you are ending up with weird integer overflows - it's not exactly the best compiler in the world. \$\endgroup\$