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 7970789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:29:01+00:00 2026-06-04T07:29:01+00:00

So, I have to do this challenge, which is to implement a camera surveillance

  • 0

So, I have to do this challenge, which is to implement a camera surveillance system for a 8051 microcontroller.

These are the specifications:

  1. Each camera is related to a movement sensor, and each time it detects a movement, the recording of this camera will be among the ones that will be registered and saved. If the sensor doesn’t capture any movement for more than 5 seconds, this camera will not be recorded anymore;

  2. If there’s no camera on, the video recorder must be on “pause”;

  3. If more than one camera is on, a multiplexer (mux) have to be used to select the camera signals in a way so each camera is recorded during 3 seconds. This way, all the active cameras must be recorded during 3 seconds. If just one camera is active, it’s signal must be the only one in the mux.

This I have already accomplished in the code below. And what we have to do now is to optimize the size of the code without the compiler optimizations. The code is 198 bytes by now, but I’m trying to get below 180 bytes.

Is it possible? I already tried to do the calculations of the #define, but the compiler already optimize that for me.

#include <REG51F.h>

#define TIMEOUT 50
#define TIMEOUT_REC 30

#define FrClk 12000000
#define FreqTimer0_emHz 10
#define VALOR_TH0 ((65536 - (FrClk /(12 * FreqTimer0_emHz ))) >> 8)
#define VALOR_TL0 ((65536 - (FrClk /(12 * FreqTimer0_emHz ))) & 0xFF)


data bit PAUSE_INT;
data bit PAUSE_TMP;
sbit PAUSE = P0^0;
sbit SENSOR1 = P0^1;
sbit SENSOR2 = P0^2;
sbit SENSOR3 = P0^3;
sbit SENSOR4 = P0^4;
sbit MUX0 = P0^5;
sbit MUX1 = P0^6;

data unsigned char CAM[4];
data unsigned char REC;
data unsigned char index;
data unsigned char count;

void timer0_int (void) interrupt 1 using 2 {
    for (index = 0; index < 4; index++)
        if(CAM[index])
        CAM[index]--;

    if (!PAUSE_INT && REC)
        REC--;
    else
    { 
         REC = TIMEOUT_REC;
         index = (index + 1) & 0x03;
         for (count = 0; !CAM[index] && count < 4; index = (index + 1) & 0x03, count++);

         MUX0 = index & 0x1;
         MUX1 = index & 0x2;


         PAUSE_INT = 0;
    }   
}

int main(void)
{

    PAUSE_TMP = 1;
    PAUSE_INT = 0;

    index = 0;

    //timer0_init
    EA = 1;
    TR0 = 0;              
    TMOD = (TMOD & 0xF0) | 0x01;  
    TH0 = VALOR_TH0;  
    TL0 = VALOR_TL0;
    ET0 = 1;     
    TR0 = 1;     

    while(1) {

        if (SENSOR1)
        {
                CAM[0] = TIMEOUT;
        }

        if (SENSOR2)
        {
                CAM[1] = TIMEOUT;
        }

        if (SENSOR3)
        {
                CAM[2] = TIMEOUT;
        }

        if (SENSOR4)
        {
                CAM[3] = TIMEOUT;
        }

        if (CAM[0] || CAM[1] || CAM[2] || CAM[3])
        {
                if (PAUSE_TMP)
                        PAUSE_INT = 1;
                PAUSE_TMP = 0;
        }
        else {
                PAUSE_TMP = 1;
        }

            PAUSE = PAUSE_TMP;
    }


}
  • 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-06-04T07:29:02+00:00Added an answer on June 4, 2026 at 7:29 am

    You’re probably going to have to look at the generated assembly code for this in order to wring the last few bytes out of it. It’s probably possible to shave a few here and there by reusing a variable or combining operations. The resulting code won’t be pretty – or maintainable – but it just might get you below your cutoff.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Challenge: I have this code that fails to compile. Can you figure out what's
I have a simple challenge with a background not animating. I have used this
I have this DependencyProperty which holds an entity with a property that is a
I have a chicken-egg problem. I would like too implement a system in PHP
Hibernate Pagination Issue I have an issue which is related to Hibernate Pagination and
I have a challenge - I have created this little concept here . The
Here's the challenge: I have a Flash movie which will be embedded in a
Hopefully someone here can help me with this challenge! I have a parent page
Not a duplicate of this I have a pretty simple CRM workflow, which basicly
I have this table named OrdersToCall Data types: All bigints, except for date which

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.