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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:07:36+00:00 2026-05-28T00:07:36+00:00

I have 8 LEDs and 2 buttons, initially the first and the last LED

  • 0

I have 8 LEDs and 2 buttons, initially the first and the last LED are lit, if i press the first button, the first led shifts right, if i press the second button the last led shifts left. If the two lights “meet”, by shifting upon each other, they switch off.

I did not know how to update the leds on a single row after pressing the buttons, so I made 2 rows, P1 and P2, for each button. The first row seems to shift properly, but the second is really messed up. What am I doing wrong?

Below is my code:

$TITLE(5)
$MOD51
ORG 100H
START: 
    ; 8 leds, P1.0-P1.7
    ; 2 buttons, P0.1 P0.2
    MOV P1, #00h
    MOV P2, #00h

    ; left LED positions
    MOV 30H, #00000001b ; initial position
    MOV 31H, #00000010b  
    MOV 32H, #00000100b  
    MOV 33H, #00001000b  
    MOV 34H, #00010000b             
    MOV 35H, #00100000b  
    MOV 36H, #01000000b  
    MOV 37H, #10000000b 

    MOV 38H, #00000000b ; leds meet

    ; right led positions
    MOV 39H, #10000000b ; initial position
    MOV 40H, #01000000b  
    MOV 41H, #00100000b  
    MOV 42H, #00010000b  
    MOV 43H, #00001000b             
    MOV 44H, #00000100b  
    MOV 45H, #00000010b  
    MOV 46H, #00000001b  

    MOV R1, #0
    MOV R2, #0

 LOOP:  
    JNB P0.1, INCREMENT_L ; left button pressed, led shifts right
    JNB P0.2, INCREMENT_R ; right button pressed, led shifts left

    CALL DISP_L ; display left led
    CALL DISP_R ; display right led

    JMP LOOP

INCREMENT_L:
    SETB P0.1
    CJNE R1, #7, INC_L
    MOV R1, #0
    JMP LOOP

INCREMENT_R:
    SETB P0.2
    CJNE R2, #7, INC_R
    MOV R2, #0
    JMP LOOP

INC_L:
    MOV A, R2
    ADD A, #39H
    MOV B, A
    MOV A, R1
    ADD A, #30H
    CJNE A, B, INCL
    JMP RESET
    JMP LOOP

INC_R:
    MOV A, R1
    ADD A, #30H
    MOV B, A
    MOV A, R2
    ADD A, #39H
    CJNE A, B, INCR
    JMP RESET
    JMP LOOP

INCL:
    INC R1
    JMP LOOP

INCR:
    INC R2
    JMP LOOP

DISP_L:
    MOV A, R1
    ADD A, #30H
    MOV R0, A
    MOV P1, @R0
    RET

DISP_R: 
    MOV A, R2
    ADD A, #39H
    MOV R0, A
    MOV P2, @R0
    RET

RESET:
    MOV R1, #0
    MOV R2, #0
    JMP LOOP

END
  • 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-28T00:07:37+00:00Added an answer on May 28, 2026 at 12:07 am

    This sounds an awful lot like a signed/unsigned issue. Is your add unsigned, or does it assume the high bit is a sign bit and do the 2s compliment stuff for you. Any carry bits left over could also affect things if not careful as well. Do you have a straight shift instruction instead of using add?

    Looked online real quick and see you do have a SHL/SHR instruction you could use to move your bits around. Then, you just xor against your location to turn the bit off if they match.

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

Sidebar

Related Questions

Have I understod the following right? font-family:sans-serif; Above will result in the default sans-serif
I have a JPanel with two JTextFields. If the user writes some text into
I'm making a monochrome in-browser 'LED' display. It should have a matrix of 33
I have a strange case that (I think) I need two resource IDs for
I have a Nexus-S which has no external notification LEDs to show a missed
This one is tricky to me: I have four groups of 8 LEDs. A
I have this form: <tr> <td><input type=hidden name=ledlamps value=LED lamps>LED lamps:</td> <td><input class=field checkbox
Have just started converting an existing job tracking system into an ASP.NET MVC application.
Have an option to choose either a windows SE or Web Edition to install,
Have 2 tables for example: In 1st: object & parent columns object | parent

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.