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.

Intio OSC very disturbing.....

Status
Not open for further replies.

hhhsssmmm

New Member
Hello

Im trying to get the internal OSC to work @ 8MHz on PIC18F1220. Im using C18 compiler. Below is my program and it uses the internal OSC. The program simply latchs HIGH and LOW 8 LEDs that are all connected to PORTB. Sadly this NEVER happens. Upon power up nothing seems to work and my LEDs do not flash. I have tested my PIC board and MCLR pin is pulled HIGH and VDD and VSS are correctly provided a clean and stable 7805 +5V / 0V supply. I have also tried changing the PIC to another 18F1220 but no luck there either.

Please can someone take a look at my below program and kindly suggest why my PIC does not do what the program below tells it to do.

Thank you

Haseeb

Code:
#include <p18f1220.h>
#include <delays.h>  
  
#pragma config OSC = INTIO1 //using Internal OSC
#pragma config WDT = OFF 
#pragma config LVP = OFF 

//defining below the LED outputs
#define LED1 LATBbits.LATB0
#define LED2 LATBbits.LATB1
#define LED3 LATBbits.LATB2
#define LED4 LATBbits.LATB3
#define LED5 LATBbits.LATB4
#define LED6 LATBbits.LATB5
#define LED7 LATBbits.LATB6
#define LED8 LATBbits.LATB7


void main(void)
{  	 

	 //Internal Oscillator Frequency @ 8MHz
	 OSCCONbits.IRCF2 = 1;
	 OSCCONbits.IRCF1 = 1;
	 OSCCONbits.IRCF0 = 1;		  
 
	 ADCON1 = 0b11111111; //All channels Digital		
	
	 PORTA = 0; //intialize PORTA  

	 PORTB = 0; //intialize PORTB

	 TRISB = 0x00; //PORTB as all OUTPUT	 

	 INTCON = 0;  //Disable all interrupts
	

	while(1) //loop forever
	{ 

		//MAKE all LEDs turn on 
		LED1 = 1;
	 	LED2 = 1; 
     	LED3 = 1;
     	LED4 = 1; 
     	LED5 = 1;
     	LED6 = 1; 
     	LED7 = 1;	
		LED8 = 1;	

		Delay10KTCYx(100); //500ms delay @ 8MHz

		//MAKE all LEDs turn off
		LED1 = 0;
	 	LED2 = 0; 
     	LED3 = 0;
     	LED4 = 0;
     	LED5 = 0;
     	LED6 = 0;
     	LED7 = 0;
		LED8 = 0;			 

		Delay10KTCYx(100); //500ms delay @ 8MHz

	}
 


} //end of main()
 

AtomSoft

Well-Known Member
Code:
    OSCCON = 0x72;              //8MHz clock
    while(!OSCCONbits.IOFS);    //Wait for OSC to become stable
OR
Code:
	 OSCCONbits.IRCF2 = 1;
	 OSCCONbits.IRCF1 = 1;
	 OSCCONbits.IRCF0 = 1;	
	 while(!OSCCONbits.IOFS);    //Wait for OSC to become stable

so should be:

Code:
#include <p18f1220.h>
#include <delays.h>  
  
#pragma config OSC = INTIO1 //using Internal OSC
#pragma config WDT = OFF 
#pragma config LVP = OFF 

//defining below the LED outputs
#define LED1 LATBbits.LATB0
#define LED2 LATBbits.LATB1
#define LED3 LATBbits.LATB2
#define LED4 LATBbits.LATB3
#define LED5 LATBbits.LATB4
#define LED6 LATBbits.LATB5
#define LED7 LATBbits.LATB6
#define LED8 LATBbits.LATB7


void main(void)
{  	 

	 //Internal Oscillator Frequency @ 8MHZ and Wait for Stable
	 OSCCON = 0x72;              
	 while(!OSCCONbits.IOFS);
 
	 ADCON1 = 0b11111111; //All channels Digital		
	
	 PORTA = 0; //intialize PORTA  

	 PORTB = 0; //intialize PORTB

	 TRISB = 0x00; //PORTB as all OUTPUT	 

	 INTCON = 0;  //Disable all interrupts
	

	while(1) //loop forever
	{ 

		//MAKE all LEDs turn on 
		LED1 = 1;
	 	LED2 = 1; 
     	LED3 = 1;
     	LED4 = 1; 
     	LED5 = 1;
     	LED6 = 1; 
     	LED7 = 1;	
		LED8 = 1;	

		Delay10KTCYx(100); //500ms delay @ 8MHz

		//MAKE all LEDs turn off
		LED1 = 0;
	 	LED2 = 0; 
     	LED3 = 0;
     	LED4 = 0;
     	LED5 = 0;
     	LED6 = 0;
     	LED7 = 0;
		LED8 = 0;			 

		Delay10KTCYx(100); //500ms delay @ 8MHz

	}
 


} //end of main()
 
Last edited:

hhhsssmmm

New Member
thank you so much...

i have just tried all that u have said but i progressed ZERO...nothing happend and the results are the same in that my LEDs will simply not flash.

plz can you help me?

thank you

Haseeb
 

be80be

Well-Known Member
It should work what programmer are you using? sounds like what bill said not setting fuse's
 

hhhsssmmm

New Member
Hey thanks....

problem is now solved!!

it was the bloody programmer....i then later used MP3 programmer from microchip...and PRESTO

it works now beatifully...

so a lesson for all......plz use a good programer such as the MP3 from microchip when using the Internal OSC.

Haseeb
 

be80be

Well-Known Member
I use a pickit2 it works good it will tell if you didn't set them.
 

AtomSoft

Well-Known Member
Just to let you know you code would work without
Code:
	 while(!OSCCONbits.IOFS);

But if you are doing something time sensitive i recommend waiting until its stable before working.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top