/**************************************************** / Program: 8 channel A/D Input / Name: ada4evb.c / Date: 30 May 2002 / By: Jake Gamage / The code was adapted from the assembly language program / written by Steven J. Dombrowski called ada4evb.asm / / This program scans all 8 A/D channels on the / M68HC12A4EVB and continually updates all readings. / / To execute this program type G 5000 /****************************************************/ #include #include #include int __main() { int count = 100; /* Set the A/D Power Up bit */ _H12ADTCTL2 = 0x80; /* Set A/D converter up for 8 conversions, scan on,and multiple channels */ _H12ADTCTL5 = 0x70; while(1) { /* The printf statements take care of the A/D reads. The first part of the printf statement is the %c\b. The code is here because of an error in the D-Bug12 implementation of printf. In the D-Bug error, the first variable that is printed will always be a gargabe character. In order to get around this, %c prints the first character and \b performs a backspace, deleting the garbage character. You might still see the garbage character flash briefly before being deleted. */ DB12->printf("%c\breading\tAD0:%3d\tAD1:%3d\tAD2:%3d\tAD3:%3d\n\r", _H12ADR0H,_H12ADR1H,_H12ADR2H,_H12ADR3H); DB12->printf("%c\breading\tAD4:%3d\tAD5:%3d\tAD6:%3d\tAD7:%3d\r", _H12ADR4H,_H12ADR5H,_H12ADR6H,_H12ADR7H); /* 0x0B is the terminal code for moving the cursor up one line */ DB12->putchar(0x0B); /* This countdown code clears the screen every 100 iterations. It was added because the serial line screws up sometimes and shifts the lines around. This will reset everything so the line shifts won't accumulate and make the output unreadable. */ count--; if(!count) { count = 100; /* 0x1A is the terminal code to clear the screen and move the cursor to the home position */ DB12->putchar(0x1A); } } }