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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/13/07 03:24
Read: times


 
#137096 - you need to control flow
Responding to: ???'s previous message
Joe Martin said:
Hi,
Here's the code for the transmitting end:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ORG 0000H
MOV SCON, #01000000B ; set serial port for mode 1 operation
MOV TMOD, #20H ; set timer 1 to auto reload
MOV TH1, #0FDH ; set reload value for 9600 baud at 11.059MHz
SETB TR1 ; start timer 1
CLR TI

LOOP:
MOV SBUF, #55H ; transmit �55� hex out in TxD line
JNB TI, $ ; wait until done
CLR TI ; clear transmit flag ready to go again
sjmp loop
END
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


I have modified your code so that it constantly sends code 55h to TxD of the serial port. Had that ljmp not have been in there, your code would probably run to the end of the code space and restart at the beginning.



And here's the code for the receiving end:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ORG 00H
JMP MAIN

ORG 23H
JMP SERIAL_ISR

MAIN:

lcall INIT_LCD

MOV SCON, #50H ; 50H=01010000B
MOV TMOD, #20H ;
MOV TH1, #0FDH ;

MOV IE, #10010000B

SETB TR1
CLR RI
sjmp $ ???

SERIAL_ISR: JNB RI, SERIAL_ISR
CLR RI
MOV R2, SBUF
CALL INIT_LCD
CALL DATA_DISPLAY

INIT_LCD:
MOV A,#38H ; initialization
ACALL CMD ; issue command
MOV A,#0EH ; LCD ON, cursor ON
ACALL CMD ;
MOV A,#01H ; clear LCD
ACALL CMD ;
MOV A,#00H ; shift cursor right
ACALL CMD ;
MOV A,#80H ; cursor: line 1, position 6
ACALL CMD ;
RET


CMD: MOV P1,A ; issue command code
CLR P3.3 ; clear RS=0, for command
CLR P3.4 ; clear R/W=0, to write to LCD
NOP
SETB P3.5 ; set E=1
NOP
NOP
CLR P3.5 ; clear E=0, to generate an H-to-L pulse
ACALL DELAY ; give LCD some time
RET;


DELAY: MOV R1,#49 ; second-loop counter
LOOP2: MOV R0,#0FFH ; first-loop counter
LOOP1: DJNZ R0,LOOP1 ; loop 255 times
DJNZ R1,LOOP2 ; loop 49 times
RET

DATA_DISPLAY:
MOV P1,R2 ; issue data
SETB P3.3 ; set RS=1, for data
CLR P3.4 ; clear R/W=0, to write to LCD
NOP
SETB P3.5 ; set E=1
NOP
NOP
CLR P3.5 ; clear E=0, to generate an H-to-L pulse
ACALL DELAY ; give LCD some time

END

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

To start, look at what I added. It is a good idea to add some sort of termination to your code. I have explained the reason above.

It is advisable to add the "lcall" statement I added in bold, so that everything has a chance to initialize before the serial port decides to hog the system though interrupts.

You may also need to add some "flags". This means you need to set a bit or even a byte when a specific condition happens.

And, your serial interrupt might not work. It allows a limited amount of clock cycles. Having an LCD display routine will use up an enormous amount of those cycles, especially when your crystal speed is high.

The only two things that you need to do in that interrupt is grab the data and clear the TI and RI bits.

The simplest way is this:

JNB RI,noget
mov A,SBUF
CLR RI
noget:
CLR TI
RETI

Now, you can be certain that the data is received. Have your LCD display routine in any other routine but your serial reception (serial interrupt) routine, so then if you are in the middle of the LCD delay routine, the system can then call the serial interrupt anytime it picks up a valid character.


List of 34 messages in thread
TopicAuthorDate
RxD to LCD problems            01/01/70 00:00      
   Serial ISR            01/01/70 00:00      
   work needed.            01/01/70 00:00      
   you need to control flow            01/01/70 00:00      
      confused            01/01/70 00:00      
         this is what I mean            01/01/70 00:00      
            OK            01/01/70 00:00      
               yes            01/01/70 00:00      
            Non-useful Serial ISR            01/01/70 00:00      
               AND it's stuck            01/01/70 00:00      
                  thanks            01/01/70 00:00      
               I was going for optimization.            01/01/70 00:00      
      It's functioning            01/01/70 00:00      
         now stay consistent            01/01/70 00:00      
            Terminating code?            01/01/70 00:00      
               .            01/01/70 00:00      
                  correct terminology            01/01/70 00:00      
                  Missing the point            01/01/70 00:00      
                     i get it now            01/01/70 00:00      
                        Most, but not all            01/01/70 00:00      
                        why on earth            01/01/70 00:00      
                        if it\'s almost correct, it\'s still wrong :-)            01/01/70 00:00      
                           ok            01/01/70 00:00      
                              Not R6 and R7            01/01/70 00:00      
                                 well it happend again            01/01/70 00:00      
                                    Q.E.D.            01/01/70 00:00      
                                       One further comment is needed            01/01/70 00:00      
                              Hey            01/01/70 00:00      
                        Dangerous recommendation            01/01/70 00:00      
                           good point            01/01/70 00:00      
                              they all do            01/01/70 00:00      
                  it 'trust' the same as 'experiment'?            01/01/70 00:00      
   more issues            01/01/70 00:00      
      Joe, please read this            01/01/70 00:00      

Back to Subject List