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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/13/09 19:11
Read: times


 
#161496 - Several
Responding to: ???'s previous message
Your main problem is you are using interrupts without actually using them. You are shooting yourself in the foot.
Your ISR immediately clears ti, and then exits, while in the main loop you wait (beugh!) for TI to come on (actually you have that line commented out) and then you transmit a byte. Proper interrupt driven serial transmission would look more like this:

;serial routines using interrupts
$mod51

org 0
	jmp	START	;
org 23h
	jmp	Ser_Int	;
org 30h
;------------------------------------------------------------
; set up uart in mode 1 (8 bits uart) with
; timer 1 in mode 2 (8 bits auto reload timer)

START:
	mov SP,#6Fh	; set up stack
	mov SCON, #50h	; uart in mode 1 (8 bit), REN=1
	orl TMOD, #20h	; Timer 1 in mode 2
	mov TH1, #0FDh	; 9600 Baud at 11.059MHz
	setb ES		; Enable serial interrupt
	setb EA		; Enable global interrupt
	setb TR1	; Timer 1 run
	
	call Test
	jmp $		; endless
;------------------------------------------------------------
;serial interrupt
Ser_Int:
	push ACC	; save accumulator
	jnb RI,Trans	; test if it is a reception
	clr RI		; clear reception flag for next reception
	mov A,SBUF	; read data from uart
	jmp ExitISR	; return
Trans: 
	CLR TI		; clear transmission flag for next trans
        clr a
        movc a,@a+dptr	; get character
        jz exitISR	; stop if char = null
        mov SBUF,A  	;

        inc dptr	; point to next char

ExitISR:
	pop ACC		; restore accumulator
	reti
;------------------------------------------------------------
Test:
	mov	dptr,#Test_String
	clr     ti
	clr a
        movc a,@a+dptr	; get character
        mov SBUF,A  	;

	;do other stuff, my ideal time waster is:

idle	equ	1
loop:	orl     pcon,#idle
	jmp	loop

Test_String:
DB	'This is a Test',0dh,0ah,0
;-----------------------------------------------------------------
end

 
Mind you, I haven't tested this code, and I have not reviewed any other details, like your initialization or anything, but it shows how the actual fetching and putting in the Tx buffer of the bytes should be part of your ISR before you can call it interrupt driven. Don't take this code as something ready to copy and paste into your project, it's only very rudimentary, but it shows the main principle.

Also, you have a massive flow problem! Your code goes:
- reset,
- init,
- call send message, (stack contains return address)
- (send message executes and returns), (stack is empty now)
- return.
The final return will return to a garbage address, as the stack will be empty at that point. You need a proper termination. My "favourite time waster" does that, at reduced energy consumption too.


List of 23 messages in thread
TopicAuthorDate
serial interrupt?            01/01/70 00:00      
   Your Problem            01/01/70 00:00      
      still not working            01/01/70 00:00      
         you need to flag somehow the end of transmission            01/01/70 00:00      
            reply to Jan            01/01/70 00:00      
   Several            01/01/70 00:00      
      To Hans            01/01/70 00:00      
         And my reply to Charles            01/01/70 00:00      
   no interrupts works            01/01/70 00:00      
   the solution            01/01/70 00:00      
      Isn't that what Hans said?            01/01/70 00:00      
      Perfectly????? Prolly should look again.            01/01/70 00:00      
         Got to look ahead...            01/01/70 00:00      
         Another thing to consider            01/01/70 00:00      
            reply to Andy Neil            01/01/70 00:00      
         reply to Michael Karas            01/01/70 00:00      
      why is this a bad idea            01/01/70 00:00      
         Exactly why not perfect !!!            01/01/70 00:00      
         response to Jan Waclawek            01/01/70 00:00      
            interrupts forever            01/01/70 00:00      
            nope            01/01/70 00:00      
               Re: Erik            01/01/70 00:00      
   if you HAVE to mix ...            01/01/70 00:00      

Back to Subject List