rahul krishnan

rahul krishnan

  • NA
  • 1
  • 1.8k

daq

Oct 6 2012 1:54 AM
sir,
this totic will discussed by all already now i am a new commer so i have some doubt about daq in using 8051
#include <reg51.h>
sbit start=P3^3; // Preparing Pin's For Microconroller
sbit end=P3^4;
sbit oe=P3^5;
sbit ale=P3^6;
sbit clock=P3^2;

unsigned char sensor=0;

void delay() //Simple Delay
{
    int k,l;
    for(k=0;k<30;k++)
        for(l=0;l<80;l++);
}
void initSerial() //Initialize the MCU
{
    TMOD=0x22;
    TH1=0xFD;
    SCON=0x50;
    TR1=1;
    EA=1;
    ES=1;
}
void usDelay(int a) //Initialize Clock for ADC0808 that work with 10kHz
{
    TH0=256-(a/1.085);
    TR0=1;
    ET0=1;
}
void timerRoutine() interrupt 1
{
    clock=~clock;
}
void sendChar(unsigned char ch) // For sending Data
{
    SBUF=ch;
    while(!TI);
    TI=0;
}

void sendReading(unsigned char val) // Sending reading of ADC (1-Character at atime) & ','
{
    sendChar(val);
    sendChar(',');
}
void latch() // Latch the Address of ADC
{
    ale=0;
    delay();
    ale=1;

}
void startConv() // Start Convertion
{
    delay();
    start=0;
    delay();
    start=1;
}
void wait() //Wait the interrupt (end of convertion (EOC))
{
    while(end==1);
}
void get() // to get data from ADC
{
    delay();
    oe=0;
    delay();
    oe=1;
}
void main() // the main Program
{

    unsigned char reading;
    P1=0;
    initSerial();
    usDelay(50);
    while(1)
    {
        if(sensor==8) // sensor for 8-channel
            sensor=0;
        if(sensor==0)
            sendChar('N'); //Evry 8-Reading send 'N' Character
        P1=(P1&0xf8)+sensor;
        latch();
        startConv();
        wait();
        get();
        reading=P2;
        sendReading(reading);
        sensor++;

    }
}


what is need of P1=(P1&0xf8)+sensor;
how can i modify this code for getting value by its name such as if temperature sensor value comes to vb as temp1 "count" and temp sensor 2 it 1s temp2 "count" if any other sensor it is
sensor name then count means value and so on....to understand which sensor giving value. also i want to know how to control delay very urgent pllllllllllllls replay.