HIGH TEMPERATURE ALERT using 8051

//Code for HIGH TEMPERATURE ALERT SYSTEM using 8051

#include<reg51.h> // Includes 8051 microcontroller definitions

// Function declarations
void delay(unsigned int i); // Generates a delay for LCD enable pulse
void lcd_cmd(unsigned char a); // Sends a command to the LCD
void lcd_data(unsigned char b); // Sends data (characters) to the LCD
void lcd_init(void); // Initializes the LCD
void lcd_str(unsigned char *str); // Displays a string on the LCD
void hex2ascii(unsigned char value); // Converts hex value to ASCII for display

// Pin and port definitions
sbit rs = P2^0; // Register select pin for LCD
sbit en = P2^1; // Enable pin for LCD
sfr ldata = 0xb0; // Data port for LCD (Port 3)
sbit rd = P2^2; // Read pin for ADC
sbit wr = P2^3; // Write pin for ADC
sbit intr = P2^4; // Interrupt pin from ADC
sfr adc = 0x90; // ADC data from Port 1
sbit buz = P2^5; // Buzzer control pin

// Main function
void main ()
{
    // LCD welcome message
    lcd_init(); // Initialize LCD
    buz = 0; // Ensure the buzzer is off at the start
    lcd_str("    WELCOME    "); // Display first line of welcome message
    lcd_cmd(0xc0); // Move to the second line
    lcd_str("   TO PROJECT   "); // Display second line of welcome message
    delay(65000); // Delay for display
    lcd_cmd(0x01); // Clear the display
    
    // Display project title
    lcd_cmd(0x81); // Position the cursor
    lcd_str("  TEMPERATURE  "); // Display project title
    lcd_cmd(0xc2); // Move to the second line
    lcd_str("   ALERT   "); // Display 'ALERT' text
    delay(65000); // Delay for display
    lcd_cmd(0x01); // Clear display
    
    // Display temperature label
    lcd_cmd(0x80); // Move cursor to first line, start position
    lcd_str("  Temp ="); // Display 'Temp =' text
    lcd_cmd(0x8b); // Move cursor to show temperature in degrees
    lcd_data((char)223); // Display degree symbol
    lcd_str("C"); // Display 'C' for Celsius

    // Infinite loop to continuously monitor temperature
    while(1)
    {   
        // ADC conversion process
        rd = 1; // Set read high
        wr = 0; // Start conversion by setting write low
        delay(100); // Wait for conversion
        wr = 1; // Set write high
        while(intr == 1); // Wait until conversion finishes (interrupt flag low)
        delay(100); // Small delay
        rd = 0; // Set read low to fetch ADC result

        // Display temperature value
        lcd_cmd(0x89); // Set cursor position to display temperature value
        hex2ascii(adc*2); // Convert ADC value to ASCII and display
        
        // High-temperature alert condition
        if(adc*2 > 0x1d) // Check if temperature exceeds threshold (29°C)
        {
            // Display alert message and activate buzzer
            lcd_cmd(0xC0); // Move cursor to second line
            lcd_str("HIGH TEMP ALERT!"); // Display high temp alert message
            buz = 1; // Turn buzzer on
        }
        else
        {
            // Clear alert message and turn off buzzer
            lcd_cmd(0xC0); // Move cursor to second line
            lcd_str("                "); // Clear the alert message
            buz = 0; // Turn buzzer off
        }
        intr = 1; // Ready for next ADC conversion
    }
}

// Function to convert hex value to ASCII and display on LCD
void hex2ascii(unsigned char value) 
{
    unsigned char x, d1, d2, d3;
    x = value / 10; // Extract tens digit
    d3 = value % 10; // Extract ones digit
    d2 = x % 10; // Extract tens digit
    d1 = x / 10; // Extract hundreds digit
    //lcd_data(d1 + 0x30); // Display hundreds digit (ASCII)
    lcd_data(d2 + 0x30); // Display tens digit (ASCII)
    lcd_data(d3 + 0x30); // Display ones digit (ASCII)
}

// LCD initialization function
void lcd_init()
{
    lcd_cmd(0x38); // Initialize LCD for 8-bit mode
    lcd_cmd(0x0c); // Display on, cursor off
    lcd_cmd(0x01); // Clear display
    lcd_cmd(0x80); // Set cursor to beginning of first line
}

// Delay function
void delay(unsigned int i)
{
    unsigned int j;
    for(j = 0; j < i; j++); // Simple loop for delay
}

// Function to send command to LCD
void lcd_cmd(unsigned char a)
{
    rs = 0; // Set for command mode
    ldata = a; // Load command to data port
    en = 1; // Enable LCD
    delay(5); // Small delay
    en = 0; // Disable LCD
    delay(5); // Small delay
}

// Function to send data (characters) to LCD
void lcd_data(unsigned char b)
{
    rs = 1; // Set for data mode
    ldata = b; // Load data to data port
    en = 1; // Enable LCD
    delay(5); // Small delay
    en = 0; // Disable LCD
    delay(5); // Small delay
}

// Function to display string on LCD
void lcd_str(unsigned char *str)
{
    while(*str) // Loop until the end of the string
    {
        lcd_data(*str++); // Send each character to the LCD
    }
}

I tried adjusting the formula used in my code to display the temperature values from an ADC connected to an LM35 temperature sensor. Initially, I multiplied the ADC value by 2, but that only displayed even temperatures.

What I Expected:
I was expecting the temperature display to show both even and odd values as the sensor reads the temperature. I anticipated a smooth progression of temperature values (e.g., 29°C, 30°C, 31°C) as the sensor detects the changes, without skipping or rounding errors.

New contributor

Pavan Freak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

HIGH TEMPERATURE ALERT using 8051

//Code for HIGH TEMPERATURE ALERT SYSTEM using 8051

#include<reg51.h> // Includes 8051 microcontroller definitions

// Function declarations
void delay(unsigned int i); // Generates a delay for LCD enable pulse
void lcd_cmd(unsigned char a); // Sends a command to the LCD
void lcd_data(unsigned char b); // Sends data (characters) to the LCD
void lcd_init(void); // Initializes the LCD
void lcd_str(unsigned char *str); // Displays a string on the LCD
void hex2ascii(unsigned char value); // Converts hex value to ASCII for display

// Pin and port definitions
sbit rs = P2^0; // Register select pin for LCD
sbit en = P2^1; // Enable pin for LCD
sfr ldata = 0xb0; // Data port for LCD (Port 3)
sbit rd = P2^2; // Read pin for ADC
sbit wr = P2^3; // Write pin for ADC
sbit intr = P2^4; // Interrupt pin from ADC
sfr adc = 0x90; // ADC data from Port 1
sbit buz = P2^5; // Buzzer control pin

// Main function
void main ()
{
    // LCD welcome message
    lcd_init(); // Initialize LCD
    buz = 0; // Ensure the buzzer is off at the start
    lcd_str("    WELCOME    "); // Display first line of welcome message
    lcd_cmd(0xc0); // Move to the second line
    lcd_str("   TO PROJECT   "); // Display second line of welcome message
    delay(65000); // Delay for display
    lcd_cmd(0x01); // Clear the display
    
    // Display project title
    lcd_cmd(0x81); // Position the cursor
    lcd_str("  TEMPERATURE  "); // Display project title
    lcd_cmd(0xc2); // Move to the second line
    lcd_str("   ALERT   "); // Display 'ALERT' text
    delay(65000); // Delay for display
    lcd_cmd(0x01); // Clear display
    
    // Display temperature label
    lcd_cmd(0x80); // Move cursor to first line, start position
    lcd_str("  Temp ="); // Display 'Temp =' text
    lcd_cmd(0x8b); // Move cursor to show temperature in degrees
    lcd_data((char)223); // Display degree symbol
    lcd_str("C"); // Display 'C' for Celsius

    // Infinite loop to continuously monitor temperature
    while(1)
    {   
        // ADC conversion process
        rd = 1; // Set read high
        wr = 0; // Start conversion by setting write low
        delay(100); // Wait for conversion
        wr = 1; // Set write high
        while(intr == 1); // Wait until conversion finishes (interrupt flag low)
        delay(100); // Small delay
        rd = 0; // Set read low to fetch ADC result

        // Display temperature value
        lcd_cmd(0x89); // Set cursor position to display temperature value
        hex2ascii(adc*2); // Convert ADC value to ASCII and display
        
        // High-temperature alert condition
        if(adc*2 > 0x1d) // Check if temperature exceeds threshold (29°C)
        {
            // Display alert message and activate buzzer
            lcd_cmd(0xC0); // Move cursor to second line
            lcd_str("HIGH TEMP ALERT!"); // Display high temp alert message
            buz = 1; // Turn buzzer on
        }
        else
        {
            // Clear alert message and turn off buzzer
            lcd_cmd(0xC0); // Move cursor to second line
            lcd_str("                "); // Clear the alert message
            buz = 0; // Turn buzzer off
        }
        intr = 1; // Ready for next ADC conversion
    }
}

// Function to convert hex value to ASCII and display on LCD
void hex2ascii(unsigned char value) 
{
    unsigned char x, d1, d2, d3;
    x = value / 10; // Extract tens digit
    d3 = value % 10; // Extract ones digit
    d2 = x % 10; // Extract tens digit
    d1 = x / 10; // Extract hundreds digit
    //lcd_data(d1 + 0x30); // Display hundreds digit (ASCII)
    lcd_data(d2 + 0x30); // Display tens digit (ASCII)
    lcd_data(d3 + 0x30); // Display ones digit (ASCII)
}

// LCD initialization function
void lcd_init()
{
    lcd_cmd(0x38); // Initialize LCD for 8-bit mode
    lcd_cmd(0x0c); // Display on, cursor off
    lcd_cmd(0x01); // Clear display
    lcd_cmd(0x80); // Set cursor to beginning of first line
}

// Delay function
void delay(unsigned int i)
{
    unsigned int j;
    for(j = 0; j < i; j++); // Simple loop for delay
}

// Function to send command to LCD
void lcd_cmd(unsigned char a)
{
    rs = 0; // Set for command mode
    ldata = a; // Load command to data port
    en = 1; // Enable LCD
    delay(5); // Small delay
    en = 0; // Disable LCD
    delay(5); // Small delay
}

// Function to send data (characters) to LCD
void lcd_data(unsigned char b)
{
    rs = 1; // Set for data mode
    ldata = b; // Load data to data port
    en = 1; // Enable LCD
    delay(5); // Small delay
    en = 0; // Disable LCD
    delay(5); // Small delay
}

// Function to display string on LCD
void lcd_str(unsigned char *str)
{
    while(*str) // Loop until the end of the string
    {
        lcd_data(*str++); // Send each character to the LCD
    }
}

I tried adjusting the formula used in my code to display the temperature values from an ADC connected to an LM35 temperature sensor. Initially, I multiplied the ADC value by 2, but that only displayed even temperatures.

What I Expected:
I was expecting the temperature display to show both even and odd values as the sensor reads the temperature. I anticipated a smooth progression of temperature values (e.g., 29°C, 30°C, 31°C) as the sensor detects the changes, without skipping or rounding errors.

New contributor

Pavan Freak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật