Sample code and data HEX files for programming the Atmel AT89S8252

Sample code was assembled using MetaLink's asm51 version 1.2h

Sample source file for data to be programmed into the eeprom of the 8252.

cr		equ	0dh
lf		equ	0ah

		org	0
		db	'This is a test text file',cr,lf
		db	'to be programmed into the',cr,lf
		db	'eeprom in the Atmel 8252',cr,lf,'$'
		end

HEX file generated by assembly.

:100000005468697320697320612074657374207467
:100010006578742066696C650D0A746F20626520CE
:1000200070726F6772616D6D656420696E746F20A8
:100030007468650D0A656570726F6D20696E207455
:1000400068652041746D656C20383235320D0A24A4
:00000001FF

Sample program file to display on a terminal the contents of a text string stored in the 8252's eeprom.

;Program to display a text string stored in the 8252's eeprom.
;Peter Averill 1-7-1999
;
$mod8252

CR		EQU	0dh		; carriage return
LF		EQU	0ah		; line feed

BAUD_9600	EQU	0fdh		; 9600 baud


		DSEG AT 20h

		ORG	60h		; stack origin
stack:		DS	20h		; stack depth


		CSEG

		ORG	0000h		; power on/reset vector
		jmp	main

		ORG	0003h		; external interrupt 0 vector
		reti			; undefined

		ORG	000Bh		; timer 0 overflow vector
		reti

		ORG	0013h		; external interrupt 1 vector
		reti			; undefined

		ORG	001Bh		; timer 1 overflow vector
		reti			; undefined

		ORG	0023h		; serial I/O interrupt vector
		jmp	serial_int


		ORG	40h		; begin constant data space
mess:           DB      CR,LF,LF,LF,LF,LF,LF,LF,LF,LF,LF,LF,LF,LF,LF,LF
		db	LF,LF,LF,LF,LF,LF,LF,LF,LF,LF
		db	'Atmel AT89C8252 Eeprom test program',LF,CR
		db	'___________________________________',LF,CR
		db	'Written by Peter Averill   1-7-1999',LF,LF,LF,CR
		db	0

; begin code space

		USING	0		; register bank zero
main:
		mov	sp, #(stack-1)	; initialize stack pointer
		call	initialize	; initialize controller registers


		setb	TI		; set transmit interrupt flag
					;   (kludge for first use)
m1:		mov     dptr, #mess
		call    send_string
		mov	dptr,#0
		call	e_string
		call	get_char
		jmp	m1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e_string:

	; Transmit string pointed to by DPTR in eeprom.
	; String may be of any length, but must be '$' terminated.

		push	acc
		push	dpl
		push	dph
		mov	wmcon,#0ah	;setbit eemem so movx accesses
					;eeprom
es1:
		clr	a
		movx	a, @dptr	; get character
		cjne	a,#'$',es2	; check for terminator
		jmp	es3
es2:		call	send_char	; send character

		inc	dptr		; point to next character
		jmp	es1
es3:
		pop	dph
		pop	dpl
		pop	acc
		ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
serial_int:

		clr	F0		; clear connect flag
		clr	TI		; clear transmit interrupt flag

		jnb	RI, si2		; exit if not receive data ready

		mov	a, SBUF		; get character into accumulator

		setb	F0		; set connect flag
		clr	RI		; reset receive flag
	si2:
		reti

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
initialize:

	; Initialize controller registers and I/O lines.

		mov	PCON, #0	; initialize power control register
		mov	IE, #0		; deactivate all interrupts

		mov	SCON, #01000000b	; serial port mode one
		mov	TMOD, #00100001b	; timer one 8-bit auto-reload,
						;   timer zero 16-bit
		mov	TH1, #BAUD_9600		; timer one reload value
		mov	TCON, #01000000b	; start timer one

		setb	REN		; enable serial reception
		setb	EA		; global interrupt enable

		ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
send_string:

	; Transmit string pointed to by DPTR.
	; String may be of any length, but must be null-terminated.

		push	acc
		push	dpl
		push	dph
	ss1:
		clr	a
		movc	a, @a+dptr	; get character
		jz	ss2		; check for terminator

		call	send_char	; send character

		inc	dptr		; point to next character
		jmp	ss1
	ss2:
		pop	dph
		pop	dpl
		pop	acc
		ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
send_char:

		jnb	TI, $		; wait here for transmitter to clear
		clr	TI		; clear transmit flag
		mov	SBUF, a		; load character into transmitter
		ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_char:

		jb	RI, gc2		; jump if char is waiting
	gc1:
		jnb	RI, gc1		; exit loop when char received
	gc2:
		mov	a, SBUF		; get character into accumulator
		clr	RI		; reset receive flag
		ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
delay_ms:

	; Delay for one millisecond times the value in the accumulator.

		push	acc
		push	b

		mov	b, #0
	dd:
		djnz	b, $		; 500 uS @ 12 MHz
		djnz	b, $		; 500 uS @ 12 MHz
		djnz	acc, dd

		pop	b
		pop	acc
		ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
delay_sec:

	; Delay for one second times the value in the accumulator.

		push	acc
		push	b

		mov	b, a
	ddd:
		mov	a, #250
		call	delay_ms	; 250 mS
		call	delay_ms	; 500 mS
		call	delay_ms	; 750 mS
		call	delay_ms	; 1000 mS

		djnz	b, ddd

		pop	b
		pop	acc
		ret


		END

HEX file generated by assembly.

:040000000200CC32FC
:01000B0032C2
:0100130032BA
:01001B0032B2
:03002300020103D4
:100040000D0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0D
:100050000A0A0A0A0A0A0A0A0A0A41746D656C2029
:1000600041543839433832353220456570726F6DEE
:1000700020746573742070726F6772616D0A0D5F12
:100080005F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F80
:100090005F5F5F5F5F5F5F5F5F5F5F5F5F5F5F5F70
:1000A0005F5F0A0D5772697474656E206279205023
:1000B000657465722041766572696C6C2020203110
:1000C0002D372D313939390A0A0A0D0075815F1231
:1000D0000111D2999000401201289000001200E511
:1000E00012014780EFC0E0C082C08375960AE4E049
:1000F000B424030200FC12013FA380F2D083D0821B
:10010000D0E022C2D5C299309806E599D2D5C298DE
:100110003275870075A800759840758921758DFD29
:10012000758840D29CD2AF22C0E0C082C083E493E5
:10013000600612013FA380F6D083D082D0E0223047
:1001400099FDC299F599222098033098FDE599C24E
:100150009822C0E0C0F075F000D5F0FDD5F0FDD5D7
:10016000E0F7D0F0D0E022C0E0C0F0F5F074FA3152
:0F01700052315231523152D5F0F3D0F0D0E0225B
:00000001FF
5 :10013000600612013FA380F6D083D082D0E0223047 :1001400099FDC299F599222098033098FDE599C24E :100150009822C0E0C0F075F000D5F0FDD5F0FDD5D7 :10016000E0F7D0F0D0E022C0E0C0F0F5F074FA3152 :0F01700052315231523152D5F0F3D0F0D0E0225B :00000001FF