/* TrikiBoard RamTest. checks 32K SRAM and glows motor1 Led if OK
else lights up Motor 2 Led */

#include <reg52.h>
#define maxdata 0x8000

sbit mot1a      = P1^4;  //give sensible names to portpins. 
sbit mot1b	= P1^5;  //these 4 pins control motors 
sbit mot2a	= P1^6;   
sbit mot2b	= P1^7;   

unsigned char xdata dat[0x8000];  //define an array in external RAM.
               //size of this array is 32KBytes, so it fills all xRAM

bit RamCheck()
{
//try to make as many varibles as unsigned CHAR, since they take 1byte
//then unsigned int, instead of int if -ves are needed. optimize like an
//Elec engineer and save memory.
unsigned int i; 
unsigned char val=0;

bit err=0;
for(i=0; i<maxdata; i++)
  {
  dat[i] = val; //save numbers in mem
  val++;
  }

val=0;
for(i=0; i<maxdata; i++)
 { 
  if(dat[i] != val) err=1;
  val++;
 }
 
return err;
}

void main()
{

bit abc;

while(1)
{
abc = RamCheck();

if(abc == 0) 
  {
   P1 = 0; //switch off all 
   mot1a = 0;  //mot1 led on  -RAM ok
   mot1b = 1;
  }
else 
 { P1 = 0; 
   mot2a = 0;
   mot2b = 1;
 } 
} //while(1) repeat infinite
}


