Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Grant Beattie
02/11/20 14:10
Read: 312 times
Irvine, Ca
USA


 
#190967 - Keil C51 Bug
I think I found a bug in the pre-processor for C51 v9.52. I'm using uVision V4.72.9.0

In testing some baud rates I found that the table values calculated by the pre-processor are wrong in one instance. All of the baud rate generator values are correct except for 19600.


#define  SYS_CLK   12000000L           // Tcyc = 1/12MHz = 83ns

/*
| Baud rate to UART 1 baud rate generator reload conversion. 
|
|                       SYSCLK
| Reload = 65536 - ------------------  
|                  PRE * 2 * baudrate
|
| Assume SYSCLK is 12MHz and Baud Rate Prescaler Select == 11 (/1).

*/
#define  NUM_BAUDRATES  9

static U16 code BaudParams[NUM_BAUDRATES] =
   {
   65536 - (SYS_CLK/(1*2*1200)),       // 0xEC78 (exact)
   65536 - (SYS_CLK/(1*2*2400)),       // 0xF63C (exact)
   65536 - (SYS_CLK/(1*2*4800)),       // 0xFB1E (exact)
   65536 - (SYS_CLK/(1*2*9600)),       // 0xFD8F (exact)
   65536 - (SYS_CLK/(1*2*19200)),      // 0xFEC7 (0.16%) // COMPILER BUG? Gives 0x01BA. :(
   65536 - (SYS_CLK/(1*2*38400)),      // 0xFF64 (0.16%)
   65536 - (SYS_CLK/(1*2*57600)),      // 0xFF98 (0.16%)
   65536 - (SYS_CLK/(1*2*115200)),     // 0xFFCC (0.16%)
   65536 - (SYS_CLK/(1*2*31250))       // 0xFF40 (exact)
   };

#if(65536 - (SYS_CLK/(1*2*19200)) != 0xFEC7)
   #warning "Compiler preprocessor BUG at UART1 Baud rate 19200!"
#endif

 


If anyone wants to double check this and other versions, that would be great. Also not sure if it's worth trying to find the Keil/Arm forum wherever it's gotten to...





List of 6 messages in thread
TopicAuthorDate
Keil C51 Bug      Grant Beattie      02/11/20 14:10      
   integer overflow      Jan Waclawek      02/12/20 01:06      
      Same result (bad)      Grant Beattie      02/12/20 09:45      
         Spreadsheet Analysis       Michael Karas      02/13/20 23:18      
         please try again      Jan Waclawek      02/14/20 15:22      
            Yay      Grant Beattie      02/14/20 15:58      

Back to Subject List