/* NAME: C-code for 121 Prototype Board Testing CODE: ANSI-C for 68HC11A0 TOOLS: Whitesmiths c-compiler ver 3.02 FILE: test.c AUTHOR: S.C. Petersen REV: 1.0 Fall-99/scp 2.0 Spring-2000/scp This is a simple test program to be used as a first checkout of your lab prototype board. An infinite loop writes ascii characters from 0h to 255h out the serial port and to the embedded HC11 Port-D, which can be used to verify program execution independent of the serial port. */ #include #include #define TDRE 0x80 /* Transmit Ready Bit */ #define RDRF 0x20 /* Receive Register Full Bit */ #define RDRF_W_ERRS 0x2E /* RDRF + OR + NF + FE */ #define MISO 0x04 #define MOSI 0x08 #define FIFO_SZ 0x1000 const unsigned char ready[] = "\r\nI'm completely operational, and all my circuits are functioning perfectly.\r\n"; _PORT char px @0x7000; _PORT char py @0x7800; unsigned char x, y; unsigned char tic, ptic; unsigned char ticks[ 3 ]; //sec min hr unsigned int ihead, itail; //add chars to tail, read from head //head points to valid char, tail points to unused char //if head == tail then no chars! unsigned char ififo[ FIFO_SZ ]; unsigned int ohead, otail; unsigned char ofifo[ FIFO_SZ ]; @interrupt void tick() { TOC2 = TCNT + 0xf415; /* 0xf424 - 0xe (cycles to service ISR) - 0x1 (average latency) */ TFLG1 = 0x40; /* clear OC2F bit */ ++tic; if( tic & 0x01 ) ++ticks[ 0 ]; // divide-by-two if( ticks[ 0 ] > 59 ) { ticks[ 0 ] = 0; ++ticks[ 1 ]; if( ticks[ 1 ] > 59 ) { ticks[ 1 ] = 0; ++ticks[ 2 ]; if( ticks[ 2 ] > 23 ) { ticks[ 2 ] = 0; } //t2 } //t1 } //t0 return; } @interrupt void scisr() { if( ( SCSR & RDRF_W_ERRS ) == RDRF ) { if( itail != ( ihead - 1 ) ) { ififo[ itail ] = SCDR; ++itail; if( itail >= FIFO_SZ ) itail = 0; } } else if( SCSR & TDRE ) { if( ohead != otail ) { SCDR = ofifo[ ohead ]; ++ohead; if( ohead >= FIFO_SZ ) ohead = 0; } if( ohead == otail ) //if FIFO is empty { ohead = 0; otail = 0; //reset pointers SCCR2 = SCCR2 & 0x7f; //clear Transmit Interrupt Enable bit } } return; } int putchar( char c ) { _asm("sei"); //mask interrupts for this call if( ( otail == ohead ) && ( SCSR & TDRE ) ) //if FIFO and SCI Tx buffer are empty { SCDR = c; //write to the port } else if( otail != ( ohead - 1 ) ) //else ensure FIFO isn't full { ofifo[ otail ] = c; //and write to the FIFO ++otail; if( otail >= FIFO_SZ ) otail = 0; } _asm("cli"); SCCR2 = SCCR2 | 0x80; //set Transmit Interrupt Enable bit return c; } int getchar() { if( ihead != itail ) { _asm("sei"); //mask interrupts for this case x = ififo[ ihead ]; ++ihead; if( ihead >= FIFO_SZ ) ihead = 0; _asm("cli"); } else { ihead = 0; itail = 0; //reset pointers x = 0; //return NULL } return( x ); } void main(void) { /* initialize fifos */ ihead = 0; itail = 0; ohead = 0; otail = 0; /* initialize Port D Data Direction Register */ DDRD = ( DDRD & 0xfb ) | 0x08; // PORTD = PORTD & 0xf7; //clear MOSI /* enable Receiver Interrupt Enable */ SCCR2 = SCCR2 | 0x20; putchar( 0x1b ); putchar( 0x5b ); putchar( 0x3f ); putchar( 0x37 ); putchar( 0x68 ); //enable auto wrap to new line puts( ready ); /* main event loop */ while( 1 ) { x = getchar(); if( x != 0 ) { putchar( x ); if( x == 'J' ) { putchar( 'A' ); putchar( 'S' ); putchar( 'O' ); putchar( 'N' ); } } else if( ticks[ 0 ] != ptic ) { ptic = ticks[ 0 ]; /* output time *************************************************************/ putchar( 0x1b ); putchar( 0x37 ); //save cursor position //send cursor to 0;70 putchar( 0x1b ); putchar( 0x5b ); putchar( '0' ); putchar( ';' ); putchar( '7' ); putchar( '0' ); putchar( 0x48 ); printf( "%2d:%02d:%02d", ticks[2], ticks[1], ticks[0] ); putchar( 0x1b ); putchar( 0x38 ); //restore cursor position /***************************************************************************/ } } // end while( 1 ) }