Wednesday, 9 April 2014

Hi fellowVectorians...!
               Firstly i HaveBeen Thanking My Parents For Supporting me and Thankful to Director Raju Sir for providing Genuine Placements. and Guru Sir for Exploring The Knowledge On Technical and Lcs Kishore,Tandava RamaKrishna,Sangu Gurung for explaing patiently for what  I Asked...
      I Had Ateended For 6 Companies..
    1) CUPOLA Technologies
          As I Attended in middle Of My Course I dont have Sufficient knowledge to answer Questions Regarding 8051 Micro Controller..
         Written Test 1:   Basic Questions On C,Linux,Tcp/ip 
          Written Test 2: C Programming and TCP/IP Client Server Communication PRogram
           Technical Round : 
 a)Questions On Answers We Written in 1st Round and 2nd Round
 b)Questions  on My B.tech Project In Depth (I am not Able To Explain Well) 
 c)Questions On MicroController Very Depth

2)VVDN Chennai
       Yep,I Dont Have Enough Knowlege To Clear The Written Test Bcz it Contains Electronics....
       remaining Sections C Basics And Apti are very Easy.... 
3) TeraData
        VeryGood Company , Having 7 Rounds in it Selection process and HighPackage around 4.8 Lakh 
              They Are mainly concentrated on Data Structers And Sorting Mechanisms
       I Got Question from Linked list and tree Concepts In Round1
            in 2nd round they focused on Hashmap,Binary Tree and Programs On Strings
             I am Back From This Round......
4)EliteCore
      I Faced 6 Rounds for this company..
      They Are Mainly Focusing on Apti , Puzzles and Programming 
    Wrtitten Test 1: C basics,Apti
    Written Test 2:  Data Structres Programming,Linux Internals
    Technical Round 1 : C Basics ,C programming ,Puzzles
     Technical Round 2: Linux Internals, Tcp/Ip ,Vector Project
    Techinical Round 3: questions from Toatl Vector Course Cirriculam and Answers Which are Written by Us...
     Telephonic Round : itself Mixing Of Technical and HR questions..(I Rejected)
5)Safran Engineering Services,BLR
    i had faced written test and Technical only 
  In Techinical I got Questions From C very Depth
  --> Create Generis Stack which has Able to add Integer or charcter or string or float pr even Structure also..
--> Create Cirular Stack
Ans:
I have a need for a fixed-size (selectable at run-time when creating it, not compile-time) circular buffer which can hold objects of any type and it needs to be very high performance. I don't think there will be resource contention issues since, although it's in a multi-tasking embedded environment, it's a co-operative one so the tasks themselves can manage that.
My initial thought were to store a simple struct in the buffer which would contain the type (simple enum/define) and a void pointer to the payload but I want this to be as fast as possible so I'm open to suggestions that involve bypassing the heap.
Actually I'm happy to bypass any of the standard library for raw speed - from what I've seen of the code, it's not heavily optimized for the CPU : it looks like they just compiled C code for things like strcpy()and such, there's no hand-coded assembly.
Any code or ideas would be greatly appreciated. The operations required are:
  • create a buffer with specific size.
  • put at the tail.
  • get from the head.
  • return the count.
  • delete a buffer.
Program:
typedef struct circular_buffer
{
    void *buffer;     // data buffer
    void *buffer_end; // end of data buffer
    size_t capacity;  // maximum number of items in the buffer
    size_t count;     // number of items in the buffer
    size_t sz;        // size of each item in the buffer
    void *head;       // pointer to head
    void *tail;       // pointer to tail
} circular_buffer;

void cb_init(circular_buffer *cb, size_t capacity, size_t sz)
{
    cb->buffer = malloc(capacity * sz);
    if(cb->buffer == NULL)
        // handle error
    cb->buffer_end = (char *)cb->buffer + capacity * sz;
    cb->capacity = capacity;
    cb->count = 0;
    cb->sz = sz;
    cb->head = cb->buffer;
    cb->tail = cb->buffer;
}

void cb_free(circular_buffer *cb)
{
    free(cb->buffer);
    // clear out other fields too, just to be safe
}

void cb_push_back(circular_buffer *cb, const void *item)
{
    if(cb->count == cb->capacity)
        // handle error
    memcpy(cb->head, item, cb->sz);
    cb->head = (char*)cb->head + cb->sz;
    if(cb->head == cb->buffer_end)
        cb->head = cb->buffer;
    cb->count++;
}

void cb_pop_front(circular_buffer *cb, void *item)
{
    if(cb->count == 0)
        // handle error
    memcpy(item, cb->tail, cb->sz);
    cb->tail = (char*)cb->tail + cb->sz;
    if(cb->tail == cb->buffer_end)
        cb->tail = cb->buffer;
    cb->count--;
}

--> Function Pointers
function pointer (or subroutine pointer or procedure pointer) is a type of pointer supported by third-generation programming languages (such as PL/ICOBOLFortran,dBASE dBL, and C) and object-oriented programming languages (such as C++ and D). Instead of referring to data values, a function pointer points to executable code within memory. When dereferenced, a function pointer can be used to invoke the function it points to and pass it arguments just like a normal function call. Such an invocation is also known as an "indirect" call, because the function is being invoked indirectly through a variable instead of directly through a fixed name or address. Function pointers can be used to simplify code by providing a simple way to select a function to execute based on run-time values.

Wild Pointer,Dangling Pointer
Dangling pointers and wild pointers in computer programming are pointers that do not point to a valid object of the appropriate type. These are special cases of memory safety violations.
Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. As the system may reallocate the previously freed memory to another process, if the original program then dereferences the (now) dangling pointer, unpredictable behavior may result, as the memory may now contain completely different data. This is especially the case if the program writes data to memory pointed by a dangling pointer, a silent corruption of unrelated data may result, leading to subtle bugs that can be extremely difficult to find, or cause segmentation faults (UNIX, Linux) orgeneral protection faults (Windows). If the overwritten data is bookkeeping data used by the system's memory allocator, the corruption can cause system instabilities.
Wild pointers arise when a pointer is used prior to initialization to some known state, which is possible in some programming languages. They show the same erratic behaviour as dangling pointers, though they are less likely to stay undetected.
-->  Structure Padding , Holes ,Pragma pack ,find size of structure without using sizeof OPerator
--> Valgrind Tool to find out Memory Leaks
6)American MegaTrends  Inc
 I got Selected In This Company..
 Process:
Written Test 1: Apti,IQ questions(Objective),C questions(Objective),Java Questions(Objective),HR Questions(Descriptive) ,Two Java Progrms
Written Test 2: C and C++ Programming And Theotical Questions
HR Round : Asked me about from myself from my  childhood  to till now.. about 1 Hour...

    Finally I Got Selected in Ami..
Read More

Recruitment Process in VVDN Technologies

Hello friends,

This was a pattern of VVDN paper held on 29-06-13 in Vector Bangalore.
3 sections,total 60 ques,90 minutes

I- 20 questions on aptitude.
II-20 questions on electronics.
III-20 questions on C.

The level of questions was average.

I am providing the questions of Electronics Section.

1-Unit of magnetic field.

In SI units, B is measured in teslas (symbol: T) and correspondingly Î¦B (magnetic flux) is measured in webers (symbol: Wb) so that a flux density of 1 Wb/m2 is 1 tesla. The SI unit of tesla is equivalent to (newton·second)/(coulomb·metre). In Gaussian-cgs unitsB is measured in gauss (symbol: G). (The conversion is 1 T = 10,000 G.) The H-field is measured in amperes per metre (A/m) in SI units, and in oersteds (Oe) in cgs units.
2-Unit of resistivity.

Ampere - A

The ampere is that constant current which, if maintained in two straight parallel conductors of infinite length, of negligible circular cross section, and placed 1 meter apart in vacuum, would produce between these conductors a force equal to 2 x 10-7 Newton per meter of length.
Electric current is the same as electric quantity in movement, or quantity per unit time, expressed like
I = dq / dt  
where 
I = electric current (ampere, A)
dq = electric quantity (coulomb, C)
dt = time (s)

Coulomb - C

The standard unit of quantity in electrical measurements. It is the quantity of electricity conveyed in one second by the current produced by an electro-motive force of one volt acting in a circuit having a resistance of one ohm, or the quantity transferred by one ampere in one second.

Farad - F

The farad is the standard unit of capacitance. Reduced to base SI units one farad is the equivalent of one second to the fourth power ampere squared per kilogram per meter squared (sA2/kg m2).
When the voltage across a 1 F capacitor changes at a rate of one volt per second (1 V/s) a current flow of 1 A results. A capacitance of 1 F produces 1 V of potential difference for an electric charge of one coulomb (1 C).
In common electrical and electronic circuits units of microfarads Î¼F (1 μF = 10-6 F) and picofarads pF (1 pF = 10-12 F) are used.

Ohm - Î©

The derived SI unit of electrical resistance - the resistance between two points on a conductor when a constant potential difference of 1 volt between them produces a current of 1 ampere.

Henry - H

The Henry is the unit of inductance. Reduced to base SI units one henry is the equivalent of one kilogram meter squared per second squared per ampere squared (kg m2 s-2 A-2).

Inductance

An inductor is a passive electronic component that stores energy in the form of a magnetic field.
The standard unit of inductance is the henry abbreviated H. This is a large unit and more commonly used units are the microhenry abbreviated Î¼H (1 μH =10-6H) and the millihenry abbreviated mH (1 mH =10-3 H). Occasionally, the nanohenry abbreviated nH (1 nH = 10-9 H) is used.

Joule - J

The unit of energy work or quantity of heat done when a force of one Newton is applied over a displacement of one meterOne joule is the equivalent ofone watt of power radiated or dissipated for one second.
In imperial units the British Thermal Unit (Btu) is used to express energy. One Btu is equivalent to approximately 1,055 joules.

Siemens - S

The unit of electrical conductance S = A / V

Watt

The watt is used to specify the rate at which electrical energy is dissipated, or the rate at which electromagnetic energy is radiated, absorbed, or dissipated.
The unit of power W or Joule/second

Weber - Wb

The unit of magnetic flux.
The flux that when linking a circuit of one turn, produces an Electro Motive Force - EMF - of 1 volt as it is reduced to zero at a uniform rate in one second.
  • 1 Weber is equivalent to 108 Maxwells

Tesla - T

The unit of magnetic flux density the Tesla is equal to 1 Weber per square meter of circuit area.

Volt

The Volt - V - is the Standard International (SI) unit of electric potential or electromotive force. A potential of one volt appears across a resistance of one ohm when a current of one ampere flows through that resistance.
Reduced to SI base units,
    1 (V) = 1 (kg m2 / s3 A) 

3-Thevenin equivalent of the circuit.


4-find the voltage across the load,the figure will be provided.
5-find the equivalent capacitance,through the figure provided.
6-find the equivalent gate,gate will be made by BJT.
7-find the equivalent gate,gate will be made by Diode.
8-One multiplexer question.

9-value of charge on electron.

The electron (symbol: e) is a subatomic particle with a negative elementary electric charge.Electrons belong to the first generation of the lepton particle family, and are generally thought to be elementary particles because they have no known components or substructure.The electron has a mass that is approximately 1/1836 that of the proton.Quantum mechanical properties of the electron include an intrinsic angular momentum (spin) of a half-integer value in units of Ä§, which means that it is a fermion. Being fermions, no two electrons can occupy the same quantum state, in accordance with the Pauli exclusion principle. Electrons also have properties of both particles and waves, and so can collide with other particles and can be diffracted like light. Experiments with electrons best demonstrate this duality because electrons have a tiny mass.

−1.602176565(35)×10−19 C
10-2 more question regarding the charge.
11-1 que of BJT circuit. 
12-Effect of temperature on conductivity of the semiconductor.

Let’s Consider the effect of increasing the temperature on the conductivity of semiconductors.
                                   
Let's look at the factors that go into conductivity of a semiconductor and consider how each of these are affected:


sigma = ni q (me + mh)


  • First let's consider q. As with conductors, as temperature increases, the charge on each carrier will not change.
               
  • Now consider mobility. The effect of an increase in temperature on mobility is the same as it was for conductors. With the same reasoning, we see that the drift velocity will decrease causing the mobility to decrease.
                      
  • Lastly, let's consider what will happen to ni for semiconductors as temperature increases. The electrons in the valance band will gain energy and go into the higher energy levels in the conduction band where they become charge carriers! So this term will increase. Not only will it increase, but it will increase exponentially! (Promoting electrons from the valance band into the conduction band is a thermally activated process.) 
    • ni = C e – (E – Eave)/kT  
    • ni = C e – Eg/2kT
So even though mobility decreases, the exponential increase in the number of charge carriers will dominate.

Conclusion:
The electrical conductivity of a semiconductor will increase 
exponentially with an increase in temperature!

sigma = C e – Eg/2kT

We can graph this equation on log vs. 1/T axes to get a linear plot (as with all Arrhenius type equations):
Arrhenius plot showing linear relationship between log of the conductivity vs. 1/T. The slope of the plot is equal to -Eg/2(2.3k)

13-Effect of temperature on conductivity of the conductor.

How Does Temperature Affect the Conductivity of a Conductor?
Let’s Consider the effect of increasing the temperature on the conductivity of conductors.
                                   
Let's look at the factors that go into conductivity and consider how each of these are affected:

sigma = n q m            
  • First consider what will happen to n as temperature increases. The electrons that are charge carriers in a conductor will gain energy and go into higher energy levels. However, these energy levels are all still in the valance band. So the number of charge carriers will not change for a conductor with an increase in temperature.
  • Now consider q. As temperature increases, the charge on each carrier will not change.
                  
  • Finally, what happens to the mobility? Recall that mobility is the drift velocity divided by the electric field strength. Temperature won't affect the electric field strength. But it will decrease the drift velocity because as the temperature increases, the atomic vibrations will increase, which will cause more collisions of the electrons with the crystal lattice. Hence the drift velocity will decrease. 

Conclusion:
The electrical conductivity of a conductor will decrease with an increase in temperature!

The relationship is not linear, however, if we consider the resistivity, which is the reciprocal of conductivity, we do get a linear relationship:
rho  =  rhoroomTemp [1 + alpha(T - Troom)]
where rhoroomTemp is the room temperature resisitvity and alpha is the temperature coefficient of resistivity.

plot showing linear variation of resistivity with temperature for copper, aluminum and iron
The electron (symbol: e) is a subatomic particle with a negative elementary electric charge.Electrons belong to the first generation of the lepton particle family, and are generally thought to be elementary particles because they have no known components or substructure.The electron has a mass that is approximately 1/1836 that of the proton.Quantum mechanical properties of the electron include an intrinsic angular momentum (spin) of a half-integer value in units of Ä§, which means that it is a fermion. Being fermions, no two electrons can occupy the same quantum state, in accordance with the Pauli exclusion principle. Electrons also have properties of both particles and waves, and so can collide with other particles and can be diffracted like light. Experiments with electrons best demonstrate this duality because electrons have a tiny mass.

−1.602176565(35)×10−19 C

14-Find the resistance of the long wire(I dont know the question exactly)
15-1 que on transformer(simple)


16-1 que on steady state 
an unvarying condition in a physical process, especially as in the theory that the universe is eternal and maintained by constant creation of matter
17-1 que on majority carriers & minority carriers in BJT.

Hope this will be helpful for you & best of luck.
Read More

Recruitment process in VVDN Technologies, Chennai

These are the rounds VVDN Tech conducted for us.
Round-1:
First round is written test, it is not objective but descriptive. The written has three sections
-> Aptitude
-> General Electronics(Digital and Analog).
-> C
Aptitude- They asked some problems based on Train(Speed and Distance),Time and some apti questions.
General Electronics-I remember only few questions they gave some digital design's and they asked the truth table for them.
C- basic C questions.
Round-2:
Two people Interviewed me in this round.

The Second round is Technical round. First they asked me some simple C questions(basic) and later Linux basics. Then they moved to basic electronics.
They asked me to calculate Relative resistance for the given Network(both open and short circuits and asked me relative resistance).
Then they moved to Micro-Controllers and asked me some basics mainly on the board and controller of our project done.
They also concentrated on Communication skills and attitude.
Round-3:
This is the final technical round and there will be no HR-round.
In this round One guy interviewed me. He first asked me on my B.Tech and Vector projects.
Then he asked me to write C programs using bit wise operators
I remember one question, he asked me to write a*b operation without using '*' operator using single for loop and bit-wise operatiors.(not simply adding a b times).
Then he moved to Digital Electronics he asked me to design Digital Circuit for the given truth table, he gave one criteria where I have to design two port n/w where if you alter the i/p ports either port1 and  port2 '+' and  '-' or port1 '-' and port2 '+' you have to maintain const o/p only port3 '+' and port4'-'.(where port1 and port 2 are i/p ports and port3 and port4 o/p ports).


All the best guys.
Read More

Previous Interview Questions from AMI

Hai Friends,

AMI Selection process:
They conducted 2 written tests on C, C++ and Java.
Program on 
i) Checking whether the system is little endian or big endian.

Sol:

First of all, Do you know what Little-Endian and Big-Endian mean? 

Little Endian means that the lower order byte of the number is stored in memory at the lowest address, and the higher order byte is stored at the highest address. That is, the little end comes first. 

For example, a 4 byte, 32-bit integer


Byte3 Byte2 Byte1 Byte0


will be arranged in memory as follows: 


Base_Address+0 Byte0 
Base_Address+1 Byte1 
Base_Address+2 Byte2 
Base_Address+3 Byte3 


Intel processors use "Little Endian" byte order.


"Big Endian" means that the higher order byte of the number is stored in memory at the lowest address, and the lower order byte at the highest address. The big end comes first. 


Base_Address+0 Byte3
Base_Address+1 Byte2
Base_Address+2 Byte1
Base_Address+3 Byte0


Motorola, Solaris processors use "Big Endian" byte order.

In "Little Endian" form, code which picks up a 1, 2, 4, or longer byte number proceed in the same way for all formats. They first pick up the lowest order byte at offset 0 and proceed from there. Also, because of the 1:1 relationship between address offset and byte number (offset 0 is byte 0), multiple precision mathematic routines are easy to code. In "Big Endian" form, since the high-order byte comes first, the code can test whether the number is positive or negative by looking at the byte at offset zero. Its not required to know how long the number is, nor does the code have to skip over any bytes to find the byte containing the sign information. The numbers are also stored in the order in which they are printed out, so binary to decimal routines are particularly efficient.


Here is some code to determine what is the type of your machine

int num = 1;
if(*(char *)&num == 1)
{
printf("\nLittle-Endian\n");
}
else 
{
printf("Big-Endian\n");
}

And here is some code to convert from one Endian to another.

int myreversefunc(int num)
{
int byte0, byte1, byte2, byte3; 

byte0 = (num & x000000FF) >> 0 ;
byte1 = (num & x0000FF00) >> 8 ;
byte2 = (num & x00FF0000) >> 16 ;
byte3 = (num & xFF000000) >> 24 ;

return((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | (byte3 << 0));
}


ii) Given Number is power of 2 or not.
#include<stdio.h> 
main() 

int no, rem, flag=0; 
printf("\nEnter a Number: "); 
scanf("%d",&no); 
while(no>2) 

rem=no%2; 
if(rem==1) 

flag=1; 
break; 

else 
no=no/2; 

if(flag==1) 
printf("\nNo is not Power of two."); 
else 
printf("\nNo is Power of two"); 


iii) Java program to implement our own Array List Functions.
Personal Advice:

                Friends, never get nervousness when being got rejected in any of the companies. From each of the failure you are going to learn something. Try try until u get the fruit of success.
Read More

1-wire protocol project to read temparature

Program to provide 1msec Delay Delay.h

void Delayus(unsigned int);
void Delayms(unsigned int);


void Delayms(unsigned int m)
{
unsigned int i,j;
for(i=0;i<m;i++)
for(j=0;j<1275;j++);
}
DS18b20 Temparature Sensor Ds18b20.h
sbit DQ  =  P3^5; // connect with DS1820 Data pin

void DelayMs(unsigned int);
bit ResetDS1820(void);
void DelayUs(int);
bit ReadBit(void);
void WriteBit(bit);
unsigned char ReadByte(void);
void WriteByte(unsigned char);
int ReadTemp(void);
void Delayus(int);


void DelayUs(int us)
{
 int i;
 for (i=0; i<us; i++);
}


//----------------------------------------
// Reset DS1820
//----------------------------------------
bit ResetDS1820(void)
{
 bit presence;
 DQ = 0;   //pull DQ line low
 DelayUs(29);  // leave it low for about 490us
 DQ = 1;   // allow line to return high
 DelayUs(3);  // wait for presence 55 uS
 presence = DQ;  // get presence signal
 DelayUs(25);  // wait for end of timeslot 316 uS 
 return(presence); // presence signal returned
}  // 0=presence, 1 = no part

//-----------------------------------------
// Read one bit from DS1820
//-----------------------------------------
bit ReadBit(void)
{
 unsigned char i=0;
 DQ = 0;  // pull DQ low to start timeslot
 DQ=1;
 for (i=0; i<3; i++); // delay 17 us from start of timeslot
 return(DQ); // return value of DQ line
}

//-----------------------------------------
// Write one bit to DS1820
//-----------------------------------------
void WriteBit(bit Dbit)
{
 unsigned char i=0; 
    DQ=0; 
 DQ = Dbit ? 1:0;
 DelayUs(5);    // delay about 39 uS
 DQ = 1;
}

//-----------------------------------------
// Read 1 byte from DS1820
//-----------------------------------------
unsigned char ReadByte(void)
{
 unsigned char i;
 unsigned char Din = 0;
 for (i=0;i<8;i++)
 {
  Din|=ReadBit()? 0x01<<i:Din;
  DelayUs(6); 
 }
 return(Din);
}

//-----------------------------------------
// Write 1 byte
//-----------------------------------------
void WriteByte(unsigned char Dout)
{
 unsigned char i;
 for (i=0; i<8; i++) // writes byte, one bit at a time
 {     
  WriteBit((bit)(Dout & 0x1));   // write bit in temp into
  Dout = Dout >> 1;
 }
 DelayUs(5);
}

//-----------------------------------------
// Read temperature
//-----------------------------------------
int ReadTemp(void)
{
 unsigned char n,buff[2];
 int temp;
 
 EA=0; // disable all interrupt
 ResetDS1820();
    WriteByte(0xcc);  // skip ROM
    WriteByte(0x44);  // perform temperature conversion
    while (ReadByte()==0xff); // wait for conversion complete 
    ResetDS1820();
    WriteByte(0xcc);  // skip ROM
    WriteByte(0xbe);  // read the result
    
    for (n=0; n<2; n++)     // read 9 bytes but, use only one byte
    {
       buff[n]=ReadByte();  // read DS1820
    }
 EA=1;
 temp=buff[1];
 temp=temp<<8;
 temp=temp|buff[0];
 return(temp);
}


Program to roll a string on LCD LCD.h
#define lcd P0 //LCD Data lines connected to Port 0
sbit rs=P2^0;  //RS bit connected to Port 2.0
sbit rw=P2^1;  //RW bit connected to Port 2.1
sbit en=P2^2;  //En bit connected to Port 2.2

void init_lcd(void);
void writecmd(unsigned char);
void lcd_char(unsigned char);
void lcd_str(unsigned char*,unsigned char);
void lcd_int(char);
void Delayus(int);

//----------------------------------------
// Initlise LCD
//----------------------------------------
void init_lcd()
{
writecmd(0x38);
writecmd(0x0c);
writecmd(0x06);
writecmd(0x01);
}
//----------------------------------------
// Writing command to LCD
//----------------------------------------
void writecmd(unsigned char c)
{
lcd=c;
rs=rw=0;
en=1;
Delayus(400);
en=0;
}

//----------------------------------------
// Writing Char on LCD
//----------------------------------------
void lcd_char(unsigned char d)
{
lcd=d;
rs=1;
rw=0;
en=1;
Delayus(400);
en=0;
}

//----------------------------------------
// Writing String 
//----------------------------------------
void lcd_str(unsigned char *s,unsigned char l)
{
writecmd(l);
while(*s)
lcd_char(*s++);
}

//----------------------------------------
// Writing Integer
//----------------------------------------
void lcd_int(char i)
{
char d=0,t=0,h=0;
if(i)
{
 d=(i%10)+48;
 i=i/10;
 if(i)
 {
  t=(i%10)+48;
  i=i/10;
  if(i)
  h=i+48;
 }
}
if(h)
lcd_char(h);
if(t)
lcd_char(t);
if(d)
lcd_char(d);
}

Serial Data Transmission Serial.h
void init_serial(void);
void ser_char(unsigned char);
void ser_str(unsigned char *);
void ser_int(char);

//----------------------------------------
// Initlise Serial communication 
//----------------------------------------
void init_serial()
{
TMOD=0x20;
TH1=-3;
SCON=0x40;
}

//----------------------------------------
// Sending Character
//----------------------------------------
void ser_char(unsigned char c)
{
TR1=1;
SBUF=c;
while(!TI);
TR1=0;
TI=0;
}

//----------------------------------------
// Sending String
//----------------------------------------
void ser_str(unsigned char *s)
{
while(*s)
ser_char(*s++);
}

//----------------------------------------
// Sending integer
//----------------------------------------
void ser_int(char i)
{
char d=0,t=0,h=0;
if(i)
{
 d=(i%10)+48;
 i=i/10;
 if(i)
 {
  t=(i%10)+48;
  i=i/10;
  if(i)
  h=i+48;
 }
}
if(h)
ser_char(h);
if(t)
ser_char(t);
if(d)
ser_char(d);
}

Main Program To Calculate Temparature by Using 1-wire Protocol Main.c
#include<reg51.h>
#include"lcd.h"
#include"serial.h"
#include"ds18b20.h"


void Delayms(unsigned int);

main()
{
int temp;
char tp,tpd,n=0;
init_lcd();
init_serial();
lcd_str("Temperature:",0x80);
//ser_str("Temperature: ");
while(1)
 {
 n++;
 temp=ReadTemp();        
 tp  = temp>>4;
 tpd=temp&0x08?0x35:0x30;
 writecmd(0xc0);
 lcd_int(tp);
 lcd_char('.');
 lcd_char(tpd);
 lcd_str(" Degree C",0xc4);
 ser_int(n);
   ser_str(" Temperature= ");
 ser_int(tp);
 ser_char('.');
 ser_char(tpd);
 ser_str(" Degree C\r\n ");
 Delayms(200);
 }
}

void Delayms(unsigned int m)
{
unsigned int i,j;
for(i=0;i<m;i++)
for(j=0;j<1275;j++);
}

Read More