| ??? 11/25/06 07:40 Read: times |
#128496 - v to f interfacing with 89s52 |
hi there i am interfacing the v to f converter AD645
to 89s52 i am going to used this v to f converter as an ADC.but i trapped in some problem the value is not displayed on the display(7 SEGMENT)the routine for the display is working properly as i tried it with the test value following code give you the clear idea. and i am using keil
#include<reg52.h>
#include<define.h>
#include<intrins.h>
/*****************function declaration***************************/
void disp_wait(void);
void disp(unsigned int);
unsigned int cal();//v2f
/**********************************************************************/
unsigned char number_code[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//7_seg
unsigned int i,j,k,l,val;//7_seg
unsigned int No_Of_Count,Over_Flow_Occours,No_In_Counter,No_In_CounterHI,No_In_CounterLO;//v2f
unsigned int sec_1 = 0; //v2f
/********************* interrupt setting (routine)*************************/
void TMR_1(void) interrupt 3 //v2f
{Over_Flow_Occours++;}
void TMR_0(void)interrupt 1
{
TF0 = 0; //reload timer
TR0 = 0;
TH0 = 0x63;
TL0 = 0xbf;
disp(val); // call display
sec_1++; // dec upto 1 sec
if(sec_1 == 50)
{
sec_1 = 0;
No_Of_Count = cal();
TR0 = 1;
}
else
{TR0 = 1;}
}
void disp(unsigned int val)
{
unsigned int tempreg,i_digi,j_digi,k_digi,l_digi;
unsigned int val_2,val_3;
tempreg = val;
i_digi = tempreg % 10;
val_2 = tempreg / 10;
i = i_digi;
j_digi = val_2 % 10;
val_3 = val_2 / 10;
j = j_digi;
k_digi = val_3 % 10;
k = k_digi;
l_digi = val_3 / 10;
l= l_digi;
DECOD1 = 0;
DECOD2 = 0;
DECOD3 = 0;
P0 = number_code[i];
disp_wait();
DECOD1 = 1;
DECOD2 = 0;
DECOD3 = 0;
P0 = number_code[j];
disp_wait();
DECOD1 = 0;
DECOD2 = 1;
DECOD3 = 0;
P0 = number_code[k];
disp_wait();
DECOD1 = 1;
DECOD2 = 1;
DECOD3 = 0;
P0 = number_code[l];
disp_wait();
}
void main(void)
{
P0 = 0x3f;
P1 = 0xff;
P2 = 0xf8;
P3 = 0xff;
IE = 0x8A;
TMOD = 0x51; /* Timer 0 as timer in mode 1 ; Timer 1 as counter in mode 1 */
TH0 = 0x63;
TL0 = 0xbf;
TR0 = 1;
while(1)
{}
}
/**************************dly routine's*******************************/
void disp_wait()
{
unsigned int w1=0;
unsigned int w2=0;
for(w1=0;w1<=20;w1++)
{
for(w2=0;w2<=22;w2++)
{}
}
}
/**********************************************************************/
unsigned int cal()
{
unsigned int w1 = 0;
unsigned int w2 = 0;
unsigned int Value;//count in 100 msec period
Over_Flow_Occours = 0x00;
TR1 = 1; // run countrer and give dly for 100 msec
for(w1 = 1;w1<=40;w1++)
{
for(w2 = 1;w2<=930;w2++)
{}
}
TR1 = 0; // stop the counter
TH1 = ACC; // get value from TH1 to ACC
ACC = No_In_CounterHI; // move value(HI) form ACC to No_In_CounterHI
No_In_CounterHI = No_In_CounterHI * 100;
TL1 = ACC;
ACC = No_In_CounterLO; // move value(LO)form ACC to No_In_CounterLO
No_In_Counter = No_In_CounterHI + No_In_CounterLO;
Value =(Over_Flow_Occours*512) + (No_In_Counter);//calculation for no of count.
Value = 2345 ; //test value
val = Value;//No_In_Counter;
return(val); // return No_In_Counter [No_In_Counter == vtg]
}
for ad654 click on http://www.analog.com/UploadedF.../AD654.pdf page no. 8 and 9 will give you the clear idea |
| Topic | Author | Date |
| v to f interfacing with 89s52 | 01/01/70 00:00 | |
| you are calling a SLOW routine in an ISR that | 01/01/70 00:00 | |
| Re: SLOW routine in an ISR | 01/01/70 00:00 | |
| and in all takes way too long time for the ISR to | 01/01/70 00:00 | |
some output at the display | 01/01/70 00:00 |



