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

Back to Subject List

Thread Closed: Issue successfully resolved

???
04/11/07 13:08
Read: times


 
#136979 - +1 for this answer
Responding to: ???'s previous message
One thing that I did notice in the code is that he is not adding something to terminate his string, or he is not limiting the number of times the loop can run.

His LCD display subroutine will loop 256 times because he sets R0 to 0 and he uses "DJNZ R0,NEXT" which means R0 goes through 256 different values.

This may be a problem because in the best case scenario, unwanted characters can appear.

If I were to redo your LCD data display routine, here is how I would do it.

---------------------------------------------------------------
MOV DPTR,#MSG ;INITIALIZE POINTER
MOV R0,#0X3 ;INITIALIZE COUNTER TO NUMBER OF CHARACTERS IN TEXT
NEXT: MOV A,#0X00
MOVC A,@A+DPTR ;FETCH DATA BYTE FROM INTERNAL EPROM

SETB RS ;SELECT DATA REGISTER
CLR RW ;WRITE MODE
MOV P2,A ;OUTPUT DATA TO PORT 2
SETB E
CLR E ;APPLY ENABLE PULSE

LCALL DLY_160U

INC DPTR ;INCREMENT TO NEXT DATA
DJNZ R0,NEXT
--------------------------------------------------------------

If you don't want to worry about text length, you can use this code instead:

---------------------------------------------------------------
MOV DPTR,#MSG ;INITIALIZE POINTER
NEXT: MOV A,#0X00
MOVC A,@A+DPTR ;FETCH DATA BYTE FROM INTERNAL EPROM
JZ terminate ;TERMINATE CODE IF THE BYTE IS NUL
SETB RS ;SELECT DATA REGISTER
CLR RW ;WRITE MODE
MOV P2,A ;OUTPUT DATA TO PORT 2
SETB E
CLR E ;APPLY ENABLE PULSE

LCALL DLY_160U

INC DPTR ;INCREMENT TO NEXT DATA
LJMP NEXT
terminate:
----------------------------------------------------------------

I prefer the second piece of code, because it reads as many characters as necessary until it comes to character NUL (ascii code 0). JZ will detect this condition. Basically this "JZ" functions exactly like an "EXIT DO" in Visual Basic.

LJMP NEXT is the best to use for starters. In fact, there are no restrictions when using LJMP with the exception that you can't go past the highest byte you have in your code space without expecting erratic results. For example, LJMP #FFFFh won't work if you have 1K of code memory (or memory that contains code).
The only other restriction is that you can't go past #FFFFh.


If you use the second piece of code, you can change your data to something like this:

DB 'Test!',00h



List of 78 messages in thread
TopicAuthorDate
LCD Problem            01/01/70 00:00      
   stop shouting - also            01/01/70 00:00      
      Sorry Erik            01/01/70 00:00      
         no need to be 'sorry'            01/01/70 00:00      
            timing            01/01/70 00:00      
               delays aren't necessary if you monitor busy            01/01/70 00:00      
   Pullup resistors on P0            01/01/70 00:00      
      already answered            01/01/70 00:00      
   make sure            01/01/70 00:00      
      Is there any test procedure to test LCD Module?            01/01/70 00:00      
         from the shop            01/01/70 00:00      
   did you try...            01/01/70 00:00      
      tthat is SOME wait            01/01/70 00:00      
         ...            01/01/70 00:00      
            well, maybe is is a good thing            01/01/70 00:00      
               i need a lcd testing procedure            01/01/70 00:00      
                  like this            01/01/70 00:00      
                     lcd testing            01/01/70 00:00      
                        Couple of links            01/01/70 00:00      
                           no datasheet            01/01/70 00:00      
                              Should work the same...            01/01/70 00:00      
                                 +1 for this answer            01/01/70 00:00      
                                    LJMP limits            01/01/70 00:00      
      delays aren't necessary if you monitor busy            01/01/70 00:00      
      May be LCD is damaged!!            01/01/70 00:00      
         Pin 3 may require a negative voltage            01/01/70 00:00      
            PLEASE!!!!            01/01/70 00:00      
               There is a "convention"            01/01/70 00:00      
            to clarify?            01/01/70 00:00      
         two problems with the 'advice' you followed            01/01/70 00:00      
            Only lower line of LCD is showing!            01/01/70 00:00      
               looks like pretty normal behavior to me ...            01/01/70 00:00      
                  'cheap' -5 for a LCD            01/01/70 00:00      
   where is that standard?            01/01/70 00:00      
      It's not an EIA or a DIN standard ...            01/01/70 00:00      
         you said exactly that            01/01/70 00:00      
            We've all told him to read his LCD datasheet            01/01/70 00:00      
               this is getting ridiculous.            01/01/70 00:00      
                  ok, I deserve -1 from before            01/01/70 00:00      
                     why not spell it correctly            01/01/70 00:00      
                  That's why there are datasheets            01/01/70 00:00      
   LCD is workingggg!!!!!!            01/01/70 00:00      
      Now get to work            01/01/70 00:00      
         MISTAKES made            01/01/70 00:00      
   Datasheet, which created a problem.            01/01/70 00:00      
   Can LCD datasheet be uploaded for others referen.?            01/01/70 00:00      
      You have to get the correct datasheet            01/01/70 00:00      
         need lcd testing procedure            01/01/70 00:00      
            You need more data!            01/01/70 00:00      
               addendum to Richards post            01/01/70 00:00      
                  There is a de-facto standard            01/01/70 00:00      
                     lcd problem            01/01/70 00:00      
                        Disconnect d1            01/01/70 00:00      
                        problem with second line of lcd            01/01/70 00:00      
                           program            01/01/70 00:00      
                              your code has a problem?            01/01/70 00:00      
                                 looks like experimenting again ...            01/01/70 00:00      
                                 from hitachi data sheet on HD44780            01/01/70 00:00      
                                    I'm starting to hate these datasheets            01/01/70 00:00      
                                       BULL            01/01/70 00:00      
                                          get it RIGHT before you deviate from spec's            01/01/70 00:00      
                                       OK... I give up...            01/01/70 00:00      
                                    8 bit Initialization            01/01/70 00:00      
                                       lcd problem            01/01/70 00:00      
                                          program i used            01/01/70 00:00      
                                             driving voltage            01/01/70 00:00      
                                                its not the contrast problem            01/01/70 00:00      
                                                   why?            01/01/70 00:00      
                                                   Contrast and Initialization            01/01/70 00:00      
                                             you are, I hope, aware            01/01/70 00:00      
                                       That's the one...thanks            01/01/70 00:00      
   about P0            01/01/70 00:00      
      It shows that you "experiment" instead of reading            01/01/70 00:00      
      gibberish            01/01/70 00:00      
   small correction            01/01/70 00:00      
      thanks a lot            01/01/70 00:00      
         Thanks for informing us.            01/01/70 00:00      
            so, next time            01/01/70 00:00      

Back to Subject List