??? 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 |