自己写的一个简单的风速仪程序

1 /*在cvavr下编写的 已经测试通过 显示用的320*240液晶
2 time0定时1s 每1秒读TCNT1的数据 然后清零tcnt1
3
4
5 */
6
7 #include <mega1280.h>
8 bit flag;
9 unsigned int count;
10 unsigned int date;
11 unsigned char fengji;
12
13 interrupt [TIM0_OVF] void time0_ovf(void)
14 {
15 count++;
16 if(count==28839)
17 {
18 count=0;
19 flag=1;
20
21 }
22
23 }
24 time_init()
25 {
26 TCCR0A=0x00;
27 TCCR0B=0x01;
28 TCNT0=0x00;
29 OCR0A=0x00;
30 OCR0B=0x00;
31
32 TCCR1A=0x00;
33 TCCR1B=0x06;
34 TCNT1H=0x00;
35 TCNT1L=0x00;
36 TIMSK0=0x01;
37 #asm("sei")
38 }
39
40 void fengsu(void)
41 {
42 float m;
43
44 if(flag==1)
45 {
46 flag=0;
48 date=(TCNT1H<<8)+TCNT1L;
49 TCNT1H=0x00;
50 TCNT1L=0x00;
51
52 }
53 if(date==0) m=0;
54 else{
55 m= date* 1.17;
56 m=m+0.4;
57 }
58
59 if(m>=3&&m<15) fengji=1;
60 else if(m>=15&&m<33) fengji=2;
61 else if(m>=33&&m<54) fengji=3;
62 else if(m>=54&&m<79) fengji=4;
63 else if(m>=79&&m<107) fengji=5;
64 else if(m>=107&&m<138) fengji=6;
65 else if(m>=138&&m<171) fengji=7;
66 else if(m>=171&&m<207) fengji=8;
67 else if(m>=207&&m<244) fengji=9;
68 else if(m>=244&&m<284) fengji=10;
69 else if(m>=284&&m<326) fengji=11;
70 else if(m>=326) fengji=12;
71 else fengji=0;
72
73 disp_value(fengji,6,217,16,8,0);
74
75 }
76
77 void main()
78 {
79 fengji=0;
80 time_init();
81 LcdInit();
82 disp_zhujiemian();  
83 while(1)
84 {
85 fengsu();
86 }
87
88 }

posted on 2011-06-14 15:15  码农也疯狂  阅读(584)  评论(0编辑  收藏  举报

导航