Path: Home => AVR-Overview => Hardware => RAM

; TestRam tests external SRAM on the STK-200 board

; ************************************************
; TestRam tests external SRAM on the STK200 board
; Counts SRAM-positions by writing AAh and 55h
; in each position, verifies the content and displays
; the MSB of the highest SRAM-adress on the LEDs.
; ************************************************

; Explanation on the RAM access
; The MUX-IC 74HC573 and the SRAM 62256-70 have to be
; installed on the board.
; Port A is multiplexed adress bus for the LSB adress and the
; data bus
; Port C is the upper adress bus
; Port D Bit 6 is /RD (Read) on the SRAM, Bit 7 is /WR (Write)
; Line ALE (Adress Latch Enable) is used, Pin 30 of the 8515
; If the whole external SRAM has been tested ok, all LEDs are
; switched on except LED7. The highest adress then is
; 7FFFh, if a 32 kB SRAM is used.

; 8515-definitions

.NOLIST
.INCLUDE "8515def.inc"
.LIST

; Registers

.def   mp = R16 ; Multi-Purpose
.def   soll = R17 ; AA or 55 for test

; Reset-/Interrupt-Vector

   RJMP   main

; Main program

main:   LDI   mp,LOW(RAMEND) ;Initiate Stackpointer
   OUT   SPL,mp ; for subroutines
   LDI   mp,HIGH(RAMEND)
   OUT   SPH,mp

; Port B drives the LEDs

   LDI   mp,0xFF ; All outputs
   OUT   DDRB,mp ; to data direction register

   IN   mp,MCUCR ; Read MCU-Control-Register
   ORI   mp,0x80 ; Set Bit 7
   OUT   MCUCR,mp
; If the SRAM used is slower than 70 ns and therefore requires an
; additional WAIT-state, then Bit 6 has to set additionally. The
; ORI command then must be ORI mp,0xC0 to set bit 6, too.

   LDI   XL,LOW(RAMEND) ; Register XL is R26, LSB RAM-Adress
   LDI   XH,HIGH(RAMEND) ; Register XH is R27, MSB RAM-Adress

   LDI   soll,0b10101010 ; Bit pattern for Test

loop:
   INC   XL
; Inc adress
   BRNE   check ; Not zero, MSB ok
   INC   XH ; Inc MSB of Adress
   BREQ   check ; Zero, MSB overflow, skip
check:
   ST   X,soll
; write Bitpattern to SRAM
   LD   mp,X ; Read the same location
   CP   mp,soll ; Compare written and read
   BRNE   Zurueck ; Not equal, skip
   COM   soll ; Invert bit pattern (XOR FF)
   ST   X,soll ; write 0101.0101
   LD   mp,X ; Read back
   CP   mp,soll ; compare
   BRNE   Zurueck ; Not equal, skip
   COM   soll ; invert
   RJMP   loop ; next location

Zurueck:
   LD   mp,-X
; Decrement Pointer X
Ungleich:
   COM   XH
; XOR FF of MSB
   OUT   PORTB,XH ; to the LEDs
ende:   RJMP   ende ; Loop forever


©2002 by http://www.avr-asm-tutorial.net