How to set ADC of 18F452

Thread Starter

ssm14293

Joined Jul 14, 2011
90
yes i did...(posted above) even the code where i did not use PIC_setting(); instead wrote the whole code (previous page) did not work... is the IC burnt or am i doing something wrong?
 
Last edited:

Thread Starter

ssm14293

Joined Jul 14, 2011
90
what should be MCLR state when the pic turns on... no POR... i guess this is where i messed up...
further more... there are 2 Vdd and Vss pins, the one on analog side is necessary to wire up?
i guess this is what i should have asked earlier... -.-'
 

t06afre

Joined May 11, 2009
5,934
Do you have some premade demo board. Or do you use your circuit built on some self made platform? If you have made test circuit by your self can post the schematic
 

Thread Starter

ssm14293

Joined Jul 14, 2011
90
this is my present schematic... blinking LED.. just for checking... im using proteus... advice any other one please...

Rich (BB code):
void PIC_setting(void){
 ADRESH = 0x00;
 ADRESL = 0x00;
 ADCON0 = 0x44;
 ADCON1 = 0x06;
 TRISA = 0x00;
 TRISB = 0x00;
 TRISC = 0x00;
 TRISD = 0x00;
 TRISE = 0x00;
}

void main() {
   PIC_setting();
   while (1){
         PORTA = 0x01;
         delay_ms(1000);
         PORTA = 0x00;
         delay_ms(100);
   }
}
 

Attachments

t06afre

Joined May 11, 2009
5,934
I can not see anything from your picture it is way to fuzzy. First for testing only. Use internal oscillator and disable the MCLR pin. Do this in the config settings. Then check your data sheet. And apply power/GND to all the pins used for this purpose. And your LED need a series resistor. Do not connect a LED directly to MCU port ever. I would say a resistor in range about 300 ohm. Should do fine
 

Thread Starter

ssm14293

Joined Jul 14, 2011
90
I can not see anything from your picture it is way to fuzzy. First for testing only. Use internal oscillator and disable the MCLR pin. Do this in the config settings. Then check your data sheet. And apply power/GND to all the pins used for this purpose. And your LED need a series resistor. Do not connect a LED directly to MCU port ever. I would say a resistor in range about 300 ohm. Should do fine
It dosent have an internal oscillator and how will i disable the MCLR pin? via program or hardware? if in program than how in hardware. i have a resistor of 220 ohm on board may be i missed it here...
Thanks
 

t06afre

Joined May 11, 2009
5,934
It dosent have an internal oscillator and how will i disable the MCLR pin? via program or hardware? if in program than how in hardware. i have a resistor of 220 ohm on board may be i missed it here...
Thanks
Forget it. My bad. Since it was a 18F chip I was quite sure it has those functions. But your chip was introduced before these functions become standard
 

Thread Starter

ssm14293

Joined Jul 14, 2011
90
honestly speaking.... i dont know... i re-wrote the code gave vcc to MCLR pin and it started to work... :D
back to my original question... ADC help... :p
 

Thread Starter

ssm14293

Joined Jul 14, 2011
90
is this the right setting for ADCON0 and ADCON1 for AN0 as analog only...
ADCON0 = 0xC5;
ADCON1 = 0xCE;

im using 8Mhz Crystal....
 

Thread Starter

ssm14293

Joined Jul 14, 2011
90
can anyone please tell me that this code for UART tx is correct? Please!

Rich (BB code):
void PIC_setting(void){
 ADRESH = 0x00;
 ADRESL = 0x00;
 ADCON0 = 0xC5;
 ADCON1 = 0xCE;
 TRISA = 0x00;
 TRISB = 0x00;
 TRISD = 0x00;
 TRISE = 0x00;
 UART1_init(9600);
}
char read;
void main() {
   PIC_setting();
   delay_ms(100);
   while (1){
         PORTA = ~PORTA;
         UART1_write_text("U%");
         delay_ms(500);
         UART1_write_text("U%");
         delay_ms(500);
         UART1_write_text("L%");
         delay_ms(500);
         UART1_write_text("L%");
         delay_ms(500);
         UART1_write_text("D%");
         delay_ms(500);
         UART1_write_text("D%");
         delay_ms(500);
         UART1_write_text("R%");
         delay_ms(500);
         UART1_write_text("R%");
         delay_ms(500);
   }
}
if yes then why my PIC is not giving an output...
 
Top