Thursday, February 28, 2008

Timer Programming

PROGRAM NO.01

USING SOFTWARE POLLED TIMER APPROACH WRITE A PROGRAM WHICH BLINKS LED CONNECED AT BIT 0 OF PORT 1. LED SHOULD REMAIN ON FOR 500MS AND OFF FOR 500MS. USE TIMER 0 TO GENERATE BASIC 1MS DELAY.


ORG 0000H

MOV TMOD,#01H ; 65536-1000=64536(FC18H)
MOV TL0, #18H ;ASSUME 12MHZ CRYSTAL FREQUENCY
MOV TH0, #0FCH
SETB TR0

MOV DPTR,#000CH ;200H=512D
MAIN: JNB TF0, MAIN
MOV TL0, #18H
MOV TH0, #0FCH
CLR TF0

INC DPTR
MOV A, DPH
CJNE A, #02H, MAIN
CPL P1.0
MOV DPTR, #000CH
AJMP MAIN

END



PROGRAM NO.02

WRIE AN ALP IN 8051 MICROCONTROLLER TO GENERATE 5MS DELAY USING FOLLOWIN METHODS: (1) REGISTER PAIR (2) TIMER-1 IN MODE-1.




(1) USING TIMERIN MODE-1


ORG 0000H

MAIN:
MOV TMOD,#10H
ACALL DELAY

PASS: AJMP PASS

DELAY: MOV TL1, #78H ;5MS DELAY
MOV TH1, #0ECH ;TAKE F=12MHZ, 65536-5000=60536 (EC78H)
SETB TR1
L1: JNB TF1, L1
CLR TR1
RET


(2) USING REGISTER PAIR

ORG 0000H

MAIN:
MOV TMOD,#10H
ACALL DELAY

PASS: AJMP PASS

DELAY: ;MC =3+3R1+2R1R2
MOV R1, #0C8H ; R1=200, R2=11
L2: MOV R2, #0BH
L1: DJNZ R2, L1
DJNZ R1, L2
RET

END

PROGRAM NO.03

WRITE A PROGRAM TO USE TIMER 1 TO INTERRUPT THE PROGRAM AFTER A DELAY OF 2 MS. (CRYSTAL FREQUENCY = 10 MHZ).


ORG 0000H
AJMP MAIN ; 2000/1.2=1667,65536-1667=63869 (F97DH)

ORG 001BH
MOV A, #7EH
ADD A,TL1
MOV TL1,A ;MOV TL1,#7DH
MOV TH1, #0F9H
RETI

MAIN: MOV IE, #88H
MOV TMOD,#10H
MOV TL1, #7DH
MOV TH1, #0F9H
SETB TR1

TIMEPASS: LJMP TIMEPASS

END

PROGRAM NO.04

WRITE AN ASEMBLY LANGUAGE PROGRAM TO MEASURE AN UNKNOWN FREQUENCY CONNECTED ON PIN P3.4(T0). USE TIMER 0 IN COUNTER MODE.



ORG 0000H

MAIN: MOV TMOD,#05H ; TIMER-0 IN MODE-1 AS COUNTER
MOV TL0, #00H
MOV TH0, #00H
SETB TR0

ACALL DELAY ;5+3R3+3R3R4+2R3R4R5
CLR TR0
MOV R0,TL0
MOV R1,TH0

AJMP MAIN

DELAY: MOV R3, #32H
LOOP3: MOV R4, #64H
LOOP2: MOV R5, #64H
LOOP1: DJNZ R5, LOOP1
DJNZ R4, LOOP2
DJNZ R3, LOOP3
RET

END



PROGRAM NO.05

WRITE A PROGRAM WHICH CONTINUOUSLY READS FROM P0 AND SEND IT TO P1, WHILE SIMULTANEOUSLY CREATING SQUAREWAVE OF 5 KHZ ON PIN 2.1. USE TIMER 0 INTERRUPT SERVICE ROUTINE. INTIALIZE TIMER 0 IN MODE-2.



ORG 0000H
AJMP MAIN ;ASSUME 12MHZ CRYSTAL FREQUENCY
;1/5KHZ=0.2MS
; 256-100 =156 (9CH)

ORG 000BH
CPL P2.1
RETI

MAIN: MOV IE, #82H
MOV TMOD,#02H
MOV TH0, #9CH
SETB TR0

SEND: MOV P0, #0FFH
MOV A, P0
MOV P1, A
AJMP SEND

END

PROGRAM NO.06

WRITE AN ALP USING INTERRUPTS TO DO FOLLOWING TASK,(1) MAKE TIMER TO GENERATE A SQUAREWAVE OF 4KHZ FREQUNCY ON P2.0, (2) ASSUME THAT INT1 PIN IS CONNECTED TO A SWITCH THAT IS NORMALLY HIGH, WHWNEVER IT GOES LOW, IT SHOULD READ PORT P1, COMPLEMENT THE DATA AND SEND IT TO PORT P2.

ORG 0000H
AJMP MAIN

ORG 000BH
CPL P2.0
RETI

ORG 0013H
AJMP IN_EXT

MAIN: MOV IE, #86H
MOV IP, #04H
MOV TMOD,#0AH
MOV TH0, #83H ;ASSUME 12MHZ CRYSTAL FREQUENCY
SETB TR0 ;1/4KHZ=0.25MS, 125US HALF CYCLE PERID
; 256-125 =131 (83H)
PASS: AJMP PASS
IN_EXT: MOV P1, #0FFH
MOV A, P1
CPL A
MOV P2, A
RETI
END

No comments:

Custom Search
Custom Search