Find help, specifications and source code for the LPC900. The LPC900 challenges Microchip and AVR based on the worlds most popular 8-bit architecture the 80C51. With a 2-clock core the LPC900 series is a high performance, very flexible and low cost 8-bit microcontroller family. Designers using or interested in these devices are encouraged to share their know-how and ask questions.
IAP-lite ? - Fred - Jun 16 8:33:49 2006
Hi.
I am using the following code, mostly from the datasheets. I simply
want to write a byte in flash. I cannot test this code using my Keil
emulator, it is not supported. Now, I have flashed the code on a
PLC922, and call this routine. I know that the code doesn't return an
error because the PLC922 is resetted. However, the byte is NOT written
in flash...
Does anybody see something wrong here ? Do I have to set the KEY
(0x86) at address 0xFF before doing this ?
Any help is appreciated !
Thanks,
-Frederic
;;;
;;; flash_write : routine to write bytes to the PIC flash
;;;
;;; Parameters :
;;; - AddrH : address high
;;; - AddrL : address low
;;; - ByteCount : number of bytes to program
;;; - R0 : pointer to data
;;;
;;; Returns :
;;; - R7 : status byte
;;; - C : clear on no error, set on error
;;;
;;; NOTE: The emulator EPM900 from Keil DOES NOT emulate IAP-lite.
;;;
sfr FMCON = 0xE4
sfr FMADRH = 0xE7
sfr FMADRL = 0xE6
sfr FMDAT = 0xE5
flash_write:
#if EMULATOR == 1
CLR C ; emulator doesn't support IAP-lite
RET
#endif
CLR EA ; disable interrupts
MOV FMCON, #0x00 ; load command
MOV FMADRH, AddrH ; set address
MOV FMADRL, AddrL
load_page:
MOV FMDAT, @R0
INC R0
DJNZ ByteCount, load_page
MOV FMCON, #0x68 ; start erase/program cycle
SETB EA ; re-enable interrupts
MOV R7, FMCON ; get result
MOV A, R7
ANL A, #0x0F ; only 4 lower bits are significant
JNZ flash_bad
CLR C ; no error
RET
flash_bad:
SETB C ; set error
RET

(You need to be a member of LPC900_users -- send a blank email to LPC900_users-subscribe@yahoogroups.com )
Re: IAP-lite ? - zhongyongbofly - Jun 16 23:45:59 2006
try this one,please!
;**************************************************
;* pgm user code *
;**************************************************
;* Inputs:acc,dptr
;* Outputs:A
;* c=3D0 ok,c=3D1 error
;**************************************************
PGM_USER:
MOV FMCON,#LOAD ;load command, clears page register
MOV FMADRH,dph ;get high address
MOV FMADRL,dpl ;get low address
MOV FMDATA,a ;write data to page register
MOV FMCON,#EP ;else erase & program the page
MOV A,FMCON ;copy status for return
ANL A,#0FH ;save only four lower bits
JNZ BAD ;
CLR C ;clear error flag if good
RET ;and return
BAD:=20=20=20=20=20
SETB C ;set error flag
RET ;and return
;**************************************************
;**************************************************
; name:RD_BYTE=20
; function:read one byte from e2
; input:DPTR
; output:the read data save to ACC=20
; occupied:ACC,DPTR,C
;**************************************************
RD_BYTE:=20=20=20=20=20=20=20=20=20=20=20
CLR A
MOVC A,@A+DPTR=20=20=20=20
RET
Best Regards=A3=A1
Frank
--- In l...@yahoogroups.com, "Fred"
wrote:
>
> Hi.=20
>=20
> I am using the following code, mostly from the datasheets. I simply
> want to write a byte in flash. I cannot test this code using my Keil
> emulator, it is not supported. Now, I have flashed the code on a
> PLC922, and call this routine. I know that the code doesn't return=20
an
> error because the PLC922 is resetted. However, the byte is NOT=20
written
> in flash...
>=20
> Does anybody see something wrong here ? Do I have to set the KEY
> (0x86) at address 0xFF before doing this ?
>=20
> Any help is appreciated !
>=20
> Thanks,
>=20
> -Frederic
>=20
>=20
>=20
> ;;;
> ;;; flash_write : routine to write bytes to the PIC flash
> ;;;
> ;;; Parameters :
> ;;; - AddrH : address high
> ;;; - AddrL : address low
> ;;; - ByteCount : number of bytes to program
> ;;; - R0 : pointer to data
> ;;;
> ;;; Returns :
> ;;; - R7 : status byte
> ;;; - C : clear on no error, set on error
> ;;;
> ;;; NOTE: The emulator EPM900 from Keil DOES NOT emulate IAP-lite.
> ;;;=20=20=20=20=20=20=20
>=20
> sfr FMCON =3D 0xE4
> sfr FMADRH =3D 0xE7
> sfr FMADRL =3D 0xE6
> sfr FMDAT =3D 0xE5
>=20=09=09
> flash_write:
> #if EMULATOR =3D=3D 1
> CLR C ; emulator doesn't support IAP-
lite
> RET
> #endif
> CLR EA ; disable interrupts
> MOV FMCON, #0x00 ; load command
> MOV FMADRH, AddrH ; set address
> MOV FMADRL, AddrL
> load_page:
> MOV FMDAT, @R0
> INC R0
> DJNZ ByteCount, load_page
> MOV FMCON, #0x68 ; start erase/program cycle
> SETB EA ; re-enable interrupts
> MOV R7, FMCON ; get result
> MOV A, R7
> ANL A, #0x0F ; only 4 lower bits are significant
> JNZ flash_bad
> CLR C ; no error
> RET
> flash_bad:
> SETB C ; set error
> RET
>
=20
=20
=20

(You need to be a member of LPC900_users -- send a blank email to LPC900_users-subscribe@yahoogroups.com )Re: IAP-lite ? - zhongyongbofly - Jun 17 0:01:40 2006
try this one,please!(fixed)
;==========================================================
;define IAP_Lite SFR
sfr FMCON = 0xE4
sfr FMADRH = 0xE7
sfr FMADRL = 0xE6
sfr FMDAT = 0xE5
;==========================================================
;define FLASH iap-lite control command
LOAD EQU 00H ; load command
EP EQU 68H ; start erase/program cycle
;==========================================================
;**************************************************
;* pgm user code *
;**************************************************
;* Inputs:acc,dptr
;* Outputs:A
;* c=0 ok,c=1 error
;**************************************************
PGM_USER:
MOV FMCON,#LOAD ;load command, clears page register
MOV FMADRH,dph ;get high address
MOV FMADRL,dpl ;get low address
MOV FMDATA,a ;write data to page register
MOV FMCON,#EP ;else erase & program the page
MOV A,FMCON ;copy status for return
ANL A,#0FH ;save only four lower bits
JNZ BAD ;
CLR C ;clear error flag if good
RET ;and return
BAD:
SETB C ;set error flag
RET ;and return
;**************************************************
;**************************************************
; name:RD_BYTE
; function:read one byte from e2
; input:DPTR
; output:the read data save to ACC
; occupied:ACC,DPTR,C
;**************************************************
RD_BYTE:
CLR A
MOVC A,@A+DPTR
RET
;**************************************************
Frank

(You need to be a member of LPC900_users -- send a blank email to LPC900_users-subscribe@yahoogroups.com )