Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer questions CLEARLY and LEGIBILITY !!!! NAME: TEST 2 MICROCONTROLLER

ID: 3837578 • Letter: P

Question

Please answer questions CLEARLY and LEGIBILITY !!!!
NAME: TEST 2 MICROCONTROLLERS SPRING 17 1. Using the 8051 Timers and Interrupts Requirements this lab is to control and program the Timers of the micro-controller in a given of sequence. The program read (PI) and outputs its initial status on port P1 is of incremented at a controlled rate and displayed on Display update takes place once at the end a sequence including Timero overflow followed by Timer Timero and l are programmed using interrupt, status of and TF1 displayed on Port 3 bit your 3.1) respectively. You can use the Keil simulator to develop, check, and verify the operation of program. Steps First, configure and the required interrupt vectors for the Power Timero, and the Timerl i The Main program at code memory address 40H, while the Timer0 interrupt handler starts at code memory 100H and the Timer nterrupt handler starts at code memory 140H. The main program only function is reading P1 and displaying the value on P2. possible in the main program configure the two timers, Tim and Timerl, for Mode 1 with maximum initial delay time. Enable the Timer0 and Timerl start Timero, read port and display its value on P2.Continue updating port P2 and the status of TFo & on P3.1. 3) Third, write an interrupt service routine for Timer0 and for Timeri "TIMERIH". They start at code memory "TIME executes every time Timero or Timer1 overflows. address 100H and 140H. These routines The service routine for Timer0 clears T updates and displays the status of TF0 & TFI, and and Timer 1. The service routine for Timerl clears TF0, updates and displays the status of TFo & TF1, starts Timer0.

Explanation / Answer

I have developed the program for the MC8051 Timers which basically reads the Port (P1) and gives the initial status of Port (P2). I have added the comments for the each part of the code and the final output of it.

Let me explain you the way list of steps in a step-by-step manner:-

Step - 1:

I have included the main program which deals with the starting address at 40H.

Program:-


// The reg51.h is includes the 8051 micro contoller register file

#include <reg51.h>

// Declare the variable mcVar to the port P1   

mcVar pin = P1^0;

// This is the starting point of the program

main()
{
   // It will clear the respective port
P1 = 0x00;
  
// The timer TMOD will assign the 16 bit value     
     
TMOD = 0x09;   
loop:TL0 = 0xAF;
TH0 = 0x7B;   
pin = 1;   

// The timer will start now.
     
TR0 = 1;   
while(TF0 == 0) {}   
TL0 = 0xAF;
TH0 = 0x7B;
pin = 0;   
while(TF0 == 0) {}

// Continue with the loop iteration
  
goto loop;   
}

Step-2:

I have configured the two timers which is very well known for maximum delay time.

Program:-

// The reg51.h is includes the 8051 micro contoller register file

#include <reg51.h>

// Declare the variable mcVar to the port P1

mcVar clock = P1^0;

// It uses the interrupt function on the contollerTimer0 method

void contollerTimer0 (void) interrupt 1
{
clock=~clock;
TH0=0x7C;
TL0=0xHB;
}

// Created the main function as the starting point of program

void main (void)
{
TMOD=0X01;
TH0=0x7C;   
TL0=0xHB;
TR0=1;
IE=0X82;   
while(1);

}

Step-3:

Next step is to create a interrupt service routine for the Timer0H and Timer1H.

Program:-


// // The stdio.h is used for the standard input / output files
// The reg51.h is includes the 8051 micro contoller register file

#include<stdio.h>
#include<reg51.h>

// Created an char and int variable

unsigned char timerCount;
unsigned int timerVal;

// Written the main function as the starting point of program

void main()
{
P0=0x00;
TMOD=0x01;   
TH0=0x00;
TL0=0x00;
TCON=0x10;
IE=0x82;   
while(1);
}

// It uses the interrupt function on the Timer0 method

void Timer0(void)interrupt 1
{
timerVal++;
if(timerVal==38)   
{
P0=~P0;
timerVal=0;
}
}