I am doing an ADC12 conversion and sending this value to ADC12MEM0. Once the ADC12 is complete, I am sending the ADC12MEM0 values upper and lower 8 bits to the hyperterminal. I understand that it is simply sending the hex values in the register over as ascii, but I would like to display these values as hex on the hyperterminal. I would like to copy the register exactly as it appears to the hyperterminal (0x0FFF on ADC12MEM0 would make hyperterminal display 0x0FFF... etc.). I have looked at hex to ascii tables and I understand how this works, but I have no idea how to write this as code in code composer studio. Is there some advice you could give me or an example code I can look at to better understand. Below I have provided my code. Thanks!
# include <msp430xG46x.h>
volatile unsigned int temp;
volatile unsigned int i;
void main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog
// Initialization of ADC12//
P6SEL |= 0x01; // Enable A/D channel A0
ADC12CTL0 &= ~ENC;
ADC12CTL0 = ADC12ON + SHT0_2 + REFON + REF2_5V+MSC; // turn on ADC12, set samp time
ADC12CTL1 = SHP+CONSEQ_2; // Use sampling timer
ADC12MCTL0 = SREF_1 + INCH_0; // Vr+=VeREF+ (external)
ADC12CTL0 |= ENC; // Enable conversions
// Initialization of Rs-232//
FLL_CTL0 |= XCAP14PF; // Configure load caps
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
//_delay_cycles(50000); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
P2SEL |= 0x30; // P2.4,5 = USCI_A0 RXD/TXD
UCA0CTL1 |= UCSSEL_1; // CLK = ACLK
UCA0BR0 = 0x03; // 32k/9600 - 13.65
UCA0BR1 = 0x00; //
UCA0MCTL = 0x06; // Modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0TXIE + UCA0RXIE; // enable RXD and TXD interrupt;
while (1)
{
// ADC loop //
ADC12CTL0 |= ADC12SC; // Start conversions
//while (!(ADC12IFG & 0x0001)); // Conversion done?
temp = ADC12MEM0; // Move result
__no_operation(); // SET BREAKPOINT HERE
// RS-232 loop //
UCA0TXBUF = temp; // send lower part
__no_operation();
//while(!(IFG2 & UCA0TXIFG))
//{
//_delay_cycles(1000); // wait for first transmit
//}
UCA0TXBUF = temp >> 8;// send upper part
__no_operation();
// _delay_cycles(1000);
//UCA0TXBUF = temp;
}
}