Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seting up a clock and data link between two microcontrollers

Status
Not open for further replies.

Borgeh

Programmer
Nov 28, 2004
1
0
0
GB
Hello,
i want to have two microcontrollers set up with a clock and data wire between them, there will be three switches on one microcontroller and three led's on the other... on the transmitting microcontroller i have ths code but it doesnt seem to send out the right pattern. any help on debugging it will be apreciated.

*******************START OF CODE ***********************
$include (reg66x.INC)
; CLOCK IS SET AT 10,000 PER SECOND THROUGH P2.1, DATA IS SET ON P2.2
; DATA RATE SHOULD BE 10Kbps
; SHOULD SEND 10111SSS, S BEING THE SWITCH VALUE.

ORG 0
SJMP START
ORG 40H

START:
; START BY READING IN THE SWITCHS AND MASKING THE BYTE
MOV A,P1
ANL A,#07H

ACALL SEND1 ;SENDING 1 THROUGH THE DATA PIN
ACALL SEND0 ;SENDING 0 THROUGH THE DATA PIN

;SENDING THREE 1'S THROUGH THE DATA PIN
MOV R3,3
AGAIN:
ACALL SEND1
DJNZ R3,AGAIN

;SENDING THE SWITCH VALUES THROUGH THE DATA PIN
MOV R3,3
AGAIN1:
ACALL SDATA
DJNZ R3,AGAIN1

JMP START

;SENDS 1 THROUGH THE DATA PIN P2.2
SEND1:
SETB P2.1
ACALL DELAY
SETB P2.2
ACALL DELAY
CLR P2.1
ACALL DELAY
CLR P2.2
ACALL DELAY
RET

;SENDS 0 THROUGH DATA PIN 2.2
SEND0:
SETB P2.1
ACALL DELAY
ACALL DELAY
CLR P2.1
ACALL DELAY
ACALL DELAY
RET

;READS THE SWITCH VALUE EITHER SEND 1 OR 0 DEPENDING ON VALUE
SDATA:
RLC A
JC SDATA1
ACALL SEND0
SDATA1:
ACALL SEND1
RET

;DELAY OF 0.05MS
DELAY:
MOV R0,#44
AGAIN2:
DJNZ R0,AGAIN2
RET

END

****************** END OF CODE ***********************
 
Dear Borgeh,

The misstake is soo easy to make, that it took me some time
before a nothisted it.

In the routine: SDATA you just forgotten a RET afther the
ACALL SEND0.

So now when the data is 0 (zero) you send a 0 and a 1.

Sincerly,

Tessa (Hardware designer/Programmer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top