Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I NEED CODE FOR 8051 SERIAl comm..PLSSS HELP

Status
Not open for further replies.

kumar_3k

New Member
GUY PLS HELP ME , I NEED ASSM CODE(INTEL) FOR 8051 :TO RECEIVE DATA FROM SERIAL PORT AND SEND IT TO PORT1 AND TO READ DATA FROM PORT2 AND SEND IT SERIAL;WITH CONTINUESLY.
IF ANYONE HV THIS CODE PLS LEAVE THE CODE IN THIS PAGE...
ANY SIMILAR CODE ALSO FINE FOR ME...THANKS.
 

kinjalgp

Active Member
Try This:
Code:
;All baud rates @ 11.0592 MHz
.EQU	BAUD_CONST,	250		; 9600 BAUD

.EQU OLD_DATA, 0x30
.EQU NEW_DATA, 0x31

;********************************************************************************
.ORG	0000H
	LJMP MAIN

.ORG	0023h		; SERIAL I/O INTERRUPT VECTOR
	LJMP UART_INTR
;**********************************************************************************

;**********************************************************************************
; PROGRAM ENTRY POINT
;**********************************************************************************
MAIN:
	CLR	ACC
	MOV	NEW_DATA, A
	MOV	OLD_DATA, A
	LCALL	INIT_SERIAL

MAIN_LOOP:
	MOV	NEW_DATA, P2
	MOV	A, OLD_DATA
	XRL	A, NEW_DATA
	JZ	MAIN_LOOP
	MOV	OLD_DATA, NEW_DATA      ; Send character if data is changed on P2
	MOV	SBUF, NEW_DATA
	SJMP	MAIN_LOOP


;***********************************************************************************************
; INITIALIZE SERIAL PORT
;***********************************************************************************************
INIT_SERIAL:
        CLR     EA
        ORL     PCON, #10000000B        ;SET DOUBLE BAUD RATE
        ANL     TMOD, #00001111B        ;CLEAR ALL TIMER1 BITS IN TMOD
        ORL     TMOD, #00100000B        ;SET TIMER1 AS 8 BIT AUTO RELOAD
        CLR     TR1                     ;MAKE SURE TIMER1 ISN'T RUNNING
        CLR     TF1
        MOV     A, #BAUD_CONST          ;256 - (CRYSTAL / (BAUD * 192))
        MOV     TH1, A                  ;SET TIMER1 RATE
        MOV     TL1, A
        MOV     SCON, #01010000B        ;CONFIG SERIAL PORT (RI AND TI CLEARED) MODE=1
        SETB    TR1                     ;START TIMER1
        SETB    ES                      ;ENABLE SERIAL PORT INTERRUPT
        SETB    EA                      ;ALSO TURN ON INTERRUPTS IN GENERAL
	SETB	PS			;SET SERIAL PORT PRIORITY LEVEL 
        RET

;**********************************************************************************
; SERIAL PORT INTERRUPT SERVICE ROUTINE
;**********************************************************************************
UART_INTR:
GetChar:
	PUSH	PSW
	PUSH	ACC
	JB	TI,TRANSMIT_1
	JNB	RI,GetChar
	MOV	P1, SBUF ;Send Character to P1
	CLR	RI
	SJMP	INTR_END
TRANSMIT_1:
	CLR	TI
INTR_END:	
	POP	ACC
	POP	PSW
	RETI

And remember one thing. Do not post your question twice or thrice on this forum. Crossposting will not get you faster replies - moderator @ www.electro-tech-online.com
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top