Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6762437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:19:33+00:00 2026-05-26T14:19:33+00:00

I am writing a very simple application which allows one to change the temperature.

  • 0

I am writing a very simple application which allows one to change the temperature. The temperature is displayed using LEDS (BCD format)

I wrote the following code in Keil C51:

#include< REG51.h>

sbit select = P1^7;
sbit up = P1^0;
sbit down = P1^1;
int data room = 24;

void main()
{   int prog;
    P2 &=0x00;
    P1 |=0x83;
    prog = 0;
    while (1)
    {
        if(select == 1)
            prog++;
        if(prog == 1)
        {
            if(up == 1)
                room++;
            if(down == 1)
                room--;

            P2 = room;
        }
    }
}

I then complied this and obtained the Intel hex file which i then tried to simulate using the Edsim.

According to the C code the temp should change when prog=1 and when either up(p1.0) or down(p1.1) is pressed, but in the simulation it only changes when both select(p1.7) and up/down is pressed!

Why is this happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:19:34+00:00Added an answer on May 26, 2026 at 2:19 pm

    prog++ means that the value of prog increments by 1 every time that the condition select == 1 is true. This means that the condition prog == 1 is true only on the first iteration that it’s incremented.

    Try changing prog++ to prog = 1.

    Edit: As per discussion in comments, if you wish to track the number of times select has gone up, you need to wait for it to be 0 again before you let prog be incremented again. For example:

    int prev = select;
    …
    if (select != prev) {
        // select has changed from its previous state
    
        prev = select;
        if (prev) {
            // select went from 0 to 1
            ++prog;
    
            if (prog == 1) {
               // code to be executed once only on the first press
            } else if (prog == 2) {
               // code to be executed once only on the second press
            } else if (prog >= 3) {
               // code to be executed once on every subsequent press
            }
        } else {
            // select went from 1 to 0
        }
    }
    
    if (prev) {
       // select is being pressed
    
       if (prog == 1) {
           // code to be executed _continuously_ while select is held down
           // (after first press only)
       }
       // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a very simple JavaFX application which will hopefully display information from
I'm writing a very simple web application in ASP.NET MVC 2.0 which is used
I am writing a very simple application, for the iPhone. Unfortunately I am really
Background I am writing and using a very simple CGI-based (Perl) content management tool
I am writing a web based application using Ruby on Rails. In one of
I am writing a simple C++ application which might be installed on Linux or
Okay, simple situation: I'm writing a simple console application which connects to a SOAP
I'm writing a very simple flash app (AS 2) to sign users up to
I'm writing a very simple text editor and have run into a somewhat minor
I am writing a very simple RMI server, and I am seeing intermittent java.rmi.NoSuchObjectExceptions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.