Q1. Write a delay routine for 8051 to create a delay of approximately 1 ms.
Q2. Write a routine for 8051 to create a rectangular wave (on port 2, bit 1) of 66% duty cycle using the above delay routine.
1.
Algorithm for a delay program of 1mS in 8051 timer :
1. Assume the processor is clocked by a 12KHz crystal.
2. Then the timer clock input will me 12KHz/12 = 1KHz.
3. hence the time taken for the timer to make one increment = 1mS
1 program for delay of 1mS DELAY: MOV R6,#250D MOV R7,#250D LABEL1: DJNZ R6,LABEL1 LABEL2: DJNZ R7,LABEL2 RET
2 GENERATING A RECTANGULAR WAVE OF 1mS /*pulse of 1mS is created on pin p1.0*/ #include<reg51.h> sbit pin=P1^0; void timer_delay(); int i; void main() { TMOD=0X01; // MODE 1 OF TIMER O IS SELECTED while(1) { pin=0; timer_delay(); pin=1; timer_delay(); } } void timer_delay() { // time delay of 1mS using 12KHz crystal oscillator TL0=0Xdb; TH0=0Xff; TR0=1; while(!TF0); TF0=0; TR0=0; }
Get Answers For Free
Most questions answered within 1 hours.