#include #include #include unsigned char getmem(unsigned int addr){ unsigned char data = 0x00; //delay_us(1); DDRA = 0x00; // set data lines to read //delay_us(1); PORTB = (unsigned char)((addr & 0xff00) >> 8); //PORTB.1 = 1; //delay_us(1); PORTC = (unsigned char)(addr & 0x00ff); //delay_us(1); PORTD.3 = 1; // set to read //delay_us(1); #asm("nop"); #asm("nop"); data = PINA; //delay_us(1); return data; } void setmem(unsigned int addr, unsigned char value){ DDRA = 0xff; // set data lines to write //delay_us(1); PORTB = (unsigned char)((addr & 0xff00) >> 8); //PORTB.1 = 1; //delay_us(1); PORTC = (unsigned char)(addr & 0x00ff); //delay_us(1); PORTA = value; //delay_us(1); PORTD.3 = 0; // set to write //delay_ms(1); PORTD.3 = 1; // set back to read (for video) //delay_us(1); DDRA = 0x00; // set data lines to read again //delay_us(1); } void main(){ unsigned long i = 0; unsigned char data; unsigned int num_errors = 0; UBRRL = 103 ; //sets UART baud rate, using a 16 MHz crystal this is 9600 baud DDRD = 0xff; DDRB = 0xff; DDRC = 0xff; PORTD.2 = 0; // initialize interrupts UCSRB = 0b00011000 ; // enables usart transmit and receive, and TXempty interrupt delay_ms(50); UDR = 'H'; delay_ms(5); //while(1){ /*for(i = 0; i < 65536; i++){ setmem(i,0xff); } */ for(i = 0; i < 65536; i++){ setmem(i,(unsigned char)i); } PORTA = 0xff; for(i = 0; i < 65536; i++){ // setmem(i,(unsigned char)0xff); // setmem(i,0); //delay_us(1); data = getmem(i); //data = getmem(i); // UDR = data; // delay_ms(1); /*UDR = data; delay_ms(2);*/ if(data != (unsigned char)i)//(unsigned char)i) { //UDR = data; //setmem(i,0); /*while(0 != data){ data = getmem(i); UDR = data; num_errors++; }*/ num_errors++; //delay_ms(5); UDR = data; delay_ms(5); UDR = (unsigned char)(i>>8); delay_ms(5); UDR = (unsigned char)i; delay_ms(5); } /*else{ UDR = 0; }*/ } UDR = num_errors >> 8; delay_ms(5); UDR = num_errors; delay_ms(5); UDR = 0 ; delay_ms(5); UDR =0; delay_ms(5); UDR = 0; delay_ms(5); UDR = 0; delay_ms(5); UDR = 0; delay_ms(5); //} }