8051 Manual Fin
8051 Manual Fin
8051 Manual Fin
Micro
Controller
Lab Manual
ORG 0H
START1: MOV R0,#40H ;R0 POINTED TO INTERNAL RAM 40H
MOV R1,#30H ;R1 POINTING TO INTERNAL RAM 030H
MOV R2,#5 ;R2 LOADED WITH NO. OF ELEMENTS IN `
;THE ARRAY
START: MOV A,@R0 ;DATA TRANSFER
MOV @R1,A
INC R0
INC R1
DJNZ R2,START ;DECREMENT R2,IF NOT EQUAL TO ;
0,CONTINUE WITH DATA
;TRANSFER PROCESS.
HERE: SJMP HERE
END
RESULT:
Before Execution: Fill 5 locations at I:0040h with data bytes.
5 locations at I:0030h are blank.
After Execution: 5 locations I:0040h are filled up with data. These are copied
to 5 locations at I:0030h .
After Execution: 10 locations at X:8041h are filled up with data from 8035h.
Algorithm:
1. Initialize registers to hold the count of number of data bytes to be
moved, the source address and the shift(difference between
destination addresses and source address).
2. Compute addresses of last locations of destination and source blocks.
and set the pointers(using bank registers R0 & R1)
3. Get data from source location into accumulator
4. Transfer accumulator content to the destination location.
5. Decrement the count, update data pointers(Decrement R0&R1).
6. Check whether all the bytes are transferred or not. ie, if count is not
zero repeat step 3 through 6.
Note: To transfer the Block to a memory with overlapped memory address
the pointers are to be pointed to the end of the blocks
Program Code:
ORG 0
MOV R1,#10H ;SOURCE BLOCK
MOV R2,#6H ;NUMBER OF ELEMENTS TO BE ;MOVED(BLOCK
SIZE)
MOV R3,#3H ;SHIFT
MOV A,R1
ADD A,R2
MOV R1,A
ADD A,R3
MOV R0,A
LOOP:DEC R0
DEC R1
MOV A,@R1
MOV @R0,A
DJNZ R2,LOOP
END
Results:
Before Execution: locations from I:0010h are filled up with data bytes.
MOVX @R1,a
XCH A, R2
MOVX @R0,a
INC R0
INC R1
DJNZ R3, BACK
HERE: SJMP HERE
END
RESULT:
Before Execution: 5 locations at X:0027h & X:0041h are filled up with data.
LAB Assignments:
1) Write an ALP to move a block of 10 data bytes, stored in external RAM
starting at location 8050h to internal RAM locations at 30h.
2) Write an ALP to move a block of 10 data bytes, stored in internal RAM
starting at location 10h to locations in external RAM starting at 30h.
(i) Use DPTR ii) Bank registers to point to External RAM locations.
3) Write an ALP to move a block of 10 data bytes, stored in external RAM
starting at location 8050h to locations starting at 8055h.
4) Write an ALP to Reverse a block of 10 data bytes, stored in internal RAM
starting at location 10h
5) Write an ALP to exchange 10 data bytes, stored in internal RAM starting
at location 20h with data bytes, stored in internal RAM locations starting at
35h.
6) Write an ALP to exchange 10 data bytes, stored in internal RAM starting
at location 20h with data bytes, stored in external RAM locations starting at
35h
7) Write an ALP to exchange 10 data bytes, stored in internal RAM starting
at location 20h with data bytes, stored in external RAM locations starting at
8035h
8) Write an ALP to exchange 10 data bytes, stored in external RAM
starting at location 8020h with data bytes, stored in external RAM locations
starting at 8035h
ORG 0000H
SJMP 30H
ORG 30H
MOV R0,#05 //count n-1 -ARRAY SIZE-n- Pass Counter
L1: MOV dptr, #9000h //array stored from address 9000h
MOV A,R0 //initialize exchange counter
MOV R1,A
L2: MOVX a, @dptr //GET NUMBER FROM ARRAY
MOV B, A //& STORE IN B
INC dptr
MOVX a, @dptr //next number in the array
CLR C //reset borrow flag
MOV R2, A //STORE IN R2
SUBB A, B //2nd - 1st no.—no compare instruction in 8051
JC NOEXCHG // JNC - FOR ASCENDING ORDER
MOV A,B //EXHANGE THE 2 NOES IN THE ARRAY
MOVX @dptr,a
DEC DPL //DEC dptr-INSTRUCTION NOT PTRESENT
MOV a,R2
MOVX @dptr,a
INC DPTR
NOEXCHG: DJNZ R1,L2 //decrement compare counter
DJNZ R0,L1 //decrement pass counter
here: SJMP here
END
Algorithm
1. Store the elements of the array from the address 9000h
2. Initialize a pass counter with array size-1 count (for number of
passes).
3. Load compare counter with pass counter contents & initialize DPTR
to point to the start address of the array (here 9000h).
4. Store the current and the next array elements pointed by DPTR in
registers B and r2 respectively.
5. Subtract the next element from the current element.
6. If the carry flag is set (for ascending order) then exchange the 2
numbers in the array.
7. Decrement the compare counter and repeat through step 4 until the
counter becomes 0.
8. Decrement the pass counter and repeat through step 3 until the
counter becomes 0.
RESULT:
Before Execution:Unsorted Array at 9000h
RESULT:
Before Execution:
2. ARITHMETIC INSTRUCTIONS
ASSEMBLY LANGUAGE PROGRAM ILLUSTRATING ADDITION,
SUBTRACTION, MULTIPLICATION AND DIVISION .
5) Write an ALP to perform the following:
If x=0-perform w + v; else if x=1-perform w-v; else if x=2-perform w*v; elseif
x=3-perform w/v, where w & v are eight bit numbers.
ORG 0000H
SJMP 30H
ORG 30H
MOV R0, #40H
MOVX A,@R0
MOV R1, A //R1 HAS CONDITION X
INC R0
MOVX A,@R0
MOV B, A //B HAS 1ST NUMBER-v
INC R0
MOVX A,@R0 //A HAS 2ND NUMBER-w
CJNE R1,#00,CKSUB
ADD A,B //PERFORM ADDITION
MOV B,#00 //B HAS CARRY
JNC SKIP
MOV B,#01H
SKIP:SJMP LAST
CKSUB: CJNE R1,#01,CKMUL
CLR C //RESET BORROW FLAG
SUBB A,B
MOV B,#00 //B INDICATES BORROW
JNC SKIP1
MOV B,#0FFH //FF INDICATES NEGATIVE NUMBER
SKIP1:SJMP LAST
CKMUL: CJNE R1,#02,CKDIV
MUL AB //16 bit product in AB with A having lower
byte
SJMP LAST
CKDIV: CJNE R1,#03,OTHER
DIV AB //Quotient in A & remainder in B
SJMP LAST
OTHER:MOV A,#00
MOV B,#00
LAST: INC R0
MOVX @R0,A
INC R0
MOV A,B
MOVX @R0,A
HERE:SJMP HERE
END
Algorithm
1. Store the condition x in r1.
2. Load the first and second numbers to A and B registers respectively
3. Compare the contents of r1 and perform the operations add, sub, etc
accordingly.
4. Store the result present in A and B registers to the appropriate
memory locations.
To get square make the D1 bit of data memory 20h high, say FF,02,06,etc.
The bit address is 01. Similarly bit address 78h correspond to D0 bit 0f data
ram location 2Fh.
Algorithm
1. Store the eight bit number x in A, r0 & B registers.
2. Multiply A and B registers to obtain the square (say SQH:SQL) of
the number x.
3. Check if bit 01 is set. If set go to end (storing the result), else do the
cube operations.
4. The high part of the square result (SQH) is stored on the stack.
5. Multiply the low part of the square result (SQL) with x (partial cube
result).
6. Store the low part of the above result at 9001h & the high part in R2.
7. Retrieve the high part of the square result (SQH) stored on the stack
& multiply with x.
8. Add the low part of the above result (SQH*X) with R2 and store in
9002h.
9. Add the high part (SQH*X) with the resulting carry and store in 9003.
SJMP END1
BIG:SETB 7FH
SJMP END1
EQUAL:CLR 77H
CLR 7FH
END1:SJMP END1
END
Algorithm:
1. Store the elements of the array from the address 4000h
2. Move the first number in r0 and the second number in register A
respectively
3. Clear carry flag and subtract the two numbers, if the carry flag is 0(if
the nos are equal), Clear both LSB & MSB of bit addressable memory
location 2Fh
4. If the carry bit is set then Set MSB of 2F(7FH), else LSB of data RAM
2F (bit address 78H).
4. LOGICAL INSTRUCTIONS
8) ASSEMBLY PROGRAM ILLUSTRATING LOGICAL INSTRUCTIONS
(BYTE LEVEL)
3 eight bit numbers X, NUM1 & NUM2 are stored in internal data RAM
locations 20h, 21h & 22H respectively. Write an ALP to compute the
following.
IF X=0; THEN NUM1 (AND) NUM2, IF X=1; THEN NUM1 (OR) NUM2,
IF X=2; THEN NUM1 (XOR) NUM2, ELSE RES =00, RES IS 23H
LOCATION
ORG 0000H
SJMP 30H
ORG 30H
MOV A, 20h //donot use #, as data ram 20h is to be accessed
MOV R1,A //X IN R1
MOV A,21H //A -NUM1
CJNE R1,#0,CKOR
ANL A, 22H
SJMP END1
CKOR:CJNE R1,#01,CKXOR
ORL A, 22H
SJMP END1
CKXOR:CJNE R1,#02,OTHER
XRL A, 22H
SJMP END1
OTHER: CLR A
END1: MOV 23H,A //STORE RESULT
Algorithm:
1. Point to the data RAM register 20h and store the condition x.
2. Point to 21h and 22h and move the first number to A register.
3. Compare the contents of r1 and perform the operations accordingly.
4. The result will be stored in 23H register.
RESULT: 1)Before Execution: D:020H =00, 21=0f, 22 = 12
After Execution D:023H = 02
2)Before Execution: D:020H =01, 21=0f, 22 = 12
After Execution D:023H = 1F
3)Before Execution: D:020H =02, 21=0f, 22 = 12
After Execution D:023H = 1D
4)Before Execution: D:020H =34, 21=0f, 22 = 12
After Execution D:023H = 00
The above program can also be written as shown below (using indirect
addressing)
ORG 0000H
SJMP 30H
ORG 30H
mov r0,#20h
MOV A,@R0 //ON CHIP DATA RAM-DONOT USE
MOVX
MOV R1,A //X IN R1
INC R0
MOV A,@R0 //A -NUM1
INC R0 // R0 POINTS TO NUM2
CJNE R1,#0,CKOR
ANL A, @R0
SJMP END1
CKOR:CJNE R1,#01,CKXOR
ORL A, @R0
SJMP END1
CKXOR:CJNE R1,#02,OTHER
XRL A, @R0
SJMP END1
OTHER: CLR A
END1:INC R0
MOV @R0,A //STORE RESULT
HERE:SJMP HERE
END
Boolean variable instructions are also called as bit level logical
instructions
9) 3 eight bit numbers X, NUM1 & NUM2 are stored in internal data RAM
locations 20h, 21h & 22H respectively. Write an ALP to compute the
following.
IF X=0; THEN LSB OF NUM1 (AND) LSB OF NUM2,
IF X=1; THEN MSB OF NUM1 (OR)MSB OF NUM2 ,
IF X=2; THEN COMPLEMENT MSB OF NUM1
Algorithm:
1. Move the condition X (from 20h location) into R0 register.
2. If X=0; then move LSB bit of 21h to carry flag and ‘AND’ Carry flag
with LSB bit of 22h. Goto step5
3. If X=1; then move MSB bit of 21h to carry flag and ‘OR’ Carry flag
with MSB bit of 22h. Goto step5
4. If X=0; then complement MSB bit of 21h and move it to carry flag.
Goto step5
5. Store Carry flag at MSB bit of 23h location.
5. COUNTERS
ASSEMBLY PROGRAM ILLUSTRATING HEX UP/DOWN COUNTERS.
//counter program - hex/binary counters
10) Write an ALP to implement (display) an eight bit up/down binary (hex)
counters on watch window.
Note: to run this program, after selecting DEBUG session in the main menu
use
View-> Watch& call Stack window, in the Watches select watch
1(or 2) and
press F2 and enter a (for accumulator A)
ORG 0H
SJMP 30H
ORG 0H
MOV a,#00
BACK: ACALL DELAY
INC a //dec a for binary down counter
JNZ BACK
HERE:SJMP HERE
Algorithm:
1. Move 00 to A register
2. Call the delay subroutine for 1 second, in delay program move FFH to
registers r1, r2 and r3, loop and decrement until 0.
3. Increment A register(decremant for down counter)
ORG 30H
MOV TMOD,#20H //timer 1; mode 2
MOV TH1,#-3 //-3=FD loaded into TH1 for 9600 baud,
11.0592MHz.
MOV SCON,#50H //8-bit, 1 stop bit, REN enabled
SETB TR1 //Start timer 1
AGAIN:MOV A,#’y’ //transfer “y”
ACALL TRANS
MOV a,#’E’ //transfer “E”
ACALL TRANS
AGAIN1:SJMP AGAIN1
TRANS: MOV SBUF,a //load SBUF
HERE:JNB TI,HERE //Wait for last bit to transfer
CLR TI //get ready for next byte
RET
END
Algorithm:
1. Set up timer0 in mode 2 operation
2. Load TH1 with 118 to generate an interrupt every 0.05msec.
3. Reset registers a, r1 & r0.
4. Repeat step 4 continuously
5. On interrupt; ISR at 000B loaction goes to step 6
6. disable timer0
7. Update r1 & r0
8. Check if 20000 interrupts (=1 sec) over. Yes –increment accumulator a.
9. enable timer & return from ISR.
Timerdelay = 12*(257-delay)/frequency
Timerdelay=0.05msec
Delay=256-((timerdelay * frequency)/12) =256-(0.05*10 -3 * 33*106)/12
=256-137.5 =118.5 //loaded in TH0
To get 1sec delay
1/0.05msec = 200*100 in the ISR
(assuming 33 MHZ crystal frequency. For 11 MHz, the calculations change).
8. CONVERSION PROGRAMS
ORG 0000H
SJMP 30h
ORG 30h
MOV DPTR,#40H //2-digit decimal number to be converted is given
in data memory 40h
MOVX A, @DPTR
ANL A, #0F0H //obtain upper decimal digit
SWAP A //bring to the units place
MOV B,#0AH //MULTIPLY tens digit with #0A-toget tens
in hex
MUL AB
MOV r1,a //temporarily store the converted tens
value
MOVX A,@DPTR //get the decimal number again
ANL A,#0FH //obtain the units digit
ADD A,R1 //add to the converted tens value
INC DPTR //increment data address
MOVX @DPTR,A //converted hexadecimal number in next
location
HERE:SJMP HERE
END
Algorithm
1. Move the decimal data to be converted from external memory 40h to
accumulator.
2. AND A reg with 0f0h and obtain the upper MSB of the decimal digit
and swap the LSB and MSB of accumulator to bring the same to units
place.
3. Move 0ah to B register and multiply with A reg to convert to hex
value, store the converted tens value in r1
4. Get the LSB of the decimal number and add to the converted tens
value
5. point to the next memory location and store the result (hexadecimal).
INC DPTR
XCH A,B
MOVX @DPTR,A //Store the remainder (in B) In units place
XCH A,B
MOV B,#10 //Divide the quotient in A by 10
DIV AB
INC DPTR
XCH A,B
MOVX @DPTR,A //Store the remainder (in B) In tens place
XCH A,B
INC DPTR
MOVX @DPTR,A //Store the quotient (in A) in hundreds place
HERE:SJMP HERE
End
Algorithm
1. Move the hex data to be converted to accumulator.
2. Move 10 to B register and divide with A reg to convert to ascii value
3. Store the converted LSB value in r7
4. Repeat the step 2 to obtain the converted MSB value
5. Store the same in r6
Algorithm :
//Converts the BCD byte in A into two ASCII characters.
1. Move the BCD data to be converted to accumulator.
2. Get the lower nibble(BCD digit) & ADD (or ORL) with 30h
3. Store the converted ASCII value
4. Get the higher nibble(tens BCD digit) & ADD (or ORL) with 30h
5. Store the converted ASCII value
Algorithm :
//Converts the hexadecimal byte in A into two ASCII characters.
1. Move the hexadecimal data to be converted to accumulator.
2. Get the lower nibble & call ASCII routine
3. Store the converted ASCII value
4. Get the higher nibble & call ASCII routine
5. Store the converted ASCII value
ASCII subroutine
1. If digit greater than 09,(for A-F) add 07h & 30h
2. Else (i.e., for 0-9) add only 30h
3. return
Note: For this program the input data should be only in the range 30h-39h &
41h to 46h.
Algorithm :
Hardware Interfacing
Features of Embedded C
• C is a simple programming language and so very easy to code.
• Embedded C has most features of C-language with more stress on certain bit
manipulative instructions.
• This feature makes it easy to write program for μC and μP.
• Keil is a versatile software with a cross compiler that will convert the C
program to assembly language and thus the program can be executed on the
desired target (say 8051).
a.Square waveform
b.Triangular Waveform
c.Ramp waveform
d.Sine waveform
8
0 CRO
5 P0 Dual Xout
1 P1 DAC
μC
Let initial, amplitude of the square wave be 2.5v(7F) and frequency count
100.
Output the values 00h(0ff) and 7fh(on) Values through P0.
If amplitude key is pressed then increase the voltage in steps of 0.15v(8).
If the frequency key is pressed increment the count in steps of 50. If the
count exceeds 1000 reset it back to 100.
Every time amplitude and frequency changes output the value thro P0 and
note the waveform on CRO.
#include <REG51xD2.H>
sbit Amp = P3^3; /* Port line to change amplitude */
sbit Fre = P3^2; /* Port line to change frequency */
void delay(unsigned int x) /* delay routine */
{
for(;x>0;x--);
}
main()
{
unsigned char on = 0x7f,off=0x00;
unsigned int fre = 100;
while(1)
{
if(!Amp) /* if user choice is to change amplitude */
{
while(!Amp); /* wait for key release */
on+=0x08; /* Increase the amplitude */
}
if(!Fre) /* if user choice is to change frequency */
{
if(fre > 1000) /* if frequency exceeds 1000 reset to default */
fre = 100;
#include <REG51xD2.H>
main()
{
unsigned char i=0;
P0 = 0x00; /* P0 as Output port */
while(1)
{
for(i=0;i<0xff;i++){ /* Generate ON pulse */
P1 = i;
P0 = i;
}
for(i=0xfe;i>0x00;i--) /* Generate OFF pulse */
{P0 = i;
P1 = i;}
}
}
#include <REG51xD2.H>
main ()
#include <REG51xD2.H>
main()
{
static int a[13]={128,192,238,255,238,192,128,64,17,0,17,64,128};
unsigned char i=0;
P0 = 0x00; /* P0 as Output port */
while (1)
{
for(i=0;i<13;i++) /* Output different values */
{ P0 = a[i]; }
}
}
2.Stepper Motor
• Configure P0 as output.
• Apply the initial excitation of 11 to motor coils through P0.
• For clockwise motion -Rotate right once the excitation and repeat step 2.
• For anticlockwise motion -Rotate left once the excitation and repeat step 2.
PS
PS
8051µC
P0 Stepper
FRC 26pin Motor Stepper
Cable Interface Motor
Card
#include <REG51xD2.H>
void delay (unsigned int x) /* Delay Routine */
{
for(;x>0;x--);
return;
}
Main ( )
{
unsigned char Val, i;
P0=0x00;
Val = 0x11;
for (i=0;i<4;i++)
{
P0 = Val;
Val = Val<<1; /* Val= Val>>1; for clockwise direction*/
delay (500);
}
}
• Configure P1 as output port to scan the rows and P0 as input port to read the
column values.
• First select the last row by grounding that row. Scan the columns of entire
row if a key is pressed in that row then one of the column reads ‘0’.
• If now key is pressed in the selected row all 1’s is returned. So scan next
row. Repeat the action until all rows are scanned.
PS
PS
8051µC
P0 4X4
FRC 26pin Keyboard 4X4 Hex
Cable Interface keypad
Card
if(CY)
else
{
result -= 0x04;
rows --;
if(rows == 0)
goto again;
else
{
goto next;
}
}
}
void main()
{
P0 = 0xff;
P1 = 0x00;
InitLcd();
WriteString ("KEY PRESSED=");
while(1)
{
KeyScan();
WriteString ("KEY PRESSED=");
Display();
}
}
4.DC Motor
PS
PS
8051µC
P0
FRC 26pin DC Motor
DC
Cable Interface
Motor
P3.2(inr) Card
P3.3(dec)
#include <REG51xD2.H>
sbit inr= P3^2; //speed increment switch
sbit dcr= P3^3; //speed decrement switch
main()
{
unsigned char i=0x80;
P0 = 0x7f; /*Run the motor at half speed.*/
while (1)
{ if (!inr)
{while (!inr);
if(i>10)
i=i-10; //increase the DC motor speed
}
if(!dcr)
{
while(!dcr);
if(i<0xf0)
i=i+10; //decrease the DC motor speed
}
P0=i;
} }
• Read the numbers n1 and n2 from keyboard and display them on seven
segment.
• Read the operand from the keypad if key pressed is B (+), C(-),D(*),E(/) then
respective operation is performed.
• Result is displayed on 2 digit seven segment display.
• If any time the key pressed value returned as 10h then clear the LCD.
PS
PS
8051µC
Keypad
P0
FRC 26pin
Cable
7 Seg
Display
#include <REG51xD2.H>
void DispChar(unsigned char ch);
void ClrLED();
unsigned char getkey();
unsigned char getnum();
unsigned char getOp();
sbit Clk = P3^4; /* Clock line for 7 segment display */
sbit Dat = P0^0; /* Data line for 7 segment display */
main()
{
unsigned char tmp=0x0ff,n1=0,n2,Op,Res;
unsigned char NumTab[10] = {
0x0c0,0x0f9,0x0a4,0xb0,0x99,0x92,0x82,0x0f8,0x80
,0x90 };
unsigned char OpTab[4] = { 0x88,0x0Bf,0xc8,0x0a1};
bit Neg=0;
ClrLED(); /* Clear 7 segment display */
while(1)
{
Neg = 0; /* Negative flag */
n1=getnum(); /* Get 1st number */
Neg = 1;
Res = n2 - n1;
break; }
Res = n1 - n2;
break;
case 2: Res = n1 * n2;
break;
case 3: Res = n1 / n2;
break; }
DispChar(NumTab[Res%10]); /* Display number */
DispChar(NumTab[Res/10]);
if(Neg) /* if negative result display '-' */
DispChar(0x0Bf);
}}
void DispChar(unsigned char ch) /* Routine to display char on 7
segment */
{
unsigned char i,tmp;
P0=0x00;
for(i=0;i<8;i++) /* for all bits */
{
tmp = ch & 0x80;
if(tmp) /* write data depending on MSB */
Dat = 1;
else
Dat = 0;
Clk = 0; /* Give Clk Pulse for synchronization */
Clk = 1;
ch = ch << 1; /* Get next bit */
}
}
void ClrLED()
{
unsigned char i;
for(i=0;i<4;i++)
DispChar(0x0ff); /* 0xff for clear segment ( see 7 segment manual for more
info) */
}
unsigned char getkey()
{ unsigned char i,j,indx,t;
6.Elevator
• If the current floor and requested floor are the same no change light up the
corresponding LED through P0.
• If the requested floor greaterthan current moving up of the lift is indicated
by glowing of LED’s from current floor to the requested.
• If the requested floor lesserthan current moving down of the lift is indicated
by glowing of LED’s from current floor to the requested.
PS
PS
8051µC
P0
FRC 26pin Elevator
Cable interface
#include <REG51F.H>
void delay(unsigned int);
main()
{
unsigned char Flr[9] = {0xff,0x00,0x03,0xff,0x06,0xff,0xff,0xff,0x09};
unsigned char FClr[9] = {0xff,0x0E0,0x0D3,0xff,0x0B6,0xff,0xff,0xff,0x79};
unsigned char ReqFlr,CurFlr = 0x01,i,j;
P0 = 0x00;
P0 = 0x0f0;
while(1)
{
P1 = 0x0f;
ReqFlr = P1 | 0x0f0;
while(ReqFlr == 0x0ff)
ReqFlr = P1 | 0x0f0; /* Read Request Floor from P1 */
ReqFlr = ~ReqFlr;
if(CurFlr == ReqFlr) /* If Request floor is equal to Current
Floor */
{
P0 = FClr[CurFlr]; /* Clear Floor Indicator */
continue; } /* Go up to read again */
else if(CurFlr > ReqFlr) /* If Current floor is > request floor */
{
i = Flr[CurFlr] - Flr[ReqFlr]; /* Get the no of floors to travel
*/
j = Flr[CurFlr];
for(;i>0;i--) /*Move the indicator down */
{
delay(25000);
}}
else /* If Current floor is < request floor */
{
i = Flr[ReqFlr] - Flr[CurFlr]; /* Get the no of floors to travel */
j = Flr[CurFlr];
for(;i>0;i--) /* Move the indicator Up */
{
P0 = 0x0f0 | j;
j++;
delay(25000);
} }
CurFlr = ReqFlr; /* Update Current floor */
P0 = FClr[CurFlr]; /* Clear the indicator */
}
}
void delay(unsigned int x)
{
for(;x>0;x--);
}
7.Temperature Sensor
PS
PS
8051µC
Temp Heat
P0,P2,P3 Sensor Source
FRC 26pin Interface
Cable
The interface card has a DAC to convert the actual temperature to digital this is
compared with reference temperarture. Realay also a part of interface card will turn
on and off to indicate if the actual temperature is above or below reference.
#include <REG51xD2.H>
sbit Cmp_Out = P3^4; /*Input Bit for Comparator output*/
sbit Rel_Con = P0^0; /*Relay controller Bit i.e Heater Power supply control*/
/*1- Supply OFF, 0-Supply ON*/
#define Dac_Data P1 /*DAC input Data PORT i.e. P1*/
void delay()
{ int l;
for (l=0;l<=0x8;l++);
}
main()
{
unsigned char DacIp;
void delay(void);
Dac_Data =0x00; /*Move 00h to Dac input*/
P0=0x00; /*make P0 as output*/
while(1)
{
DacIp= 0xff; /*DAC input Data counter*/
do
{
DacIp++; /*Increment the DAC input Data*/
Dac_Data = DacIp; /*Move the DAC data to DAC*/
delay();
}while(Cmp_Out); /* Check comparator output for low */
if(DacIp > 0x20) /*Compare with the set value i.e.0x20*/
Rel_Con = 1;
else
Rel_Con = 0; /* Relay ON, Supply OFF */
}
}