Professional Documents
Culture Documents
org 00h rpt: mov tmod,#15h setb p3.4 mov tl0,#00 mov th0,#00 setb tr0 mov r0,#28 again: mov tl1,#00h mov th1,#00h setb tr1 back: jnb tf1,back clr tf1 clr tr1 djnz r0,again mov a,tl0 mov P2,a mov a,th0 mov P1,a sjmp rpt end ;timer 1 as timer & timer 0 as counter ;make P3.4 as input port ;clear tl0 ;clear th0 ;start counter 0 ;R0 = 28, to time 1 second ;clear tl1 ;clear th1 ;start timer 1 ;test timer 1 flag ;clear timer 1 flag ;stop timer 1 ;repeat loop until R0 = 0 ;since 1 sec has elapsed, check TL0 ;move TL0 to P2 ;mov TH0 to Acc. ;move it to P1 ;repeat
//Digital Clock org 00h mov tmod,#01h mov P0,#00h mov P1,#00h mov P2,#00h clock: days: mov r0,#24 mov p0,#00h hours: mov r1,#60 mov p1,#00h minutes: mov r2,#60 mov p2,#00h seconds: acall delay inc P2 djnz r2,seconds inc P1 djnz r1,minutes inc P0 djnz r0,hours sjmp clock delay: j1: mov r5,#100 mov tl0,#0FFh mov th0,#0DBh setb tr0 ;call delay subroutine for 1 second ;increment P2 (seconds) ;decrement r2 & jump to 'seconds' if r2 is not zero ;increment P1 (minutes) ;decrement r1 & jump to 'minutes' if r1 is not zero ;increment P0 (hours) ;decrement r0 & jump to 'hours' if r0 is not zero ;repeat next day ;move 100 to r5 ;move 0FFh to tl0 ;move 0DBh to th0 ;start timer 0 ;set r2 for seconds ;set r1 for minutes ;set r0 for days ;select timer 0 in mode 1 ;set port 0 for hours ;set port 1 for minutes ;set port 2 for seconds
again:
jnb tf0,again clr tr0 clr tf0 djnz r5,j1 ret end
;jump if not bit to 'again' ;stop timer 0 ;clear tf0 flag ;decrement r5 & jump to 'j1' if r5 is not zero ;return
org 00h mov r1,#5 mov back: a,r1 ;load register r1 with value 5 ;copy contents of r1 to accumulator ;decrement r1 & jump to 'here' if r1 not zero ;short jump to 'next' ;move contents of r1 to register B ;multiply contents of A & B ;short jump to 'back' ;copy contents of accumulator to P1
here:
next:
ORG 00H MOV 40H,#8FH MOV 41H,#0E2H MOV A,41H ADD A,40H END ;copy data (8FH) to location 40H ;copy data (0E2H) to location 41H ;copy contents of 41H to Accumulator ;add the contents of location 40H to the contents of Accumulator
//Write a program to save any 6 hex values starting from 50H & find sum of these numbers by using loop.
ORG 00H MOV 40H,#20H ;copy data (i.e 20H) to RAM location 40H MOV 41H,#21H ;copy data (i.e 21H) to RAM location 41H MOV 42H,#22H ;copy data (i.e 22H) to RAM location 42H MOV 43H,#23H ;copy data (i.e 23H) to RAM location 43H MOV 44H,#24H ;copy data (i.e 24H) to RAM location 44H MOV 45H,#25H ;copy data (i.e 25H) to RAM location 45H MOV R3,#00H ;move data (i.e 00H) to R3 CLR C CLR A MOV R2,#6H ;clear carry ;clear accumulator ;move data (i.e 06H) to R2
MOV R1,#40H ;move data (i.e 40H) to R1 BACK: ADD A,@R1 JNC NEXT INC R3 NEXT: INC R1 ;add the contents of address in R1 to the contents of accumulator ;jump if not carry to lable 'NEXT' ;increment the contents of R3 by 1 ;increment the contents of R1 by 1
DJNZ R2,BACK ;decrement contents of R2 by 1 & jump to lable 'BACK' END ;end execution
//Write a program to save six 8-bit numbers in ROM & calculate the sum.
;shift origin to 100h ;store six 8-bit numbers in ROM locations starting from 100h ;shift origin to 00h ;copy data (i.e 06h) to R3 ;copy data (i.e 100h) to data pointer ;copy data (i.e 00h) to R2 ;copy data (i.e 00h) to R4 ;clear accumulator ;clear carry ;mov contents of address stored in data pointer to accumulator ;add contents of R4 to contents of accumulator ;jump if not carry to lable 'NEXT' ;increment contents of R2 by 1 ;increment contents of data pointer by 1 ;copy contents of accumulator to R4 ;decrement contents of R3 by 1 & jump to lable 'BACK' ;end execution
ORG 00H MOV R3,#06h MOV DPTR,#100H MOV R2,#00H MOV R4,#00H BACK: CLR A CLR C MOVC A,@A+DPTR
ADD A,R4 JNC NEXT INC R2 INC DPTR NEXT: MOV R4,A DJNZ R3,BACK END
MOV DPTR,#5743H MOV A,#27H MOV B,#78H ADD A,DPL MOV DPL,A MOV A,B ADDC A,DPH MOV DPH,A END
;MOVE DATA 5743H TO DPTR ;MOVE DATA 27H TO ACCUMULATOR ;MOVE DATA 78H TO REGISTER B ;ADD THE DATA IN DPL TO ACCUMULATOR ;MOVE THE CONTENTS OF ACCUMULATOR TO DPL ;MOVE THE COMTENTS OF ACCUMULATOR TO REGISTER B ;MOVE DPH TO ACCUMULATOR A ;MOVE CONTENTS OF ACCUMULATOR TO DPH
;shift origin to 100h ;store ten 8-bit numbers in ROM locations starting from 100h ;shift origin to 00h ;mov data (04h) in R3 ;mov data (00h) in R2 ;mov data (00h) in R1
ORG 00H MOV R3,#04H MOV R2,#00 MOV R1,#00 MOV DPTR,#100H CLR A CLR C MOVC A,@A+DPTR MOV R1,A INC DPTR CLR A MOVC A,@A+DPTR MOV R2,A BACK: INC DPTR CLR A MOVC A,@A+DPTR ADD A,R1 MOV R1,A INC DPTR CLR A
//Program to sort given numbers in ascending order ORG 00H MOV 40H,#44H MOV 41H,#55H MOV 42H,#10H MOV 43H,#36H MOV 44H,#05H MOV R1,#5 LOOP: MOV R2,#4 MOV R0,#40H BACK: MOV A,@R0 INC R0 MOV B,@R0 CJNE A,B,HERE SJMP NEXT HERE: JC NEXT MOV @R0,A DEC R0 MOV @R0,B INC R0 NEXT: DJNZ R2,BACK DJNZ R1,LOOP END ;set origing at 00h ;move data to location 40h ;move data to location 41h ;move data to location 42h ;move data to location 43h ;move data to location 44h ;move data (5) to R1 ;move data (4) to R2 ;move data (50h) to R0 ;move contents of address stored in R0 to A ;increment contents of R0 ;move contents of address stored in R0 to B ;compare & jump to label 'here' if not equal ;short jump to 'next' ;jump if carry to 'next' ;move contents of A to address stored in R0 ;decrement contents of R0 ;move contents of B to address stored in R0 ;increment contents of R0 ;decrement R2 & jump to 'back' if not zero ;decrement R1 & jump to 'loop' if not zero ;end execution
MOV DPTR,#5743H MOV A,#27H MOV B,#78H ADD A,DPL MOV DPL,A MOV A,B ADDC A,DPH MOV DPH,A END
;MOVE DATA 5743H TO DPTR ;MOVE DATA 27H TO ACCUMULATOR ;MOVE DATA 78H TO REGISTER B ;ADD THE DATA IN DPL TO ACCUMULATOR ;MOVE THE CONTENTS OF ACCUMULATOR TO DPL ;MOVE THE COMTENTS OF ACCUMULATOR TO REGISTER B ;MOVE DPH TO ACCUMULATOR A ;MOVE CONTENTS OF ACCUMULATOR TO DPH
//To add five 16-bit numbers stored in ROM ORG 100H ;shift origin to 100h DB 50H,0ABH,51H,0ACH,52H,0ADH,53H,0AEH,54H,0AFH numbers in ROM locations starting from 100h ORG 00H ;shift origin to 00h MOV R3,#04H ;mov data (04h) in R3 MOV R2,#00 ;mov data (00h) in R2 MOV R1,#00 ;mov data (00h) in R1 MOV DPTR,#100H ;mov data (100h) in data pointer CLR A ;clear accumulator CLR C ;clear carry MOVC A,@A+DPTR ;move contents of address stored in data pointer to accumulator MOV R1,A ;copy contents of accumulator to R1 INC DPTR ;increment contents of data pointer by 1 CLR A ;clear accumulator MOVC A,@A+DPTR ;move contents of address stored in data pointer to accumulator MOV R2,A ;copy contents of accumulator to R2 ;store ten 8-bit
BACK: INC DPTR ;increment contents of data pointer by 1 CLR A ;clear accumulator MOVC A,@A+DPTR ;move contents of address stored in data pointer to accumulator ADD A,R1 ;add contents of R1 into the contents of accumulator MOV R1,A ;copy contents of accumulator to R1 INC DPTR ;increment contents of data pointer by 1 CLR A ;clear accumulator MOVC A,@A+DPTR ;move contents of address stored in data pointer to accumulator ADDC A,R2 ;add with carry contents of R2 to contents of A MOV R2,A ;copy contents of accumulator to R2 DJNZ R3,BACK ;decrement contents of R3 by 1 END ;end execution
org 00h
BACK: mov p1,#0FFh ;move data 0FFh to port 1 acall delay mov p1,#00h acall delay sjmp back org 20h delay: mov r3,#6 loop: mov r4,#255 mov r5,#255 again: djnz r5,again ;call delay sub-routine ;move data 00h to port 1 ;call delay sub-routine ;short jump to 'back' ;set origin to 20h ;move data (6) to R3 ;move data (255) to R4 ;move data (255) to R5
;decrement R5 & jump to 'again' if not zero ;decrement R3 & jump to 'loop' if not zero ;return ;end execution
org 00h clr P1.3 mov tmod,#01h ;select timer 0 in mode 1 back: setb P1.3 acall delay clr P1.3 acall delay sjmp back delay: j1: mov r5,#100 ;set bit P1.3 ;call delay subroutine ;clear P1.3 ;call delay subroutine ;short jump to 'back' ;move 100 to r5 (to generate a delay of 1 second)
mov tl0,#0FFh ;move 0FFh to tl0 mov th0,#0DBh ;move 0DBh to th0 setb tr0 ;start timer 0 ;jump if not bit to 'again' ;stop timer 0 ;clear tf0 flag ;decrement r5 & jump to 'j1' if r5 is not zero
again:
//Program to generate square wave at P2.3 & P1.3 using timer interrupt
; - - main program org 0030h main: mov tmod,#22h mov ie,#8ah mov th0,#48h ;count value for 5 khz square wave mov th1,#96h ;count value for 10 khz square wave setb tr0 setb tr1 wait: sjmp wait end ;start timer 0 ;start timer 1 ;keep waiting for roll off of either timer