Write an ALP to move n bits of data from memory location X to memory location Y with overlap. Write a program to convert a given binary no to BCD equivalent.
Write an ALP to move n bits of data from memory location X to memory location Y with overlap. Write a program to convert a given binary no to BCD equivalent.
Write an ALP to move n bits of data from memory location X to memory location Y with overlap. Write a program to convert a given binary no to BCD equivalent.
1 a) Write an ALP to move n bits of data from memory location
X to memory location Y b) Write an ALP to move n bits of data from memory location X to memory location Y with overlap c) Write an ALP to exchange n bits of data from memory location X to memory location Y: d) Write an ALP to exchange a block of data bytes between external memory location starting from 500h to internal memory location starting from 30h: 2 a) Write an ALP to add n bytes numbers: b)Write an ALP to add two multibyte numbers: c)Write an ALP to subtract 2 multibytes: d) Write an ALP to add n 2 digits BCD numbers e) Write an ALP to divide two bytes 3 a) Write a program to convert a given binary no to BCD equivalent b)Write an ALP to convert given packed BCD into binary equivalent 4 4a) Write an ALP to convert an ASCII number to hex equivalent 4b) Write an ALP to convert given packed BCD to ASCII 5 5a)Write an ALP for 4:1 mux 5B) Write an ALP to 2: 4 decoder 5C)Write an ALP to realize 8: 3 priority encoder 6 6a) Write an ALP to realize 8 bit binary Up Counter? 6b)Write an ALP to realize 8 bit binary Down Counter 6c) Write an ALP to realize 8 bit BCD Up Counter? 6d) Write an ALP to realize 8 bit BCD Down Counter? 7 Write a C program to interface LCD to 8051 8 Write a C program to interface a stepper motor to 8051 9 Write a C program to interface an seven segment display to 8051 10 Write a C program to interface a DC MOTOR to 8051 11 Write a C program to interface a DAC to 8051 12 Write a C program to interface an ADC to 8051 13 Write a C program to interface an elevator to 8051 14 Write a C program to interface hex keypad to 8051
1A) Write an ALP to move n bits of data from memory location X to memory location Y:
Algorithm: 1) initialize r0,r1 as pointers for source and destination memory. 2) initialize r2 as counter for no. of bytes in block. 3) move data from source location to accumulator. 4) move data from accumulator to destination location. 5) increment source and destination address. 6) decrement the counter value, repeat steps 3,4,5. 7) end the program. Program: src equ 30h ;src =30h dst equ 50h ;dst =50h cnt equ 05h ;cnt=5 mov r0,#src ` ;r0 pointer for source location mov r1,#dst ;r1 pointer for source location mov r2,#cnt ;r2 counter back: mov a,@r0 ; a ( r0) mov @r1,a ;(r0) a inc r0 ; (r0) (r0)+1 inc r1 ;(r1) (r1)+1 djnz r2,back ;(r2) (r2)-1 ;if r2!=0 then go to label back
1B) Write an ALP to move n bits of data from memory location X to memory location Y with overlap: Algorithm: 1)initialize r0,r1 as pointers pointing to the end of source and destination memory. 2) choose destination memory such that it overlaps with source memory. 3) initialize r2 as counter for no. of bytes in block. 4) move data from source location to accumulator.
5) move data from accumulator to destination location. 6) decrement source and destination address. 7) decrement the counter value, repeat steps 4,5,6. 8) end the program. Program: src equ 30h ;src =30h dst equ 33h ;dst =33h cnt equ 06h ;cnt=5 mov r0,#src +cnt-1 ` ;r0 pointer for source location mov r1,#dst +cnt-1 ;r1 pointer for source location mov r2,#cnt ;r2 counter back: mov a,@r0 ; a ( r0) mov @r1,a ;(r0) a dec r0 ; (r0) (r0)+1 dec r1 ;(r1) (r1)+1 djnz r2,back ;(r2) (r2)-1 if r2!=0 then go to back end ;end the program Before execution: 0X30h=11h 0X31h=22h 0X32h=33h 0X33h=44h 0X34h=55h 0X35h=66h
1C) Write an ALP to exchange n bits of data from memory location X to memory location Y: Algorithm: 1) initialize r0,r1 as pointers for source and destination memory. 2) initialize r2 as counter for no. of bytes in block. 3) exchange data between source location and accumulator. 4) exchange data between accumulator and destination location. 5) exchange data between source location and accumulator again. 6) increment source and destination address. 7) decrement the counter value, repeat steps 3,4,5. 8) end the program.
Program: src equ 30h ;src =30h dst equ 50h ;dst =50h cnt equ 05h ;cnt=5 mov r0,#src ` ;r0 pointer for source location mov r1,#dst ;r1 pointer for source location mov r2,#cnt ;r2 counter back: XCH a,@r0 ; a ( r0) XCH a,@r1 ;a (r1) XCH a,@r0 ; a ( r0) inc r0 ; (r0) (r0)+1 inc r1 ;(r1) (r1)+1 djnz r2,back ;(r2) (r2)-1 ;if r2!=0 then go to label back end ;end the program
1D) Write an ALP to exchange a block of data bytes between external memory location starting from 500h to internal memory location starting from 30h: Algorithm: 1) initialize r0 as pointer for internal memory. 2) initialize DPTR as pointer for external memory. 3) initialize r2 as counter for no. of bytes in block. 3) move data from external memory location to accumulator 4) exchange data between accumulator and internal memory. 5) ) move data from accumulator to external memory location 6) increment external and internal memory location. 7) decrement the counter value, repeat steps 3,4,5,6. 8) end the program. Program: ext equ 30h ;src =30h int equ 50h ;dst =500h
cnt equ 05h ;cnt=5 mov r0,#int ` ;r0 pointer for source location mov DPTR,#ext ;r1 pointer for source location mov r2,#cnt ;r2 counter back: mov a, @DPTR ; a ( DPTR) XCH a,@r0 ;a (r0) mov @DPTR ,a ; (DPTR) a inc r0 ; (r0) (r0)+1 inc DPTR ;(DPTR) (DPTR)+1 djnz r2,back ;(r2) (r2)-1 ;if r2!=0 then go to label back end ;end the program
1F) Write an ALP to move a string from code memory to data memory Algorithm: 1)store the code from memory location 0000h. 2)initialize r0 as pointer for data memory. 3)initialize DPTR as pointer for code memory. 4)initialize r2 as counter for no, of blocks. 5)move the contents from code memory to data memory. 6)increment code and data memory addresses. 7)decrement counter,repeat steps 5,6. 8)end the program.
inc r0 ;(r0)(r0)+1 inc DPTR ;(DPTR)(DPTR)+1 djnz r2,back ;(r2) (r2)-1 ;if r2!=0 then go to label back ORG 100h ;starts storing from 100h string: db HELLO ; end ;end of program
Algorithm: 1)Initialize source location and the location of the result. 2)mov r0 into source location and mov no of bytes into r2 3) use ADD instruction for adding n multibytes 4) mov result into desired location 5) account for the carry if it is generated 6) end the program.
Program:
src equ 30h ; src=30h cnt equ 05h ;cnt=05h res equ 50h ;res=50h mov r0,#30h ;r030h mov r1,#05h ;r105h clr a ;a=00h back: add a,@r0 ;aa+(r0) inc r0 ;r0r0+1 jnc next ;cy=0, jump to next inc r2 ;r2r2+1 next: djnz r1, back ;r1r1-10,back mov 51h,a ;51ha mov 50h,r2 ;50hr2 end ;end the program
Output: Before execution: After execution: d: 0X30h =10h d: 0x50h=02h 0X31h =A0h 0X 51h=f0h 0X32h =B0h 0X33h =C0h 0X34h =D0h
2b)Write an ALP to add two multibyte numbers: Algorithm: 1)Store location of 2 multibyte numbers in R0 and R1 such that the number denoting the location is pointing to the last byte 2)Store the no of bytes in a number in R2 3)add with carry the last two bytes 4)decrement R0 and R1 5)decrement R2 6)repeat steps 3,4 and 5 7) account for carry from the last byte. 8)end the program
Program: add1 equ 30h ; add1=30h
add2 equ 40h ;add2=40h cnt equ 04h ;cnt =04h mov r0,#add1+cnt-1 ;r033h mov r1,#add2+cnt-1 ;r143h mov r4,#cnt ;r4cnt clr c ;c=0 back:mov a,@r0 ;a(r0) addc a,@r1 ;aa+r1+c mov @r0,a ;(r0)a dec r0 ;r0r0+1 dec r1 ;r1r1+1 djnz r4,back ;r4 r4-10,jump back mov a,#00h ;a00h addc a,#00h ;aa+00+cy mov @r0,a ;(r0)a end ;end the program
1)Store location of 2 multibyte numbers in R0 and R1 such that the number denoting the location is pointing to the last byte 2)Store the no of bytes in a number in R2 3)subtract with borrow the last two bytes 4)decrement R0 and R1 5)decrement R2 6)repeat steps 3,4 and 5 7 )account for borrow from the last byte. 8)end the program
2d) Write an ALP to add n 2 digits packed BCD numbers Algorithm:
1)Initialize source location and the location of the result. 2)mov r0 into source location and mov no of bytes into r2 3) use ADD instruction for adding n multibytes 4) mov result into desired location 5) account for the carry if it is generated 6)use decimal adjust to get back BCD number 7) end the program
Program:
src equ 30h ; src=30h cnt equ 05h ;cnt=05h res equ 50h ;res=50h mov r0,#30h ;r030h mov r1,#05h ;r105h clr a ;a=00h back: add a,@r0 ;aa+(r0) inc r0 ;r0r0+1 jnc next ;cy=0, jump to next inc r2 ;r2r2+1 next: djnz r1, back ;r1r1-10,back mov 51h,a ;51ha mov a,r2 ;ar2 da a ;aa+66h,under certain conditions
mov r2,a ; r2a mov 50h,r2 ;50hr2 end ;end the program
Output: Before execution: After execution: d: 0X30h =10h d: 0x50h=01h 0X31h =20h 0X 51h=80h 0X32h =30h 0X33h =40h 0X34h =80h
2e) Write an ALP to divide two bytes: Algorithm: 1) Store the dividend and divisor in location pointed to by R0 and R1 respectively. 2) Move them to accumulator and reg B 3) Divide them using DIV instruction 4) Store quotient and remainder in desired locations 5) End the program Program: div1 equ 30h ;div1=30h div2 equ 40h ;div2=40h mov r0,#div1 ;r0div1 mov r1,#div2 ;r1div2 mov a,@r0 ;a(r0)
mov 0f0h,@r1 ;b(r1) div ab ;aa/b inc r1 ;r1r1+1 mov @r1,a ;(r1)a inc r1 ;r1r1+1 mov @r1,0f0h ;(r1)b end ;end the program
Output: Before execution: After Execution: D: 0X 30h= Fb h D: 0X 32h= Fb h 0X 40h= 05 h 0X33h=01h
3a) Write a program to convert a given no to BCD equivalent:
Algorithm: 1) Store the number in the location pointed to by r0 2) Divide the number by 100d 3) The quotient in A and remainder in B 4) Now divide remainder by 10d 5) Store the first quotient,second quotient and the remainder in increasing manner of memry location. 6) End the program
Program:
num equ 30h ; num=30h mov r0,#num ; r0 num mov a,@r0 ; a(r0) mov 0f0h,#100d ;b100d div ab ;aa/b, ba-(a*b) mov @r0,a ;(r0)a mov a,0f0h ;ab mov 0f0h,#10d ;b10d div ab ; aa/b, ba-(a*b) inc r0 ;r0r0+1 mov @r0,a ;(r0)a inc r0 ; r0r0+1 mov @r0,0f0h ;(r0)b end ;end the program
Output: Before Execution: After Execution: D:0X30h=FFh d:0X30h=02h 0X31h=05h 0X32h=05h
3b)Write an ALP to convert given packed BCD into binary equivalent:
Algorithm:
1)store the number in the location pointed to by ro 2)mask the lower bit of the number 3)swap the upper and lower nibble and store it in a memory location 4)mask the upper nibble 5)store it in the consecutive memory location 6)end the program
Program:
num equ 40h ;num =40h mov r0,#num ;r0 num mov a,@r0 ;a(r0) ANl a,#0f0h ;a(a.f0h) swap a ; mov 0f0h,#10d ;b10d mul ab ;a(a*b) mov r1,a ;r1a push 1 ;spsp+1, stack memr1 mov a,@r0 ;a(r0) ANL a,#0fh ;a(a.0fh) pop 1 ;spsp-1, r1stack mem ADD a,r1 ;aa+r1 mov @r0,a ;(r0)a end ;end the program
Output: Before Execution: After Execution: D:0X30h=45h d:0X30h=2Dh
4a) Write an ALP to convert an ASCII number into hex equivalent:
Algorithm: 1)check if the number is less than 39 or greater than 46, if yes set r2 2) check if number is between 30-39, if yes, then subtract 30 from it 3)if number is between 40-46, frst subtract 7 then subtract 30 4)store the result i n the required memory location 5)end the program
Program:
num equ 30h ; num =30h mov r0,#num ;r0 num mov a,@r0 ;a(r0) new: CJNE a,#30h,invalid ; a-30h0 then jump to invalid start: CJNE a,#39h,start1 ;a-39h0, jump to start1 start1: jnc start2 ;cy=0 jump to start2 SUBB a,#30h ;a a-30h
mov @r0,a ;(r0)a sjmp end2 ;jump to end2 start2: SUBB a,#07h ;a a-07h SUBB a,#30h ;a a-30h mov @r0,a ;(r0)a sjmp end2 ;jump to end 2 invalid: jc end1 ;cy=1 jump to end1 CJNE a, #46h,invalid2 ;a-46h0 then jump to invalid2 sjmp start ;jump to start invalid2:jnc end1 ;cy=0, jump to end1 sjmp start ;jump to start end1: mov a,#0ffh ;affh end2: end ;end the program
Output: Before Execution: After Execution: d: 0X 30h=43h d: 0X 30h=2Dh
4b) Write an ALP to convert given packed BCD to ASCII
Algorithm: 1) Store the number in the location pointed to by r0 2) Mask the lower bit, swap it and store it in the required memory location 3) Mask the upper bit and store it in the consecutive location
4) End the program
Program: num equ 30h ;num= 30h mov r0,#num ;r0 num mov a,@r0 ;a(r0) mov r1,a ;r1a push 1 ;spsp+1, stack memr1 ANL a,#0fh ;a(a.00001111b) mov @r0,a ;(r0)a pop 1 ;spsp-1, r1stack memory mov a,r1 ;ar1 ANL a,#0f0h ;a (a.11110000b) swap a ; dec r0 ;r0r0-1 mov @r0,a ;(r0)a end ;end the program
Output: Before Execution: After Execution: d: 0X 30h=43h d: 0X29h=04h 0X30h=05h
5a)Write an ALP for 4:1 mux
ALGORITHM: 1) configure P1 as input port 2) configure P1.7 and P1.6 be the two select lines ( say S1 and S0). 3) check if S1 is high, if yes branch to another location and check for S0. ( u have checked for 11 and 10 combination) 4) if no S1 is 0 then again check for S0. ( this time u have checked for 01 and 00) 5) end the program.
5B) Write an ALP to 2: 4 decoder ALGORITHM: 1) configure P1 as input port 2) check if P1.1 is set , if yes branch to another location check if P1.0 is set if yes , then make P2.3 high 3) similarly if P1.1 P1.0 = 1 0 set p2.2 and so on 4) end the program
PROGRAM mov a,#0ffh mov p1,a ; configure P1 as input port
5C)Write an ALP to realize 8: 3 priority encoder ALGORITHM: 1) configure P1 as input port 2) this is an active low encoder, priority increases from left to right 3) start checking ,from extreme right, if any bit is 0 4) if yes, then jump to the specified ( for that condition) location and send the corresponding number on P2
5) end the program
PROGRAM: mov a,#0ffh mov p1,a ; configure P1 as input port
back: clr p2.0 clr p2.1 clr p2.2 jnb p1.1,cno0 jnb p1.1,cno1 jnb p1.2,cno2 jnb p1.3,cno3 jnb p1.4,cno4 jnb p1.5,cno5 jnb p1.6,cno6 jnb p1.7,cno7 sjmp back cno0: mov a, #00h ; send 00 when P1.0 is low mov p2,a sjmp back cno1: mov a, #01h ; send 001 on P2 when P1.1 is low mov p2,a sjmp back
cno2: mov a, #02h ; send 010 on P2 when P1.2 is low mov p2,a sjmp back cno3: mov a, #03h ; send 011 on P2 when P1.3 is low mov p2,a sjmp back cno4: mov a, #01h ; send 100 on P2 when P1.4 is low mov p2,a sjmp back cno5: mov a, #01h ; send 101 on P2 when P1.5 is low mov p2,a sjmp back cno6: mov a, #01h ; send 110 on P2 when P1.6 is low mov p2,a sjmp back cno7: mov a, #01h ; send 111 on P2 when P1.7 is low mov p2,a sjmp back
6a) Write an ALP to realize 8 bit binary Up Counter? ALGORITHM 1. Clear register A. 2. Move the contents of reg.A to port 0. 3. Call delay. 4. Keep adding 1 to contents of reg.A 5. End the program.
PROGRAM Mov a,#00h ; a=00h Back: mov p0, a ; p0=a Acall delay Add a, #01h ; a=a+1 Delay: mov r1, #71h Back2: mov r2, #255h Back1: mov r3, #255h Back: djnz r3, back Delay Generation djnz r3, back djnz r3, back Ret OUTPUT:
a=01 02 03 04.FD FE FF.
6b)Write an ALP to realize 8 bit binary Down Counter ALGORITHM 1. Move value ffh to register A. 2. Move the contents of reg.A to port 0. 3. Call delay. 4. Keep subtracting 1 from contents of reg.A 5. End the program.
PROGRAM Mov a,#0ffh ; a=00h Back: mov p0, a ; p0=a Acall delay Subb a, #01h ; a=a+1 Delay: mov r1, #71h Back2: mov r2, #255h Back1: mov r3, #255h Back: djnz r3, back Delay Generation djnz r3, back djnz r3, back Ret a= FF FE FD.03 02 01.
6c) Write an ALP to realize 8 bit BCD Up Counter? ALGORITHM 1. Clear register A. 2. Move the contents of reg.A to port 0. 3. Call delay. 4. Keep adding 1 to contents of reg.A and Daa(decimal adjust after addition) 5. End the program.
PROGRAM Mov a,#00h ; a=00h Back: mov p0, a ; p0=a Acall delay Add a, #01h ; a=a+1 Da a Sjmp back Delay: mov r1, #71h Back2: mov r2, #255h Back1: mov r3, #255h Back: djnz r3, back Delay Generation djnz r3, back djnz r3, back
Ret OUTPUT: a=00 0198 99
6d) Write an ALP to realize 8 bit BCD Down Counter? ALGORITHM 1. Clear register A. 2. Move the contents of reg.A to port 0. 3. Call delay. 4.Add 99 to contents of reg.A 5. End the program.
PROGRAM Mov a,#00h ; a=00h Back: mov p0, a ; p0=a Acall delay Add a, #99h ; a=a+99 Da a Delay: mov r1, #71h Back2: mov r2, #255h Back1: mov r3, #255h Back: djnz r3, back Delay Generation djnz r3, back Djnz r3, back Ret
OUTPUT: a=99 98 ..02 01 00
7)Write a C program to interface an LCD to 8051 Algorithm: 1) Include header files <reg51Xd2.h> . This provides all the hardware information to the assembler. 2) Assign pins of LCD to p[ort pins 3) Write a function for delay. 4) Write two separate functions for writing data and command a) Every write instruction occurs after Enable undergoes a high to low transition b) Also include checking of busy pin. (as long as busy pin is high, we cannot do read or write operation). c) Take care that R/W and Rs are as specified for command and data. 5) Call the above functions as required. 6) End the program
Rs = 0 Select command register 1 Select data register
R/W = 0 Write on LCD 1 Read from LCD
E low to high Before every read from LCD High to low Before every write to LCD D7- Busy check pin. If high data cant be sent out
PROGRAM: # include <reg51Xd2.h>
void delay( unsigned int x) {
for ( i=0;i<x;i++) for ( j=0;j<2000;j++) } // function for delay
void lcdready( ) { busy=1; rs=0; rw=1; while(busy==1) { E=0; delay(1) E=1; // function for checking if LCD is busy } }
10) WRITE A C PROGRAM TO INTERFACE A STEPPER MOTOR to 8051 ALGORITHM: 1) a steeper motor is something which rotates in steps , depending on which coil is energized 2) if u energize coil A, the mean of north of rotor aligns itself with A 3) so energize coils sequentially to rotate motor 4) change the direction by reversing the sequence of energizing coils as shown in table. 5) change the speed by varying the time delay i.e., the amount of time the rotor is supposed to wait in one position. 6) observe speed and direction changes.
anti -clockwise rotation Left shift by 1; clockwise rotation right shift by 1 0 0 0 1 0 0 1 0 0 1 0 0
1 0 0 0
PROGRAM: #include<reg51Xd2.h> sbit dir=P3^2; sbit speed=P3^3; void delay(unsigned int x) { for( ;x>0;x--); } // function of delay void main() { unsigned char val, i; unsigned int cnt=500; while(1) { if (dir==0) {val =0X08; for(i=0;i<4;i++) { P0=val; val=val>>1; // for clockwise rotation delay(cnt); } 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
WRITE A C PROGRAM TO INTERFACE a seven segment display to 8051 ALGORITHM: 1) store the data u need displayed in a character array. 2) since we are using shift registers, on every clock pulse data keeps shifting left. 3) each character is a 8 bits, therefore after 8 clock pulses the first data will be displayed on the first led 4) repeat this process 4 times. 5) observe the output on the seven segment display.
PROGRAM #include<reg51Xd2.h> sbit dataout=P1^0; sbit clock = P2^0; void delay( unsigned int i) { unsigned int i; for(;i>0;i--); // delay function } main() { unsigned char regcode[4]={0x88,0x091,0x00,0x88}; // character array unsigned char a,b,c; for (a=0;a<4;a++) // repeat for all 4 values in regcode array {
c = regcode[a]; for(b=0;b<8;b++) { c=c<<1; dataout = CY; // displaying on 1 led clock=0; clock=1; delay(2); clock=0; } } }
WRITE A C PROGRAM TO INTERFACE A DC MOTOR: ALGORITHM: 1) dc motor once energized keeps rotating (unlike stepper, we dont have to energize coils for each rotation) 2) we can, therefore, only increases or decrease speed. 3) his can be done by decrementing the value we are sending on port ** 4) observe the speed variations
**
speed of the dc motor is controlled using a PWM pulse. the duration for which pulse is high determines the speed ( i.e., if pulse is high for a longer duration speed is more) this can be done by decreasing the reference value of the comparator ( i.e., by reducing the value of i( in our case)) Vref = 80 Vref 80 Vref = 80
Vref 80
PROGRAM: #include <reg51Xd2.h> sbit inc =P3^2; sbit dec = P3^3; main ( ) { unsigned char i = 0X80; while(1); P0=i; if (inc ==0) { while (inc==0);
if(i>0X10) i=i-10; } // increase speed
if (dec ==0) { while (dec==0); if(i<0XF0) i=i+10; } } // decrease speed
WRITE A C PROGRAM TO INTERFACE A DAC: ALGORITHM: FREQUENCY VARIATIONS 1) this can be done by increasing or decreasing the parameter , we pass to the delay function
AMPLITUDE VARIATIONS 1) DAC 0808, the value of FF corresponds to 5V 2) therefore choose a value say 7F , so we can include the option of increasing amplitude 3) wait fir the amplitude key to be pressed and released. After that increment your amplitude variable by some value 4) once it goes out of range , bring it back to its original value of 7F
} write a C program to interface an ADC: ALGORITHM: 1) Analog to digital conversion is done by the IC and the digital data is available at pin D0-D7 of IC at the end of process below
CS
SOC
INTR
RD
1) conversion starts when SOC goes low to high 2) process completes when INTR goes low 3) when RD goes high to low , process completes 4) data is available on PORT pins 2) write a function to display the received bits from ADC to LCD 3) observe the output
PROGRAM # include <reg51Xd2.h> #include <lcd.h> sbit SOC = P0^5
Write a C program to interface hex keypad to 8051 #include <reg51Xd2.h> #include <lcd.h> unsigned char row, col, code , count void delay() { Unsigned int x; for (x=0;x<2000;x++) //delay for 2000 counts } void display() { If (code>0X09) Code=code+37; //from A onwards do decimal addition Write Char(code); } void keyscan() { Repeat Row=0X77; Count=0X04;
Code=0X0C; next: P1=row; Row=row>>1; //right shift by 1 Col=P0; //read columns col=col & 0X0f //masking p0.7 to p0.4 if(col!=0X0F) //when no key is pressed { col=col>>1; if(!cy) { ClrLcd (); //clear lcd in lcd.h return; } else { code=code+1; goto rot; } } else { code=code-0X04; //decrement code by 4 count --; if(count==0) goto repeat;