#include #include #include #include #pragma config WDT = OFF, OSC = INTIO2, LVP = OFF, MCLRE = OFF void main (void); void Write6850Status(const char); void Write6850Data(const char); char Read6850Status(void); char Read6850Data(); void OutChar(const char); char InChar(void); void OutString(const rom char*); char ReadRAM(const char); void WriteRAM(const char, const char); void OutHex(const char); void OutOct(const char); #define RD PORTAbits.RA5 //not RD #define WR PORTAbits.RA6 //nor WR #define IOM PORTAbits.RA7 //IO/not M #define MCUALE PORTCbits.RC0 //Address latch enable output #define MCUS1 PORTCbits.RC1 //S1 output //echo program: //const rom char buf[] = {076, 03, 0323, 020, 076, 021, 0323, 020, 0333, 020, 017, 0322, 010, 00, 0333, 021, 0323, 021, 0303, 010,00}; //const int NumBytes = 21; //12k basic bootloader: const rom char buf[] = {076, 03, 0323, 020, 076, 021, 0323, 020, 041, 0302, 077, 061, 032, 00, 0333, 020, 017, 0320, 0333, 021, 0275, 0310, 055, 0167, 0300, 0351, 013, 000}; const int NumBytes = 28; const rom char hexchar[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; //---------------------------------------------------------------------------- void main (void) { char i, j; // OSC settings OSCCONbits.IRCF2 = 1; //Set osc to be 8 MHZ OSCCONbits.IRCF1 = 1; //OSCCON<2:0> = 111; OSCCONbits.IRCF0 = 1; // PORTC = 0x40; //HOLD = 1, not RESET = 0 TRISC = 0x00; //all outputs PORTA = 0xF0; //A11:A8 = 0, RD, WR, IO/M = 1 TRISA = 0x00; //All outputs PORTB = 0; //A15:A12 = 0 TRISB = 0xF0; //A16:A12 outputs, rest inputs PORTD = 0; TRISD = 0xFF; //All inputs //turn off analog ADCON1 = 0x0F; //all digital I/O // set up PWM for 9600 Baud rate clock output OpenTimer2(TIMER_INT_OFF & T2_PS_1_1); OpenPWM1(12); SetDCPWM1(26); Delay100TCYx(100); //10000 cycles Write6850Status(003); //master reset Write6850Status(021); //X16 clock, 8 bits, 2 stop bit OutString("\n\rWelcome to the Mini-Altair!\n\r"); i = 0; while (i < NumBytes) { OutString("\n\r"); OutOct(i); //address OutString(": "); for (j = 0; j < 8; ++j) { WriteRAM(i, buf[i]); OutOct(ReadRAM(i++)); if (i > NumBytes) break; OutChar(' '); } } OutString("\n\r"); Delay100TCYx(100); //10000 cycles TRISA = 0xFF; //all inputs TRISB = 0xFF; //all inputs PORTD = 0; TRISE = 0x17; //enable PSP, port E all inputs PORTC = 0x82; //MCUALE = 0, MCUS1 = 1, HOLD = 0, not RESET = 1; while(1); //wait forever } void Write6850Status(const char stat) { MCUS1 = 0; //write PORTD = 020; //register 0, status TRISD = 0; //enable data output MCUALE = 1; //pulse ALE to latch low byte of address MCUALE = 0; IOM = 1; //IO port WR = 0; //enable PORTD = stat; //write data WR = 1; TRISD = 0xFF; //disable output } void Write6850Data(const char data) { MCUS1 = 0; //write PORTD = 021; //register 1, data TRISD = 0; //enable data output MCUALE = 1; //pulse ALE to latch low byte of address MCUALE = 0; IOM = 1; //IO port WR = 0; //enable PORTD = data; //write data WR = 1; TRISD = 0xFF; //disable output } char Read6850Data() { char a; MCUS1 = 1; //read PORTD = 021; //register 1, data TRISD = 0; //enable data output MCUALE = 1; //pulse ALE to latch low byte of address MCUALE = 0; TRISD = 0xFF; //input IOM = 1; //IO port RD = 0; //enable a = PORTD; //read RD = 1; return a; } char Read6850Status() { char a; MCUS1 = 1; //read PORTD = 020; //register 0, status TRISD = 0; //enable data output MCUALE = 1; //pulse ALE to latch low byte of address MCUALE = 0; TRISD = 0xFF; //input IOM = 1; //IO port RD = 0; //enable a = PORTD; //read RD = 1; return a; } void OutChar(const char c) { while ((Read6850Status() & 0x02) == 0); //wait for tx buffer empty Write6850Data(c); //output character } char InChar() { while ((Read6850Status() & 0x01) == 0); //wait for rx buffer full return Read6850Data(); //input character } void OutString(const rom char* s) { while(*s) OutChar(*s++); } char ReadRAM(const char address) { char a; PORTD = address; TRISD = 0; //enable data output MCUALE = 1; //pulse ALE to latch low byte of address MCUALE = 0; TRISD = 0xFF; //input IOM = 0; //memory RD = 0; //enable a = PORTD; //read RD = 1; return a; } void WriteRAM(const char address, const char data) { PORTD = address; //register 1, data TRISD = 0; //enable data output MCUALE = 1; //pulse ALE to latch low byte of address MCUALE = 0; IOM = 0; //memory WR = 0; //enable PORTD = data; //write data WR = 1; TRISD = 0xFF; //disable output } void OutHex(const char c) { OutChar(hexchar[c >> 4]); OutChar(hexchar[c & 0x0F]); } void OutOct(const char c) { OutChar(hexchar[c >> 6]); OutChar(hexchar[0x7 & (c >> 3)]); OutChar(hexchar[0x7 & c]); }