c - strange Behavior of sdcc compiler for 8051 -
i used keil programming 8051 microcontrollers. reason have code in sdcc, today facing strange behavior in compiler. using code blocks ide 12.11 , sdcc 3.4 version.
i compiling simple piece of code.
#include <mcs51/8051.h> #include "serial.h" unsigned char digits[5]={0}; void main(void) { serial_init(-13); digits[2]='a'; serial_send(digits[2]); serial_send('a'); while(1) { } }
and here defination of serial_send function.
void serial_send(unsigned char dat){ while(!ti); ti = 0; sbuf = dat; }
the problem that, according code should print 'a' character 2 times on terminal printing 1 time. problem in global veriable digits[] array.
the function work constant value not variable bassed argument.
i posting question here because think problem c language trick, unable figure out.
i tried re-installing compiler , ide both problem remains same. body please explain why happening. have tried different codes , in code constant , local variables works fine global variables providing strange behaviors.
check empty while loop while(!ti);
not being optimised out compiler. main code ambiguous can't tell 'a'
you're seeing being sent.
change of them 'b'
, try swapping order of 2 serial_send()
calls verify it's not case of sbuf being prematurely overwritten new data before uart has sent current byte.
Comments
Post a Comment