Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

NATIONAL INSTITUTE OF TECHNOLOGY, TIRUCHIRAPPALLI-620 015

DEPARTMENT OF INSTRUMENTATION AND CONTROL ENGINEERING

SUBJECT: IC615 EMBEDDED SYSTEMS

PROGRAMMING ASSIGNMENT – I

MOHAMED HUSSAIN K
410420002 – PhD I Yr ICE
1. A simple burglar alarm system has 4 zone inputs connected to an 8051 I/O port. If any
one of these inputs is activated a bell will sound for 15 seconds and the corresponding
zone LED, or LEDs, will be activated.
Solution:
Burglar alarm system hardware
Program flow chart

Program

The Program

int sensor=7; //The output of PIR sensor connected to pin 7

int push_switch=6; // push button switch connected to pin 6

int buzzer=8; // buzzer connected at pin 8

int sensor_value; //variable to hold read sensor value

void setup()

pinMode(sensor,INPUT); // configuring pin 7 as Input

pinMode(push_switch,INPUT); // configuring pin 6 as Input

pinMode(buzzer,OUTPUT); // configuring pin 8 as OUTPUT


}

void loop()

sensor_value=digitalRead(sensor); // Reading sensor value from


pin 7

if(sensor_value==HIGH) // Checking if PIR sensor sends a HIGH


signal to Arduino

digitalWrite(buzzer,HIGH); // Activating the buzzer

if(digitalRead(push_switch==HIGH))// Checking if pushbutton was


pressed

digitalWrite(buzzer,LOW); // turning OFF the buzzer

}}
2. A heating oven in a manufacturing process is to be maintained at a temperature level
between 50oC and 100oC. The controller device is to be based on an 8051
microcomputer. Two temperature sensor devices are fitted to the oven as follows:
(i) Sensor A outputs logic 0 if temperature exceeds 50oC
(ii) Sensor B outputs logic 0 if temperature falls below 100oC

Solution:
Interrupt operation example

The microcomputer’s program is written so that an interrupt from the low threshold
sensor will cause the heating element to turn on and interrupt from the high threshold
sensor will cause the heating element to turn off. Figure below shows a timing diagram
for the oven’s operation.
Temperature controlled heating oven

Timing diagram for the oven control

The resulting allocation of space in code memory for the OVEN program is
shown in figure
Code positioning in code memory space

Program for interrupt driven oven control


ORG 0000h ; entry address for 8051 RESET

LJMP MAIN ; MAIN starts beyond interrupt vector space

ORG 0003h ; vector address for interrupt 0

LJMP ISR0 ; jump to start of ISR0

ORG 0013h ; vector address for interrupt 1

LJMP ISR1 ; jump to start of ISR1

;=================================================================

; MAIN enables the interrupts and defines negative trigger operation.

; Heater is turned on and program just loops letting the ISRs do the work.

;=================================================================

ORG 0100h ; defines where MAIN starts..


MAIN:

MOV IE, #10000101B ; enable external interrupts IE0, IE1

SETB IT0 ; negative edge trigger for interrupt 0

SETB IT1 ; negative edge trigger for interrupt 1

; Initialise heater ON

SETB P1.0 ; heater is ON

LOOP:

LJMP LOOP ; loop around doing nothing!

;==================================================================

; ISR0 simply turns ON the heater

;==================================================================

ISR0:

SETB P1.0 ; turn ON heater

RETI ; return from interrupt

;==================================================================

; ISR1 simply turns OFF the heater

;==================================================================

ISR1:

CLR P1.0 ; turn OFF heater

RETI ; return from interrupt

END ; end of program


3. Write an 8051 C language program which will generate a 100 Hz square wave at an
output pin. The program is to use a 16 bit timer and is to be interrupt driven.
Solution:
Hardware circuit with timing diagram

Program
#include <reg51.h> // include 8051 register file
sbit pin = P1^0; // declare a variable type sbit
for P1.0
main()
{
P1 = 0x00; // clear port
TMOD = 0x09; // initialize timer 0 as 16 bit timer
loop:TL0 = 0xFF; // load value 56319 = DBFFh so after
TH0 = 0xDB; // 50000 counts timer 0 will be
overflow
pin = 1; // send high logic to P1.0
TR0 = 1; // start timer
while(TF0 == 0) {} // wait for first overflow for 50 ms
TL0 = 0xFF; // again reload count
TH0 = 0xDB;
pin = 0; // now send 0 to P1.0
while(TF0 == 0) {} // wait for 50 ms again
goto loop; // continue with the loop
}

4. Write an 8051 C language subroutine which will transmit an 8-bit data character via
the serial port.

Solution:

#include <reg51.h>
void main(void){
TMOD=0x20; //use Timer 1, mode 2
TH1=0xFA; //4800 baud rate
SCON=0x50;
TR1=1;
while (1) {
SBUF=‘A’; //place value in buffer
while (TI==0);
TI=0;
}
}
5. One conducting probe is fixed at the level B and another conducting probe is at level
A in the coal mine where the water is accumulating. The effects of the probes A and B
can be read through pin P3.1 and P3.4. Using the timer functions of 8-bit
microcontroller, measure the rate of rise of water level. If the measured rate of rise
water is larger than the threshold, then the system has to send the alarm to the operator
for any standby operations. Write the C program to instruct the 8-bit microcontroller
to measure the rate of rise in the water level in the coal mine.

Solution:
Program for Water rate level controller

#include<reg51.h>
sbit AA=P3^0;
sbit BB=P3^1;
sbit CC=P3^2;
sbit DD=P3^3;
sbit rs=P1^0;
sbit rw=P1^1;
sbit e=P1^2;
sbit MOTOR=P3^4;
void delay(int X)
{
int i,j;
for(i=0;i<X;i++)
for(j=0;j<1000;j++);
}
void write(int j)
{
rs=1;
rw=0;
P2=j;
e=1;
delay(10);
e=0;
return;
}
void cmd(int j)
{
P2=j;
rs=0;
rw=0;
e=1;
delay(10);
e=0;
return;
}
void puts(char *a)
{
unsigned int p=0;
for(;a[p]!=0;p++)
write(a[p]);
}
void lcd_init(void)
{
cmd(0x38);
delay(10);
cmd(0x0c);
delay(10);
cmd(0x01);
cmd(0x06);
cmd(0x80);
}
void main()
{
AA=BB=CC=DD=0;
while(1)
{
while(AA==0&&BB==0&&CC==0&&DD==0)
{
lcd_init();
puts(" TANK EMPTY ");
lcd_init();
puts(" MOTOR ON");
MOTOR=1;
}
while(AA==1&&BB==0&&CC==0&&DD==0)
{
lcd_init();
puts("WATER QUARTER");
}
while(AA==1&&BB==1&&CC==0&&DD==0)
{
lcd_init();
puts("WATER HALF");
}
while(AA==1&&BB==1&&CC==1&&DD==0)
{
lcd_init();
puts("WATER 3/4 FULL");
}
while(AA==1&&BB==1&&CC==1&&DD==1)
{
lcd_init();
puts(" TANK FULL ");
lcd_init();
puts(" MOTOR OFF ");
MOTOR=0;
}}}

You might also like