hi
all this program should do is do print 2 lines:
1.) either "f ok" or "f not ok"
2.) f_cpu = 3686400
but all i get is:
1.) f not ok
2.) f_cpu = 0016384
i noticed that the factor between those 2 numbers is 225,.. no clue why!
i dont really get it.
#define should replace in the pre-prossessor every "F_CPU" with
"3686400" right?
so if i write
its exactly the same to
1 | const int freq = 3686400;
|
isnt it?
thanks for ur help
luk
1 | #define F_CPU 3686400 // max 3686400 = 3,6MHz
|
2 | #include <avr/io.h>
|
3 | #include <util/delay.h>
|
4 | //#include <stdio.h>
|
5 | #include "lcd-routines.h"
|
6 | #include <math.h>
|
7 |
|
8 | const int freq = F_CPU;
|
9 | int temp = 0;
|
10 | int counter = 0;
|
11 |
|
12 | int main(void){
|
13 |
|
14 | lcd_init();
|
15 |
|
16 | for(counter = 7; counter>=0; counter--){
|
17 |
|
18 | temp = freq * pow(10, -(counter-1));
|
19 |
|
20 | if(counter==7){
|
21 | if(freq==3686400){
|
22 | lcd_string("f ok");
|
23 | } else {
|
24 | lcd_string("f not okay");
|
25 | }
|
26 | lcd_setcursor( 0, 2 );
|
27 | lcd_string("F_CPU = ");
|
28 | }
|
29 |
|
30 | for( ; temp>=10; ){
|
31 | temp = temp%10;
|
32 | }
|
33 |
|
34 | switch(temp){
|
35 | case 0: lcd_string("0"); break;
|
36 | case 1: lcd_string("1"); break;
|
37 | case 2: lcd_string("2"); break;
|
38 | case 3: lcd_string("3"); break;
|
39 | case 4: lcd_string("4"); break;
|
40 | case 5: lcd_string("5"); break;
|
41 | case 6: lcd_string("6"); break;
|
42 | case 7: lcd_string("7"); break;
|
43 | case 8: lcd_string("8"); break;
|
44 | case 9: lcd_string("9"); break;
|
45 | }
|
46 |
|
47 | }
|
48 |
|
49 | return 0;
|
50 | }
|