Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Define the ports of AT89C51 as input or output.

Status
Not open for further replies.

Micro Lover

Member level 2
Joined
Jul 22, 2009
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
pakistan
Activity points
1,614
define ports

I m using AT89C51 for digital clock, with external Pulse.

i want to set the port0-1-2 for parallel data, and port3 for serial data

the problem is to define the port as input or Output

Master Clock
------------------
port0 for input ; Full 8 bit Port
port1 for output ; Full 8 bit Port
port2 for output ; Full 8 bit Port
port3 for output (to send serial data)

Slave Clock
------------------
port0 for output ; Full 8 bit Port
port1 for output ; Full 8 bit Port
port2 for output ; Full 8 bit Port
port3 for input (to receive data)

The main problem is to define any port a input or as output
--------------------------------
I m sending my source code please inform me any type of errors

----------------------------- Source Code ----------------------------------------

org 00h

;Set up Timer 1
MOV IE, #0 ; Disable all interrupt
MOV TMOD, #020h ; Timer 1: Mode 2 (8-bit reload)
MOV TH1, #230d ; Reload value for 1201, SMOD = 0
MOV TL1, #230d ; Make first time-out correct
ANL PCON, #07fh ; To make SMOD =0

;Set up serial ports
MOV SCON, #50h ; Timer 1 : Mode 1 (vari baud) and set receive enable
SETB TR1 ; Start timer 1
mov r1, #6d
mov r2, #91d
mov r3, #63d
mov r4, #63d

MainLoop:
setb p0.7

mov r7, #90d
SubLoop:
mov r6, #90d
InnerSpot:
jmp DisplayData
InnerSpot1:
djnz r6, InnerSpot
djnz r7, SubLoop

clr p0.7

mov r7, #90d
SubLoop1:
mov r6, #90d
InnerSpot12:
jmp DisplayData
InnerSpot11:
djnz r6, InnerSpot12
djnz r7, SubLoop1


jmp MainLoop

DisplayData:
mov C, p2.7
orl C, p0.7


mov b, r1
mov p2, b
JNC Skip1
mov b, #254d
mov p1, b
Skip1:
mov b, #255d
mov p1, b
mov b, r2
mov p2, b
JNC Skip2
mov b, #253d
mov p1, b
Skip2:
mov b, #255d
mov p1, b

mov b, r3
mov p2, b
JNC Skip3
mov b, #251d
mov p1, b
Skip3:
mov b, #255d
mov p1, b

mov b, r4
mov p2, b
JNC Skip4
mov b, #247d
mov p1, b
Skip4:
mov b, #255d
mov p1, b

jnb RI, CheckReturnPoint
clr RI
mov a, sbuf

cjne a, #246d, CountCountinus
mov r0, #0d

CheckReturnPoint:
mov c, p0.7
jc InnerSpot1
jnc InnerSpot11

CountCountinus:
inc r0

DigOne:
cjne r0, #1d, DigTwo
mov r1, a
Jmp DisplayData

DigTwo:
cjne r0, #2d, DigThree
mov r2, a
Jmp DisplayData

DigThree:
cjne r0, #3d, DigFour
mov r3, a
Jmp DisplayData

DigFour:
cjne r0, #4d, CheckReturnPoint
mov r0, #0d
mov r4, a
Jmp DisplayData

End
 

define input

Hai

With 89c51, no need to define the port as o/p or i/p

MicroCon
 

at89c51 port 2

Just by saying INPUT & OUTPUT will not solve ur problem.
I/P pin or bit is sensed & O/P pin is made high or low as per requirements.
There is a change in H/W connections.
I really dont know ur exact problem as I hav not read ur code.
If u think that the problem is in ur h/w then post ur schematic or be specific with problem.
 

ports in at89c51

yes !! 8051 ports are open collector type, you dont need to configure it as input or out put you can in or out yr data any time. check yr HW in yr case.
 

port0 as input

microcon555 said:
Hai

With 89c51, no need to define the port as o/p or i/p

MicroCon


I thought you must set the pin of 8051 before you can use it as input but nothing is done if meant for output. Please correct me if I'm wrong because i read about it. And have seen codes for 8051 on different occasion implementing this rule. Thanks
 

mov a,b

codewiz said:
microcon555 said:
Hai

With 89c51, no need to define the port as o/p or i/p

MicroCon


I thought you must set the pin of 8051 before you can use it as input but nothing is done if meant for output. Please correct me if I'm wrong because i read about it. And have seen codes for 8051 on different occasion implementing this rule. Thanks

codewiz
Yes 8051 port pin must be set to logic when used as an input
 

at89c51 set pin high

Thanks "saDesigner81"

can you tell me any source in which the ports of 89c51 are define as input or output

any type of source code or any link (Using Asmbly)

thanks again
 

at89c51 set pin p1.0 high

codewiz said:
microcon555 said:
Hai

With 89c51, no need to define the port as o/p or i/p

MicroCon


I thought you must set the pin of 8051 before you can use it as input but nothing is done if meant for output. Please correct me if I'm wrong because i read about it. And have seen codes for 8051 on different occasion implementing this rule. Thanks

Yes, setting the pin to high and sense the change is the common method used by everyone. This is to avoid some false sensing by any interference.

But you can also sense low level if you are using an try stated input. For example port0 of at89x51 is tristated. You can use any pin of the port to sense high or low.

In avr or a pic it is a must to define the port as i/p or o/p before using it

MicroCon
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top