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

Design an 8051 assembly language program to implement a daily digital water mete

ID: 2080752 • Letter: D

Question

Design an 8051 assembly language program to implement a daily digital water meter display system. The purpose of the system is to tell a customer the amount of water (in litres) they have used within the current day. The system will also use three LEDs to indicate if their usage is excessive (red), average (amber) or below average (green).

The system will be calibrated for an average household with 2 adults and 2 children. The daily allowance of water for a household of this size is 350 litres. If the household water usage on a given day is:

                <300 litres, the system will turn on the green LED.

                300 and <350 litres, the amber LED will turn on.

                >350 litres, the red LED will turn on.

The digital water meter will deliver the water consumption to the 8051 via port 1 of the microcontroller as indicated in the diagram below. It is not necessary to implement timers, or calculate averages within the microcontroller itself – you may assume that this is taken care of within the software of the digital water meter. The output of the meter is 8 bit binary, and the resolution of the output is 10 litres (so e.g. if the usage for the day is 90 litres, the meter will output a value of 9; if the usage is 370 litres, the meter will output a value of 37 etc.).

Your system should display the daily usage in litres on four 7-segment displays. The first 3 of the seven segment displays (i.e. the thousands, hundreds and tens) will be directly controlled by the microcontroller to display the thousands, hundreds and tens of litres. The ‘units’ display will be set to zero (hard-wired to display the number zero all the time) and will not change, therefore it is not necessary to connect it to the microcontroller.

The system should start when powered on and run continuously until the power is switched off.

Your program should include the following:

1) Assembly language code to read the digital water meter

2) Assembly language code to display on the 7 segment display.

3) Assembly language code to determine whether the green, amber or red LEDs should be switched on.

4)Assembly language code to allow the main functions from part i, ii, and iii to integrate into a single working program that runs continuously.

Green P 3.4 4 P2.0 P 3.5 Amber Thousands 8051 Red P 3,6 P 2.3 Microcontroller P2.4 Hundreds P 2.7 Digital Water Meter 8 P 1.0 P 3.0 Tens P 1.7 P 3-3 Units Figure 1- Water Meter system architecture Water Usage (Litres)

Explanation / Answer


void main()
{

int i = 0;
int c = 16;
int b = 0;
CMCON = 0x07;
ADCON1 = 0x06;
TRISA = 0x0F;
PORTA = 0x00;
PORTD = 0x00;
PORTC = 0x00;
TRISB = 0x00;   
TRISC = 0x00;
TRISD = 0x80;

PORTD.F2 = 1;
PORTD.F7 = 1;

Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);   
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,txt1);   
Lcd_Out(2,1,txt2);   
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);   
Lcd_Out(1,1,txt3);   
Lcd_Out(2,1,txt4);   
Delay_ms(500);

// Moving text
for(i=0; i<15; i++)
{
Lcd_Cmd(_LCD_SHIFT_RIGHT);   
Delay_ms(125);
}

i=0; //Motor Status OFF

do
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,wtr1);
Lcd_Out(2,1,mtr1);
if(c>0)
{
PORTD.F2 = 1   
c--;
}
else
PORTD.F2 = 0;   
  
if(b>0)
{
PORTD.F0 = 1;
Delay_ms(125);
PORTD.F0 = 0;
b--;
}
  
if(PORTD.F7 == 0)
c = 16;

if(PORTA == 0x0F)
{
PORTD.F1 = 1;
Lcd_Out(1,8,wtr2);
Lcd_Out(2,7,mtr3);
PORTC = 1;
if(i == 0)
{
c = 16;
b=3;   
}
i=1;
}
else if(PORTA == 0x0E)
{
Lcd_Out(1,8,wtr3);
if(i == 1)
Lcd_Out(2,7,mtr3);
else
Lcd_Out(2,7,mtr2);
PORTC = 3;   
}
else if(PORTA == 0x0C)
{
Lcd_Out(1,8,wtr4);
if(i == 1)
Lcd_Out(2,7,mtr3);
else
Lcd_Out(2,7,mtr2);
PORTC = 7;
}
else if(PORTA == 0x08)
{
Lcd_Out(1,8,wtr5);
if(i == 1)
Lcd_Out(2,7,mtr3);
else
Lcd_Out(2,7,mtr2);
PORTC = 15;
}
else if(PORTA == 0x00)
{
Lcd_Out(1,8,wtr6);
Lcd_Out(2,7,mtr2);
PORTD.F1 = 0;   
if(i == 1)
{
c = 16;
b = 3;   
}
i=0;   
PORTC = 31;
}
else
PORTA = 0x0F;
Delay_ms(125);


}while(1);   
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote