[51] 4 bit up down/counter assembly code

Status
Not open for further replies.

Sy3d

Newbie level 2
Joined
May 20, 2016
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
15
I need help with this problem doing described as below:


The issue is we didn't take anything about counters and timers of the 8051,so if someone can explain how can i write this in assembly :sad:
 

What is your clock?

First write a flow chart or some pseudo-code, e.g.:

Code:
If P3.5=1 then 
     if P1(0:3)=MOD then 
          P1(0:3)=0
     else 
           P1(0:3)=P1(0:3)+1
     end if
else
     if P1(0:3)=0 then 
          P1(0:3)=MOD
     else 
           P1(0:3)=P1(0:3)-1
     end if
end if;

This should help you figure out the assembly code.
 

@barry For now im using 11.0592 mhz clock ,but the problem is i don't know how to convert input P3.0-P3.3 as MOD.. is it 2^input ??
 

Assuming P3.0-P3.3 is a binary number (with P3.0 as the MSB) then the MOD value would be defined as:

P3.0 * 2^3 + P3.1 * 2^2 + P3.2 * 2^1 + P3.3 2^0
 
Reactions: Sy3d

    Sy3d

    Points: 2
    Helpful Answer Positive Rating
I meant, you didn't define a pin as a clock into your counter.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…