??? 01/03/12 09:40 Read: times Msg Score: -1 -1 Message Not Useful |
#185280 - frequency counter |
dear all
i am making frequency counter with 89s52 .and displaying it on sevensegment display using 4094. here is my coad olz tell me where i am wrong. error is that i cant get correct output. /*******************************************/ /* Frequency Counter With */ /* 89s52 + 4094 */ /*******************************************/ #include <REGX52.H> #include <math.h> sbit CLK = P1^1; sbit DIN = P1^0; sbit strobe = P1^2; sbit key = P3^2; unsigned int calc_del; unsigned char scale =1; unsigned char buffer[4],dig[4]; float sample[5]; unsigned long f; unsigned char segment[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10}; unsigned char a,b,c,d,e,dcnt; void delay(y){ unsigned int i; for(i=0;i<y;i++){;} } void int_to_digits(unsigned long number) { //store the digits of an integer number in the variable a,b,c,d float itd_a,itd_b; itd_a = itd_a = number / 10.0; dig[3] = floor((modf(itd_a,&itd_b)* 10)+0.5); itd_a = itd_b / 10.0; dig[2] = floor((modf(itd_a,&itd_b)* 10)+0.5); itd_a = itd_b / 10.0; dig[1] = floor((modf(itd_a,&itd_b)* 10)+0.5); itd_a = itd_b / 10.0; dig[0] = floor((modf(itd_a,&itd_b)* 10)+0.5); } void count_pulses() interrupt 1 //counter 0 interrupt { if (scale < 200) scale++; //ex_pulses++; } void write_led() { char i,j; for(j=0;j<4;j++) { for(i=0;i<8; i++) { if(buffer[j]&0x80) DIN = 1; else DIN=0; CLK= 1; buffer[j] <<=1; CLK = 0; } } strobe = 1; ; strobe = 0; } void move_Buffer() { buffer[3] = segment[dig[0]]; buffer[2] = segment[dig[1]]; buffer[1] = segment[dig[2]]; buffer[0] = segment[dig[3]]; } void reset() { if( key == 0) { f=0; } } void main() { EA = 1; // EX0 = 0; /// EX1 = 0; ET0 = 1; //Enable the Timer/counter 0 interrupt TR0 = 1; //Enable Timer/counter 0 to count TMOD = 0x25; //counter 0 in mode 1 (16 bit counter) , timer 1 in mode 2 (auto reload from TH1) TL0 = 0; //empty the counting registers TH0 = 0; //empty the counting registers TH1 = 100; //start timer 1 from 0 ET1 = 1; //enable timer 1 interrrupt TR1 = 1; //Enable Timer/counter 1 to count PT0 = 1; PT1 = 0; // IT0 = 1; // IT0 = 1; while(1) { calc_del++; if (calc_del > (12750/scale)) // update data in 1/6 sec { calc_del = 0; { f = (TL0 +TH0*256); sample[4] = sample[0] ; sample[3] = sample[1] ; sample[2] = sample[2] ; sample[1] = sample[3] ; sample[0] = f; } { TL0=0; TH0=0; if (TH0 < 10) { if (scale > 9) { scale--; } } } f = floor((sample[0]+sample[1]+sample[2]+sample[3]+sample[4])/5)*scale; // calculate the average of 5 readings reset(); int_to_digits(f); move_Buffer(); write_led(); delay(1); } } } i will be thank full to every one regards anil kumar |
Topic | Author | Date |
frequency counter | 01/01/70 00:00 | |
double posting ... | 01/01/70 00:00 | |
at this.. | 01/01/70 00:00 | |
I mean... | 01/01/70 00:00 |