8051 I/O ports, Switch to LED interface

Status
Not open for further replies.

JohnieWalker

Newbie level 1
Joined
Dec 29, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,296
Hi guys,

I've read all kind of stuff on internet and this forum but one thing still confuses me.

I have a study project.
A module is connected to 8051 Port 3.
On P3.0-P3.3 this module connects switches, on P3.4-P3.7 this module connects LED's.

When switch is pressed it triggers a logical "1" to be present on the line associated with this switch.
To light a LED you need to send a logical "1" to the line associated with this LED.

The homework is:

When switch 1 (on P3.0) is pressed light up LED's 1 2 3 4 in sequence, when switch 4 is pressed light them up in 4 3 2 1 sequence.

Ports 3.0 and 3.3 which are in question are setup for input by MOV P3,#00001001b.

The big question is: should I read input pins as low or as high? So when switch "1" is pressed and it produces logical "1" on the line associated with it (P3.0), what will I read?

As I understand a logical way would be to do like that:


Code ASM - [expand]
1
2
3
MOV P3,#00001001b    ;set I/o
SW1:    MOV C,P3.0   ;MOV P3.0 bit to carry     
        JNC SW2   ;jump to next switch checking if carry is not set (switch 1 not pressed, zero on input port P3.0)



but it doesn't work for me, since P3.0 returns as 1 even after initial setup.

So, should I expect "0" on P3.0 (and use JC instead) when switch 1 line is "1" or I'm misunderstanding something?

Like that


Code ASM - [expand]
1
2
3
MOV P3,#00001001b    ;set I/o
SW1:    MOV C,P3.0   ;MOV P3.0 bit to carry     
        JC SW2   ;jump to next switch checking if carry is not set (switch 1 not pressed, zero on input port P3.0)



Thank you.
 
Last edited:

Start a Tutorial for 8051 from basic first and use M-IDE Studio If you wantto use Assembly language
just search "m-ide studio for mcs-51" on google
 

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…