Date: 08/11/05 (Algorithms) Keywords: no keywords [Error: Irreparable invalid markup (' I have just started learning microcontrollers.
Can someone help me to provide the program (C) of the following steps: 1. Configure and enable the ATD (i.e. Analog to Digital) subsystem of the Motorola HCS12 (ATDCTL2, 3, 5). 10 Bit accuracy should be used. 2. Trigger conversions on 4 channels of the ATD. 3. Wait for the 4 conversions to be completed. 4. Print the 4 results on the screen on a single line as numbers in the range 0 to 5 Volts. 5. Wait a short while. 6. Return to step 2. The C program will be run on IAR Embedded Workbench for 68HC12. Below is my C program (with comments) to the above steps. I think I'm wrong. Thank you for correcting me. Also, I can't do step 5. #include typedef unsigned char U8; typedef unsigned int U16; #define ATDCL2 (*(volatile U8*)0x0082) #define ATDCL3 (*(volatile U8*)0x0083) #define ATDCL4 (*(volatile U8*)0x0084) #define ATDCL5 (*(volatile U8*)0x0085) #define ATDSTAT0 (*(volatile U8*)0x0086) #define ATDDR (*(volatile U16*)0x0090) void delay (int time) { while (time-->0); } void ADC_convert (void); void main (void) { /* Step 1 */ ATDCTL2 = 0x80; ATDCTL3 = 0x00; ATDCTL4 = 0x01; ADC_convert (); } void ADC_convert (); { while(1) /* Step 6 */ { ATDCTL5 = 0x03; /* Step 2 */ while ((ATDSTAT0 & 0x8000) != 0x8000) {;} /* Step 3 */ printf ("%x %x %x %x\n", ATDDR[1], ATDDR[2], ATDDR[3], ATDDR[4]); /* Step 4 */ } } Source: http://www.livejournal.com/community/algorithms/62745.html
|