Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I feel silly, but....

Status
Not open for further replies.
okay, configured as advised, but still getting the same results.
here's the configuration I put into setting:
**broken link removed**

Please advise. And oh, by the way, my programming using ASM works. MikroC's not. :eek:
 
As I said, I don't use MikroC so can't be of any more help. Maybe you could try C18 or BoostC as these are both free.

Mike.
 
Does MikroC generate an .asm file that you have access to? If it does, compare the assembly instructions and see what the difference might be.
 
Yes it does make an ASM file.

I think it's probably hardware related, ie xtal not plugged in, LEDs turned off, MCLR pin not handled correctly etc.

Hi, I'm not sure if it's actually hardware related, since my ASM ADC-reading code works just well. I suppose I just have to tweak around the code and see if there's anything else wrong with it...
 
Your oscillator frequency should be 48mhz not 20mhz


**broken link removed**

You also need to set ADCON1 right.
 
Last edited:
Your oscillator frequency should be 48mhz not 20mhz


**broken link removed**

You also need to set ADCON1 right.

Hi, thanks for the input. I put the value of ADCON1=0X0F, I suppose that should set all of the pins as output, yeah?
Also, can you explain why I need it to be 48 MHz? I'm not using it for USB purposes at the moment.
 
ALLRIGHT..... it's settled.
Code:
C:
void main() {
PORTB=0;
LATB=0;
ADCON0=0B00111100;
ADCON1=0B00001111;
TRISB=0B00000000;
PORTB=0B11111111;
while(1);
}

Picture: **broken link removed**

Thanks to Mike (Pommie) and Mr RB and to all too.
Whew!!!

Vizier87
 
Hey, glad to see its working. As a side note:

PORTx is usually used to read a port
LATx is usually used to set a port HIGH or LOW

Its good to get used to it this way. Just more proper. :D

Also its safer to setup the port then the data like:

Code:
void main() {
  ADCON0 = 0B00111100;
  ADCON1 = 0B00001111;

  LATB = 0;
  TRISB = 0B00000000;
  LATB = 0B11111111;
  
  while(1);
}
 
Last edited:
Hi, thanks for the input. I put the value of ADCON1=0X0F, I suppose that should set all of the pins as output, yeah?
Also, can you explain why I need it to be 48 MHz? I'm not using it for USB purposes at the moment.

I posted why I don't no where it went but any way Your using a 20 mhz crystal you divided it by 5 that gives the 4 mhz that's scaled to 96 then divided by 2

which is 48 mhz it's not 20mhz If you want 20 set the FOSC to HS only

One more thing you can turn off the A/D on PORTB in the configure to

bit 1 PBADEN: PORTB A/D Enable bit
(Affects ADCON1 Reset state. ADCON1 controls PORTB<4:0> pin configuration.)
1 = PORTB<4:0> pins are configured as analog input channels on Reset
0 = PORTB<4:0> pins are configured as digital I/O on Reset
 
Last edited:
I posted why I don't no where it went but any way Your using a 20 mhz crystal you divided it by 5 that gives the 4 mhz that's scaled to 96 then divided by 2

which is 48 mhz it's not 20mhz If you want 20 set the FOSC to HS only

One more thing you can turn off the A/D on PORTB in the configure to

Whoa. Okay I'll see to it. Thanks Be80be. :)
 
I'm sure I said to set the postscaler to divide by 4 which would give you 24MHz.

Mike.
 
I'm sure I said to set the postscaler to divide by 4 which would give you 24MHz.

Mike.
Hi Mike, yeah, the one which worked is according to the settings you suggested. Thanks.
However I'm not sure if the setting suggested by be80be might also work just as fine. As for now I'm trying to get the rest of the pins to turn on as well, which needs some relatively tricky tweaking with the code as well. I'll get to the pre-post-scaler part when I'm done testing the rest of the I/O pins of my PIC.

Vizier87.
 
I'm sure I said to set the postscaler to divide by 4 which would give you 24MHz.

Mike.

I went back and looked your using a divide by 4 which gives a 24Mhz like Mike said But in your pic you show 20 which is wrong it will make thing like uart not work and things with timing

The reason I said divide by 2 is that's the default setting for the PIC18F2455/2550/4455/4550 in MikroC sorry about that

I been using the start usb which has the 18f2550 on it which uses the same setting
 
Last edited:
I went back and looked your using a divide by 4 which gives a 24Mhz like Mike said But in your pic you show 20 which is wrong it will make thing like uart not work and things with timing

The reason I said divide by 2 is that's the default setting for the PIC18F2455/2550/4455/4550 in MikroC sorry about that

I been using the start usb which has the 18f2550 on it which uses the same setting

Thanks for the input be80be. I'll consider the configuration when I get to the Timer part.
 
Okay guys, now for the PORTA pins. I've read the PORTA register pretty carefully.... so please tell me what I missed. :eek:

Code:
 void main() {
CMCON=0B00000111;
UCON=0B00010000;
ADCON0=0B00111100;
ADCON1=0B00001111;
CVRCON=0;
LATA=0B000000;
TRISA=0B000000;
PORTA=0B111111;

while(1); }

Anyway, I think some of the values I put to the registers might be wrong, but I'm not sure. Here's an overview of the association with PORTA:
**broken link removed**
 
Last edited:
Hi Atomsoft, thanks for the feedback.
What's the reason behind the orientation anyway?
Seems you cleared LATB first and then put it all on HIGH. :)

Vizier87

its a habit mostly, but if your controlling a LCD for instance you rather have it clear before sending it data this way you dont send the wrong data.
 
Status
Not open for further replies.
Back
Top