Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

18F4610 won't flash LED appropriately

Status
Not open for further replies.

PomPom

Junior Member level 3
Junior Member level 3
Joined
Oct 9, 2012
Messages
28
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,522
below is my full code.


Code:
#include <p18f4610.h>

#pragma config OSC = INTIO67 //Internal oscillator, xtal becomes output
#pragma config WDT = OFF //Turn off watch dog timer
#pragma config LVP = OFF //LVP off

int i;

void main(void){

	OSCCON = 0b01110000; //8MHZ clock 
	OSCTUNEbits.PLLEN = 0b1; //enable PLL
	//Enable internal oscillator

	TRISA=0x00;
	TRISB=0x00;
	TRISC=0xFF;
	TRISD=0x00;
	i = 0;

	while(1){
		if(i < 10000){
			LATDbits.LATD2 = 1;
			LATDbits.LATD3 = 1;
			i++;}
		else{
			LATDbits.LATD2 = 1;
			LATDbits.LATD3 = 0;
		}	
	}
}

Basically it should have two LEDs turned on, then after some amount of time it should only have 1.

With i<10000 it works fine, can barely see the transition. at i < 20000 it seems to be about twice as slow, though still very quick. by the time I get to i<40000 [2x from before] it never transitions.

What am I doing wrong here? I plan on eventually using interrupts but am using this to test some code. I haven't programmed a PIC in a while but it's meant to turn on a MOSFET or BJT to switch on a much larger array of LEDs.

So my main issue is why doesn't this incrementing stuff work, and if you guys can point me to some simple timer example code (just to know when to turn off LEDs, eg interrupt every 1ms)

Thank you much
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top