Hey everyone,
I recently purchased an ADuC847 eval board, and am very green when it comes to coding in assembly and/or C. I have several questions when it comes to figuring out the code syntax, and small details which I'm most likely missing. I'm trying to figure out how to take three different analog measurements and output them (~1sec delay) in an ASCII character string such as (AxxxxxByyyyyCzzzzz). I've got the output looking like this so far: AxxxxxxByyyyyyCzzzzzz. If someone could advise me on how to reduce the x,y,z outputs from 6 to 5, hopefully without causing inaccurate readings, that would be great.
The other issue I'm having is that I am struggling with turning on the other analog inputs of the device, or if I turn them on, its displaying the same measurement three times. The code that I have placed below is very basic, and was started with the example code that came with the software.
I've also tried to write a delay program, but insofar I've only got it to freeze after outputting the string. Thoughts? The code doesn't include an attempt to turn on the other analog inputs, I originally tried it in using only ASM51, but have since switched to C and am not sure how to proceed with accomplishing that task.
My code is as follows:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <ADuC847.h> //Some of these include files may not be necessary sbit LED = 0x0B4; void delay(int); void ADC_int () interrupt 6 { LED ^= 1; printf("\n\n"); printf("A%bX%bX%bX",ADC0H,ADC0M,ADC0L); //This will output 21 ASCII digits. printf("B%bX%bX%bX",ADC0H,ADC0M,ADC0L); //Needs to be reduced to 19 characters printf("C%bX%bX%bX",ADC0H,ADC0M,ADC0L); //Need to reduce from 21 characters to 19 for(;;) { P3 ^= 0x10; delay(10); } } void delay(int length) { while (length >=0) length--; } void main (void) { //Configure UART PLLCON = 0x90; T3CON = 0x82; //115200 Baud rate T3FD = 0x2D; SCON = 0x52; //CONFIGURE ADC AND START CONVERTING.... ICON = 0x01; //Turn on IEXC1 source to drive RTD. SF = 0x200; ADC0CON1 = 0x22; //Full Buffer, Unipolar, 80mV range. ADC0CON2 = 0x4A; //Refin+/-, Ain1->Ain2 EADC = 1; //Enable ADC Interrupt EA = 1; //Enable Global Interrupts ADCMODE = 0x23; // continuous conversion on Main channel on main channel //WAIT FOR INTERRUPTS.... while(1); }The following is the output:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <ADuC847.h> //Some of these include files may not be necessary sbit LED = 0x0B4; void delay(int); void ADC_int () interrupt 6 { LED ^= 1; printf("\n\n"); printf("A%bX%bX%bX",ADC0H,ADC0M,ADC0L); //This will output 21 ASCII digits. printf("B%bX%bX%bX",ADC0H,ADC0M,ADC0L); //Needs to be reduced to 19 characters printf("C%bX%bX%bX",ADC0H,ADC0M,ADC0L); //Need to reduce from 21 characters to 19 for(;;) { P3 ^= 0x10; delay(10); } } void delay(int length) { while (length >=0) length--; } void main (void) { //Configure UART PLLCON = 0x90; T3CON = 0x82; //115200 Baud rate T3FD = 0x2D; SCON = 0x52; //CONFIGURE ADC AND START CONVERTING.... ICON = 0x01; //Turn on IEXC1 source to drive RTD. SF = 0x200; ADC0CON1 = 0x22; //Full Buffer, Unipolar, 80mV range. ADC0CON2 = 0x4A; //Refin+/-, Ain1->Ain2 EADC = 1; //Enable ADC Interrupt EA = 1; //Enable Global Interrupts ADCMODE = 0x23; // continuous conversion on Main channel on main channel //WAIT FOR INTERRUPTS.... while(1); }
The A,B,C are required as part of my task so I cannot simply rid my code of the output here.
I'll do what I can to answer any questions you all have. Thanks for your time.
Perhaps you should separate learning the 'C' programming language, from learning about microcontrollers ?
I would certainly suggest that it's easier to get to grips with the 'C' programming language on a PC - away from all the extra baggage, complications, and restrictions of embedded microcontrollers.
Here are some 'C' learning/reference resources:
http://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/
Once you have mastered the 'C' programming language, then you can focus on the embedded microcontroller stuff ...
Keil have some learning resources here:
http://www2.keil.com/mdk5/learn