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.

Need help on PIC18F2220

Status
Not open for further replies.

vdd

New Member
I am new in PIC18 family. At the moment I am trying to program a PIC18F2220, using 4 MHz internal oscillator. I am using Hi-Tec C compiler. Seems like there's no INTIO configuration bit or word in Hi-Tec C. I don't know how to configure for internal OSC in the configuration word. All I can do is set up OSCCON register 0b01100000. But it doesn't work. I think I have to set up the configuration word as well. Can someone please help.
 

vdd

New Member
I got confused. The setting for internal OSC actually works. The actual problem is the PIC doesn't response to delay routine. I try to make a LED blinks by turning on the LED, delay and turn off, and repeat.But the LED just stays on all the time. But if I use the simulator and put a stop watch on to monitor the time delay, it actual shows the delay function is working (delay time is about half second).
I 've tried using internal and external OSC, same result.
I still think the settup in the configuration still not right.

Please help....
 

kchriste

New Member
Forum Supporter
Post your code and use the code tags.
 

vdd

New Member
Here are the codes:

#include <pic18.h>

//#include "clk_freq.h"
//#include "delay.c"
//#include "delay.h"
//#include "always.h"
//#include "clk_freq.h"

//#define PIC_CLK 4000000


__CONFIG(1,XT);
__CONFIG(2,BORDIS & PWRTDIS & WDTDIS);
__CONFIG(4,LVPDIS);


void c_delay(int x)
{
int y;

while (x--)
{
for(y=0; y<100; y++)
{
NOP(); //do nothing for 10 cycles.
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
}
}
}


void main (void)

{
int i;

//OSCCON= 0b00000000;
TRISC= 0; //PortC = output
PORTC= 0;
i= 100;

while(1)
{

PORTC= 0b00000001;
c_delay(i);
PORTC= 0b00000010;
c_delay(i);
PORTC= 0b00000100;
c_delay(i);
PORTC= 0b00001000;
c_delay(i);

}

}


I have tried using Delay routine from Hi-tech C, but same result.
If the delay is short, say 10ms, then all LED will light up. If the delay is more than 100ms, then only the first LED will light up, the other LED will remain off.
Any idea why? Please help. :confused:
 

vdd

New Member
I found the problem. I think there's something wrong with the USB port with my old PC. The project was built on bread board and powered by 5v via the PICKit2 and the USB port. When I connect the project to a different PC and problem's gone. Strange thing is the old PC has connected many different PIC before and never had any trouble, and why only on PIC18F2220 but not on PIC18F252. Even now with the PIC18F2220 and the new PC, when I stand in front of it and my shadow covered the bread board, the LED would not scroll for half a second then continue. Very strange.
:confused: :confused::confused:
 

kchriste

New Member
Forum Supporter
Do you have a 0.1uF capacitor connected across the PICs power supply pins? Keep it as close as possible to the PIC. Weird symptoms like you are describing are sometimes caused by omitting power rail bypass caps. Do you have a pullup resistor on MCLR? Another possibility is dodgy breadboard connections. That usually is only a problem on older, well worn, breadboards in my experience.
 
Last edited:
Status
Not open for further replies.

EE World Online Articles

Loading
Top