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.

Turn All LEDs ON (Explorer 16)

Status
Not open for further replies.

drkidd22

Member
I have written a simple code to have all LEDs to turn 'ON' on the explorer 16. There seems to be an issue somewhere that is causing D9 to turn off while all other LEDs remain 'ON'. If I set any two of the PORTA pins that control the LEDs to LOW all LEDs seem to work properly and D9 turns on. The only way I can get all of them ON at the same time is if I set all PORTA pins that control the LEDs HIGH, but that's not the way I'm trying to do it.

Code:
void InitPorts() 
{
	LATA = 0xFF00;
	TRISA = 0xFF00;
	AD1PCFGH = 0xFFFF;
 }

void InitClock()
{

	PLLFBD = 38;			// M = 40
	CLKDIVbits.PLLPOST = 0;	// N1 = 2
	CLKDIVbits.PLLPRE = 0;	// N2 = 2
	OSCTUN = 0;
	RCONbits.SWDTEN = 0;

// This will switch the FRC clock to use external; XTPLL
	__builtin_write_OSCCONH(0x03);		// Initiate Clock Switch
	__builtin_write_OSCCONL(0x01);		// Start clock switching
	while(OSCCONbits.COSC != 0b011);	// Wait for Clock switch to occur	
	while(OSCCONbits.LOCK != 1) {};
}

int main(void) 
{

InitClock();
InitU2();
InitPorts();


		U2TXREG = 0xFE;
		U2TXREG = 0x58;

   char Txdata[] = {'L','E','D',' ','1','0',' ','i','s',' ','O','F','F','\0'};  
   int i = 0;
   while(Txdata[i])
   { 
       while( U2STAbits.UTXBF);  // wait while Tx buffer full 
       U2TXREG = Txdata[i];
       i++; 
   } 



while(TRUE) 
{
 	PORTAbits.RA0 = 1;
	PORTAbits.RA1 = 1;
	PORTAbits.RA2 = 1;
	PORTAbits.RA3 = 1;
	PORTAbits.RA4 = 1;
	PORTAbits.RA5 = 1;
	PORTAbits.RA6 = 1;  [COLOR="Red"][B] //This is D9[/B][/COLOR]
	PORTAbits.RA7 = 1; 
}
}
 
I'm using the dsPIC33FJ256GP710. The LEDs are connected as per in the Explorer 16 schematic. They are all on RA0-RA7 port and go turn on when the pin is High.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top