Why? Help,THANKS!

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Why? Help,THANKS!

跳至解决方案
675 次查看
lihao
Contributor I

# define  BUS   (48000000)

# define  PRE  (64)

# define  CLK    ( BUS / (10000*PRE) )

 

main()

{

     unsigned int  A;

     A= CLK;

}

 

******************************************

result:   A=CLK= 62411,    why? Help,Thank you!

标签 (1)
1 解答
593 次查看
kef
Specialist I

(int)10000 * (int)64 = (int)0xC400 = (int)-15360

(long)48000000 / (int)-15360 = -3125

(unsigned int)-3125 = 0xF3CB = 62411

Some UL's or typecasts are missing, try this:

# define  BUS   (48000000ul)

# define  CLK    ( BUS / (10000ul*PRE) )

在原帖中查看解决方案

2 回复数
594 次查看
kef
Specialist I

(int)10000 * (int)64 = (int)0xC400 = (int)-15360

(long)48000000 / (int)-15360 = -3125

(unsigned int)-3125 = 0xF3CB = 62411

Some UL's or typecasts are missing, try this:

# define  BUS   (48000000ul)

# define  CLK    ( BUS / (10000ul*PRE) )

593 次查看
lihao
Contributor I

Thanks you very much!   Best wishes for you!

0 项奖励
回复