I created a code to read from 8 channels from dspic30f6014a using UART1. Currently I'm using ccs c compiler ver 5.010 and win10 platform. The code compiled and there was no error. However in hyper terminal no values are displayed. I compared with other code using 18F4580 (SK40C) to display 8 values from adc channels and it works. What caused this problem? Did I miss something important here? Both devices are using UC00A and UIC00B.
TQ
- CODE: SELECT_ALL_CODE
[code]#include <dspic30f6014A uart 9600 wo start char.h>
#use rs232(baud=9600, xmit=PIN_F3,rcv=PIN_F2,Bits=8, ERRORS)
#fuses FRC, NOWDT, NOPROTECT, PUT64, BORV27 //correct - Power On Reset Timer value 64ms, Brownout reset at 2.7V
#define LED PIN_B10
int z;
void main()
{
setup_adc_ports(ALL_ANALOG); // Built-in A/D setup function
setup_adc(ADC_CLOCK_INTERNAL); // Built-in A/D setup function
const int8 channel[] = 0, 1, 2, 3, 4, 5, 6, 7;
int16 ADC_value[sizeof(channel)];
int8 value;
int16 voltage[sizeof(channel)];
while(TRUE)
{
for(z = 0; z < 1; z++)
{
// read from 8 channels ADC
for(value = 0; value < sizeof(channel); value++) // Read from 8 adc channels
{
output_high(LED);
set_adc_channel(channel[value]);
ADC_value[value] = read_adc(); // ADC readings
voltage[value] = ADC_value[value] * (5000 / 255); // Convert ADC data to mV
}
// Print all ADC data
for(value = 0; value < sizeof(channel); value++) // Display 8 voltage values
{
printf("%4.3w\r\n", voltage[value]); //format data in .000
}
printf("9\r\n"); //'9' is display at each end of 8 values
}
}
}
[/code]
- CODE: SELECT_ALL_CODE
#include <18F4580.h>
#device ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,bits=8, ERRORS)
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_8);
const int8 channel[] = 0, 1, 2, 3, 4, 5, 6, 7;
int16 ADC_value[sizeof(channel)];
int8 value;
int16 voltage[sizeof(channel)];
int z;
SETUP_ADC_PORTS(ALL_ANALOG);
output_low(PIN_B6);
output_low(PIN_B7);
while(TRUE)
{
while(TRUE)
{
for(z = 0; z < 1; z++)
{
output_low(PIN_B6);
// Collect all ADC data
for(value = 0; value < sizeof(channel); value++) // Read from 8 adc channels
{
set_adc_channel(channel[value]);
ADC_value[value] = read_adc(); // ADC readings
voltage[value] = ADC_value[value] * (5000 / 255); // Convert ADC data to mV
output_high(PIN_B7);
}
// Print all ADC data
for(value = 0; value < sizeof(channel); value++) // Display 8 voltage values
{
printf("%4.3w\r\n", voltage[value]);
}
printf("9\r\n");
}
}
}
}