#define begin { #define end } #include #include #include void initialize(); char p_ready; unsigned long present_sector; unsigned int i,j; //********************************************* interrupt [EXT_INT1] void extint1(void) begin // set flag to indicate that data is ready to read on // the parallel bus p_ready = 1; end //********************************************* void main() begin initialize(); i = 0; j = 0; // wait for the start byte on the parallel port (0xff) while (PINC.1 == 0) begin PORTB.3 = 1; // toggle the interrupt delay_us(50); PORTB.3 = 0; delay_us(50); end PORTB.3 = 1; p_ready = 0; delay_us(50); PORTB.3 = 0; while(1) begin if (p_ready) begin PORTB.3 = 1; // clear parallel interrupt sector_array_AD[j] = PINC; // read parallel bus j++; // increment parallel counter p_ready = 0; // clear flag PORTB.3 = 0; // interrupt to indicate read is finished end if (j == 512) // after reading a full sector of data begin PORTB.1 = 1; // toggle an LED to show SD card activity SD_Write((unsigned long)(400+i)<<9); // write to SD starting at sector 400 i++; // increment sector counter j = 0; // reset counter PORTB.1 = 0; // toggle LED end end end //********************************************************** void initialize() begin char result = 1; // SPI ISR disabled, SPI enabled, MSB first, master, SCK = 8MHz SPCR = 0b01010000; SPSR.0 = 1; // trigger external INT0 in falling edge of INT0 (MCUCR.1,0 = 10) // trigger external INT1 in falling edge of INT1 (MCUCR.3,2 = 10) MCUCR |= 0x0A; GICR = 0b10000000; // D.1 output for TXD, D.0 input for RXD DDRD = 0b00000010; // B.7 output SCK, B.6 input MISO, B.5 output MOSI, B.3 output for parallel interrupt, B.2 is CS for SD DDRB = 0b10111110; DDRC = 0x00; //Port C is the paralell input port // initialize CS high PORTB.2 = 1; p_ready = 0; while (result != 0) result = SD_Reset(); // reset the SD card #asm("sei") end