Could you help me to write this code to eject the cdrom ? void write_atapi(unsigned char bytelow, unsigned char bytehigh) { TRISA = 0b00000000; // All ports A are output TRISB = 0b00000000; // All ports B are output TRISE = 0b00000000; // All ports E are output TRISC = 0b00000000; // All ports C are output TRISD = 0b00000000; // All ports D are output RA1 = 0; // CS0 RA0 = 1; // CS1 RE0 = 1; // DA0 RE1 = 1; // DA1 RE2 = 1; // DA2 PORTD = bytehigh; PORTC = bytelow; RA3 = 1; // W DelayMs(1); RA3 = 0; // W } void read_atapi(int cs0, int cs1, int da0, int da1, int da2, unsigned char bytelow, unsigned char bytehigh) { TRISA = 0b00000000; // All ports A are output TRISB = 0b00000000; // All ports B are output TRISE = 0b00000000; // All ports E are output TRISC = 0b11111111; // All ports B are input TRISD = 0b11111111; // All ports D are input RA1 = cs0; // CS0 RA0 = cs1; // CS1 RE0 = da0; // DA0 RE1 = da1; // DA1 RE2 = da2; // DA2 RA2 = 1; // R bytelow = PORTC; bytehigh = PORTD; RA2 = 0; // R } void check_status() { unsigned char bytelow; unsigned char bytehigh;
while(1) { read_atapi(1, 0, 1, 1, 1, bytelow, bytehigh): //try 10011 if (bytelow == 7) DelayMs(1); else if (bytelow == 3) DelayMs(1); else break; } } void open_tray() { check_status(); write_atapi(0x1e, 0x00); write_atapi(0x00, 0x00); write_atapi(0x00, 0x00); write_atapi(0x00, 0x00); write_atapi(0x00, 0x00); write_atapi(0x00, 0x00); check_status(); write_atapi(0x1b, 0x00); write_atapi(0x00, 0x00); write_atapi(0x02, 0x00); write_atapi(0x00, 0x00); write_atapi(0x00, 0x00); write_atapi(0x00, 0x00); } void cdrom() { RA5 = 1; // Reset high open_tray(); }
Andrea Ciuffoli www.audiodesignguide.com
|