hayawana
Member level 1
- Joined
- Apr 10, 2013
- Messages
- 35
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,524
this is my code I'm stuck in the adc part I'll explain what I do:
I have 7 analog channels to be converted:
AN0: need to be *4
AN1:
AN2:
AN3: need to be * 50
AN4: need to be * 50
AN5: need to be *4
AN6: need to be *4
but in the simulation all channels are correct except for 50 ?? here is my code
I have 7 analog channels to be converted:
AN0: need to be *4
AN1:
AN2:
AN3: need to be * 50
AN4: need to be * 50
AN5: need to be *4
AN6: need to be *4
but in the simulation all channels are correct except for 50 ?? here is my code
Code:
unsigned char lowbyte;
unsigned char highbyte;
unsigned char medbyte;
unsigned int conversion1 ;
unsigned int TAB[24][7];
unsigned int conversion[12];
void main()
{
int i= 0;
/////////Initialization//////////////////
ADCON1=0x03; //VSS,VDD, ALL ANi are analog except for AN12
ADCON0=0x01; //select AN0
ADCON0=0x05; //select AN1
ADCON0=0x09; //select AN2
ADCON0=0x0D; //select AN3
ADCON0=0x11; //select AN4
ADCON0=0x15; //select AN5
ADCON0=0x19; //select AN6
ADCON2=0xAD; //Right justified, 12TAD, 16TOSC
TRISA=0xFF; // set trisA as inputs
TRISE=0b1111; // set trisE as inputs
ADON_bit=1; // enable conversion
UART1_Init(9600); // Initialize hardware UART1 and establish communication at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
/////////ADC CONVERSION///////////////////
while(1)
{
for( i=0 ;i<7;i++)
{
conversion[12] = ADC_Read(i); // Read analog value from channel 0 to 6
if( i == 0 || i == 5 || i == 6)
TAB[24][i]= conversion[12]*4;
if( i == 3|| i == 4 )
TAB[24][i]= conversion[12]*30;
if( i ==1 || i == 2 )
TAB[24][i]= conversion[12];
lowbyte= TAB[24][i]>>16;
medbyte = TAB[24][i]>> 8;
highbyte= TAB[24][i];
UART1_Write(lowbyte);
UART1_Write(medbyte);
UART1_Write(highbyte);
delay_100ms() ;
delay_100ms() ;
delay_100ms() ;
delay_100ms() ;
delay_100ms() ;
delay_100ms() ;
delay_100ms() ;
}
}
}