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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/24/10 08:26
Modified:
  05/24/10 08:57

Read: times


 
#176142 - serial communication only works once
I am talking to my mcu through my pc but it will only respond once.
there are 3 codes that i can send to it, no matter which code i send after reseting the device it responds properly but only to the first code after which i get no responce from the mcu here is my code, i have gone through it many times but can't see why its not working.
Can anyone help


$MOD51

 
          count2 equ 20h
          base equ 40H



; Program start


;;;;;;;;;;;;;;;;
start:
;;;;;;;;;;;;;;;;

	   MOV R0,#base        ; 'WRITE' POINTER
	   MOV R1,#base        ; 'READ' POINTER
           MOV COUNT2, #06H 
           LCALL SERIAL_INIT

;;;;;;;;
endloop:
;;;;;;;;
	  JMP endloop

	  ORG 0032H
          LJMP SERIAL_ISR

   
;;;;;;;;;;;;;;;;
SERIAL_INIT:
;;;;;;;;;;;;;;;;

            MOV SCON,#52H ;8-BIT UART,REN
            MOV TMOD,#20H ;8-BIT AUTO RELOAD MODE
            MOV TH1,#-15  ;8333 BPS AUTO RELOAD VALUE
            mov PCON, #080h ;To make SMOD =1 
            SETB EA       ;GLOBAL INTERRUPT ENABLE
            SETB ES       ;SERIAL INTERRUPT ENABLE
            SETB PS       ;HIGH PRIORITY FOR SERIAL INTERRUPTS
            SETB TR1      ;START TIMER
            RET

;;;;;;;;;;;;;;;;
SERIAL_ISR:
;;;;;;;;;;;;;;;;

	    PUSH ACC
	    JNB RI,TMT
	    CLR RI
	    MOV A,SBUF
	    LCALL HEXCON
	    LJMP EXITA
;;;;
TMT: 
;;;;

            CLR TI

;;;;;;
EXITA:
;;;;;;	
            POP ACC 
	    RETI

;;;;;;;;;;;;;;;;
WRITE_BUF:
;;;;;;;;;;;;;;;;
     
	     CJNE R0,#46H,NEXT1  ;CHECK FOR BUFFER RECYCLE 
	     MOV R0,#40H         ;CYCLE AGAIN

;;;;;;
NEXT1:	
;;;;;;
             MOV @R0,A
	     INC R0
	     RET



;;;;;
SEND:
;;;;;

	     MOV	SBUF, A
	     JNB	TI, $
	     CLR	TI
             RET


;;;;;;;
hexcon:
;;;;;;;
              LCALL WRITE_BUF
              dec count2
              mov a,count2
              jz check1      
              RET
;;;;;;;;;
check1: 
;;;;;;;;;
               ;reads data sent to serial from buffer and compares to find which command was sent
               ;code1

             LCALL BUFFER_READ
             CJNE A,#0F1H,EXIT1
             LCALL BUFFER_READ
             CJNE A,#58H,EXIT1
             LCALL BUFFER_READ
             CJNE A,#4AH,CHECK2
             LCALL BUFFER_READ
             CJNE A,#57H,EXIT1
             LCALL BUFFER_READ
             CJNE A,#42H,EXIT1
             LCALL BUFFER_READ
             CJNE A,#0D4H,EXIT1
             LCALL START_ENABLE
             MOV COUNT2,#06H
             RET

;;;;;;
EXIT1:
;;;;;;
             MOV COUNT2,#06H
             RET

;;;;;;;;
CHECK2:
;;;;;;;;
          ;;;;code2
       
             CJNE A,#0EH,EXIT1
             LCALL BUFFER_READ
             CJNE A,#01H,EXIT1
             LCALL BUFFER_READ
             CJNE A,#01H,CHECK3
             LCALL BUFFER_READ
             CJNE A,#0A7H,EXIT1
             LCALL  LOW_SPEED_FAN_ON
             MOV COUNT2,#06H 
             RET

;;;;;;;;;
CHECK3:
;;;;;;;;;

             ;;;code3      

             CJNE A,#00H,EXIT1
             LCALL BUFFER_READ
             CJNE A,#0A8H,EXIT1
             LCALL LOW_SPEED_FAN_OFF
             MOV COUNT2,#06H 
             RET

;;;;;;;;
DELAYa:
;;;;;;;;

             MOV A,#010H

;;;;;;;;        
DELAYRa:
;;;;;;;;

             dec A
             JNZ COUNTb
             ret

;;;;;;;
COUNTb:
;;;;;;;
	     MOV R0,#0FFH
	     DJNZ R0,$
	     JMP DELAYRa

;;;;;;;;;;;;;         
START_ENABLE:
;;;;;;;;;;;;;;

             lcall delaya
             MOV A,#0F1H
             LCALL SEND 
             MOV A,#58H
             LCALL SEND  
             MOV A,#47H
             LCALL SEND   
             MOV A,#44H
             LCALL SEND  
             MOV A,#43H
             LCALL SEND
             MOV A,#0E9H
             LCALL SEND            
             ret
                  
;;;;;;;;;;;;;;;;;
LOW_SPEED_FAN_ON: 
;;;;;;;;;;;;;;;;;

             lcall delayA
             MOV A,#0F1H
             LCALL SEND 
             MOV A,#57H
             LCALL SEND  
             MOV A,#0EH
             LCALL SEND   
             MOV A,#01H
             LCALL SEND  
             MOV A,#0A9H
             LCALL SEND           
             ret

;;;;;;;;;;;;;;;;;;
LOW_SPEED_FAN_OFF:
;;;;;;;;;;;;;;;;;;

             lcall delayA
             MOV A,#0F1H
             LCALL SEND 
             MOV A,#57H
             LCALL SEND  
             MOV A,#0EH
             LCALL SEND   
             MOV A,#00H
             LCALL SEND  
             MOV A,#0AAH
             LCALL SEND            
             ret

              
;;;;;;;;;;;;
BUFFER_READ:
;;;;;;;;;;;;

	    MOV A,R0
	    MOV B,R1
	    CJNE A,B,NEXT2       ;COMPARE R0 & R1
	    LJMP EXIT4	     ;NOTHING TO READ(BUFFER EMPTY)

;;;;;;
NEXT2:
;;;;;;
	
            CJNE R1,#46H,NEXT3
            MOV R1,#40H         ;JUMP TO START (RECYCLE)

;;;;;;
NEXT3:	
;;;;;;
            MOV A,@R1
            INC R1

;;;;;;
EXIT4:
;;;;;;
	    RET             

		







END 

 



List of 4 messages in thread
TopicAuthorDate
serial communication only works once            01/01/70 00:00      
   Comments?            01/01/70 00:00      
   think i found it            01/01/70 00:00      
      Comments!            01/01/70 00:00      

Back to Subject List