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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/13/06 10:32
Read: times


 
#126377 - ehm....
Responding to: ???'s previous message
Arvind Shrivastava said:
                       org    2010h

Why???
'51 starts executing program after reset from 0000h, doesnt' it?
Arvind Shrivastava said:
	FIRMWARE_BIT equ 010h   ;flag for checking whether the program is 
			      ; exceuting for the forst time or not
				      ; 0 for first time executing 


I thought you want to keep this flag in non-volatile memory = FLASH, won't you? Then, you need to choose a space for it so that it won't get into conflict with the software. I wouldn't put it at 0010h, as the interrupt vectors are there, so if you want to use them in the future it would interfere. It does not matter if you put it below 2000h or above 2000h; the whole APPLICATION FLASH (Block 0) is treated by the IAP in the same way.

Of course, if stored in FLASH, you cannot simply test it by jb/jnb instruction. You need to fetch it from the code memory (=FLASH) using MOVC into accumulator, and THEN test it in accumulator.

Also, you can chose the default value of the flag simply by putting it in the source as data. Then it would get burned together with the rest of code, to be prepared for the first time usage. I would suggest you to have the default ("intact") value = 00h and store it in the same page than the password (say, at address 327Fh - I assume the password will be less than 128 bytes long); so that if you erase the flash page to reprogram the password, the flag gets automatically complemented.

So if we assume you will do it as I described above, store the flag at position 327Fh and the password from 3200h; you will include into source code the following to get the initial value of the flag:
    ORG   327f
FIRMWARE_FLAG:
    db    0

and the startup algorithm would be the following:
  • reset (0000h, jump to "Start")
  • get the flag from 327F using MOVC
  • if flag is zero, it means "first time", go to "enter new password" routine
  • otherwise go to "get password" routine; if password match, start application otherwise loop back to "get password" (maybe also limiting nr of attempts?)
  • after correct password is entered: in running application, if user requires to change password, go to enter new password routine

  • Enter new password routine:
    • read in user's password (into RAM)
    • perform page erase of page 3200h (call IAP with dptr=3200 and r1=08) - this also automatically complements the flag
    • repeatedly call "program byte" IAP function, incrementing dptr & putting individual bytes of password from buffer into A

  • Check password routine:
    • read in user's password (into RAM) - this is the same as with enter new password so you can make it a subroutine
    • read in the password byte by byte using MOVC from address 3200 (no need to use IAP function 03, that is really redundant), compare with buffer and if no match, return "failed"
    • if match, return "passed"



This is the general picture; I will comment on the rest of your code but that's only to point out some of your errors.

However, I'd recommend you to restart from scratch based on my description above.

Arvind Shrivastava said:
	mov	r4, #080h	; LSB of 3200h
	mov	r5, #0c0h	; MSB of 3200h

OK so you intend to store the password in 3200h, so why do you use c080h? Your comments should reflect reality... And also the comments should say, WHAT THE HELL is 3200h...

Arvind Shrivastava said:
		org  3200h
	sjmp	START

Nono, don't put another org here... How is the processor supposed to walk from the previous instruction to here?

Arvind Shrivastava said:
FLASH_SUBROUTINE:
[... etc.]


OK, now general comments on FLASH_SUBROUTINE:
  • it's fine that you included watchdog check/disable, although we can talk about proper usage of watchdog more... But for now, it's fine. I'd store cmod on the stack (using push/pop) rather than in r2 (you should not assume the IAP preserves your registers).
  • DON'T mix application functionality into this routine! Use it only as an interface, i.e. perform the checks, registe4r fills etc. elsewhere (in the "main"), and then call this!


Arvind Shrivastava said:
	mov	dpl, #r4
	mov	dph, #r5

This is a classical technical error; the assembler should throw an error on this (but this error it has also a more dangerous form, when an actual variable reference is used, which cannot be detected by the assembler). You wanted to write:
	mov	dpl, r4
	mov	dph, r5


Arvind Shrivastava said:
; will I have to call the IAP for four times, unlike I have
' called once below

Yes.


---
I hope this helped to make an another step forward...

Jan Waclawek



List of 50 messages in thread
TopicAuthorDate
how to write in EEPROM in P89V51RD2 ?            01/01/70 00:00      
   there is no such thing as an EEPROM            01/01/70 00:00      
   eh?            01/01/70 00:00      
      I mean FLASH ...            01/01/70 00:00      
         FlashMagic            01/01/70 00:00      
            I have flash magic            01/01/70 00:00      
               that IS what FlashMagic does            01/01/70 00:00      
                  All of them ...            01/01/70 00:00      
                     I'm at a loss            01/01/70 00:00      
                  Probs is password storing ...            01/01/70 00:00      
                     you have not, see above            01/01/70 00:00      
                        just give me an idea            01/01/70 00:00      
                           datasheet            01/01/70 00:00      
                     clear question will help            01/01/70 00:00      
         read the ... datasheet            01/01/70 00:00      
            P89V51 IAP (access)            01/01/70 00:00      
         Unfortunate terminology!            01/01/70 00:00      
   I read data sheet            01/01/70 00:00      
      read about IAP!!!            01/01/70 00:00      
         IAP code example...            01/01/70 00:00      
            this is NOT for P89V51RD2!            01/01/70 00:00      
               Use 89S52 / 89S8252            01/01/70 00:00      
                  I\'d guess...            01/01/70 00:00      
            few questions ...            01/01/70 00:00      
               Do you read my posts?            01/01/70 00:00      
   I have tried but failed ...            01/01/70 00:00      
      corrupted???            01/01/70 00:00      
         Dont know            01/01/70 00:00      
            How do you know that they are corrupted?            01/01/70 00:00      
            Refer the application notes for the P89V51RD2            01/01/70 00:00      
               Detail Problem ...            01/01/70 00:00      
                  think!            01/01/70 00:00      
                     program ...            01/01/70 00:00      
                        ehm....            01/01/70 00:00      
                           Well confused!            01/01/70 00:00      
                              one has to start somewhere...            01/01/70 00:00      
                                 Flowcharts            01/01/70 00:00      
                                    I don't think it's a good idea...            01/01/70 00:00      
                        Jan ... Guide me more            01/01/70 00:00      
                           where to place the code            01/01/70 00:00      
                  BIBLE TIME            01/01/70 00:00      
                     BASICs            01/01/70 00:00      
                        A very basic question            01/01/70 00:00      
                           to Arvind            01/01/70 00:00      
                           if you mean BASIC52/RD2 v1.4beta4...            01/01/70 00:00      
      the dangers of uncharted waters withou a pilots            01/01/70 00:00      
         maybe            01/01/70 00:00      
            I would not dare that            01/01/70 00:00      
               sunset...            01/01/70 00:00      
                  Mr. Shrivastava you are Wasting other's time            01/01/70 00:00      

Back to Subject List