Embedded Assign I
Embedded Assign I
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
void setup()
void loop()
}}
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
The resulting allocation of space in code memory for the OVEN program is
shown in figure
Code positioning in code memory space
;=================================================================
; Heater is turned on and program just loops letting the ISRs do the work.
;=================================================================
; Initialise heater ON
LOOP:
;==================================================================
;==================================================================
ISR0:
;==================================================================
;==================================================================
ISR1:
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;
}}}