Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/20/04 11:14
Read: times


 
#74497 - RE: Soft UART problem
Responding to: ???'s previous message
Hello Ravi,

I formatted your code so that other members could read
it better. I flagged two mistakes I caught. I am sure
there are others.

Regards,

Charles Bannister

Ravi P Wrote:
I the following is code which i am using as second UART 
but I am not getting the output can anyone tell what 
could be wroung in the code 

	RxD1 EQU P3.6 			; reception pin 
	TxD1 EQU P3.7 			; transmission pin 
	SR_SPEED EQU 4 			; reception at 1200 bauds 
	ST_SPEED EQU 4 			; transmission at 1200 bauds 

	ST_READY BIT 1 			; 1 if transmitter ready 
	SR_READY BIT 1 			; 1 if receiver ready 
	SR_ERROR BIT 1 			; 1 if receiver error 
	SR_INCOM BIT 1 			; 1 if character received 



	SR_CH DATA 1 			; character in reception 
	SR_COUNT DATA 1 		; internal counter 
	SR_STATUS DATA 1 		; receiver status 
	SR_CHAR DATA 1 			; character received 

	ST_CHAR DATA 1 			; character in transmission 
	ST_COUNT DATA 1 		; internal counter 
	ST_STATUS DATA 1 		; transmitter status 

org 0000H
       
	AJMP MAIN 

ORG 001BH 

	JMP SI_INTERRUPT 
;***************************************************** 
MAIN: 	ACALL SI_INSTALL 		; serial interface installation 
LOOP: 	;ACALL SI_RXD <====== Mistake?=	; wait for a character reception 
	MOV A,#'D' 
	ACALL SI_TXD 			; send character received 
	SJMP LOOP 

;****************************************************** 

SI_INSTALL: 
	MOV TCON,#40H 			; Timer 1 enabled 
	MOV TMOD,#20H 			; 8-bit auto-relaod 
	MOV TH1,#0E8H 			; 1200 bauds 
	MOV SCON,#52H 			; serial port mode 1 
	SETB ST_READY 			; transmitter ready 
	SETB SR_READY 			; receiver ready 
	CLR SR_ERROR 			; no error 
	SETB ET1 			; Timer 1 
	SETB EA 
	RET 
;****************************************************** 

SI_TXD: 	
	JNB ST_READY,SI_TXD 
	mov R1,#st_ready 
	MOV C,P 
	MOV ACC.7,C 			; set parity 
	MOV ST_CHAR,A 			; character to send 
	MOV ST_COUNT,#(ST_SPEED/2) 	; set counter at 1/2 bit duration 
	MOV ST_STATUS,#0 		; status initialization 
	CLR ST_READY 			; start transmission 
	RET 
;****************************************************** 

SI_RXD: 
	JNB SR_INCOM,SI_RXD 
	MOV A,SR_CHAR 			; character received 
	CLR SR_INCOM 			; character readed 
	RET				*/      <====== Mistake? ========
;****************************************************** 

SI_INTERRUPT: 
	JNB SR_READY,SR_INTL 		; receiver not busy 
	JB RxD1,ST_INT0 		; start bit ? 
	CLR SR_READY 
	MOV SR_COUNT,#(SR_SPEED/2) 	; load counter at 1/2 bit duration 
	MOV SR_STATUS,#0 		; status initialization 
	SJMP ST_INT0 
SR_INTL: 
	DJNZ SR_COUNT,ST_INT0 		; sample point ? 
	PUSH ACC 
	PUSH PSW 
	MOV A,SR_STATUS 
	JNZ SR_INT3 
	JB RxD1,SR_FRAME 		; start bit OK (0) ? 
SR_INT2: 
	INC SR_STATUS 
	MOV SR_COUNT,#SR_SPEED 
	SJMP SR_INT5 
SR_FRAME: 
	SETB SR_READY 
	SETB SR_ERROR 			; receiver error 
	SJMP SR_INT5 
SR_INT3: 
	CJNE A,#9,$+3 			; 8 bits + stop bit 
	JNC SR_INT4 
	MOV C,RxD1 			; bit sampling 
	MOV A,SR_CH 
	RRC A 
	MOV SR_CH,A 
	SJMP SR_INT2 
SR_INT4: 
	JNB RxD1,SR_FRAME 		; stop bit OK (1) ? 
	MOV SR_CHAR,SR_CH 		; save character received 
	SETB SR_READY 
	SETB SR_INCOM 			; 1 char. received 
	SR_INT5: POP PSW 
	POP ACC 
ST_INT0: 				; transmission part 
	JB ST_READY,ST_INT5 		; exit if no character to send 
	DJNZ ST_COUNT,ST_INT5 		; sample point ? 
	PUSH ACC 
	PUSH PSW 
	MOV A,ST_STATUS 
	JNZ ST_INTL 			; start ? 
	CLR TxD1 			; set start bit 
	MOV ST_COUNT,#ST_SPEED 
	INC ST_STATUS 
	SJMP ST_INT4 
ST_INTL: 
	CJNE A,#9,$+3 			; 8 bits + stop bit 
	JNC ST_INT2 
	MOV A,ST_CHAR 
	RRC A 				; bit to send in carry 
	MOV ST_CHAR,A 
	MOV TxD1,C 			; transmission of bit 
	MOV ST_COUNT,#ST_SPEED 		; counter initialization 
	INC ST_STATUS 
	SJMP ST_INT4 
ST_INT2: 
	CJNE A,#10,ST_INT3 		; end of character ? 
	SETB ST_READY 
	SJMP ST_INT4 
	ST_INT3: SETB TxD1 		; set stop bit 
	MOV ST_COUNT,#ST_SPEED 
	INC ST_STATUS 
	ST_INT4: POP PSW 
	POP ACC 
ST_INT5: 
	RETI 
END 


List of 5 messages in thread
TopicAuthorDate
Soft UART problem            01/01/70 00:00      
   RE: Soft UART problem            01/01/70 00:00      
   RE: Soft UART problem            01/01/70 00:00      
      RE: Soft UART problem            01/01/70 00:00      
      RE: Soft UART problem            01/01/70 00:00      

Back to Subject List