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.

BoostC Flaw?

Status
Not open for further replies.

AtomSoft

Well-Known Member
I wrote this simple code
Code:
#include <system.h>

#pragma DATA	_CONFIG1H, _INTIO1_OSC_1H
#pragma DATA	_CONFIG2L, _BOR_OFF_2L     
#pragma DATA	_CONFIG2H, _WDT_OFF_2H    
#pragma DATA	_CONFIG4L, _LVP_OFF_4L

#pragma	CLOCK_FREQ 8000000

void main(void)
{
    set_bit( osccon, IRCF2 );           //8 MHz
    set_bit( osccon, IRCF1);
    set_bit( osccon, IRCF0 );

	trisb=0;
    trisa=0;
    porta=0;
    portb=0;

    porta.1=1;
    delay_s(2);
    porta.2=1;

	while(1){

	}
	
}

Yet it doesnt work right. Im worried it might give me a issue later on. What it does it light led 1 on RA1 then led 2 on RA2 but once it lights led 2 LED 1 turns off.

How come?
 
Code:
#pragma DATA	_CONFIG1H, _INTIO1_OSC_1H
You probably meant to use _INTIO2_OSC_1H. Using INTIO1 loses you the RA6 pin as a usually useless clock output.


Code:
    set_bit( osccon, IRCF2 );           //8 MHz
    set_bit( osccon, IRCF1);
    set_bit( osccon, IRCF0 );
That's fine, but these can also be done with either
Code:
    osccon,IRCF0=1;
    osccon,IRCF1=1;
    osccon,IRCF2=1;
or
Code:
    osccon=0x72;


These can be simplified if you want
Code:
	trisa=trisb=0;
        porta=portb=0;


And this can be simplified too
Code:
	while(1);


Yet it doesnt work right. Im worried it might give me a issue later on. What it does it light led 1 on RA1 then led 2 on RA2 but once it lights led 2 LED 1 turns off.

How come?
Not sure. Is this on Junebug? Show me your circuit.

Probably nothing to do with it, but your "porta.1=1" and such should be "lata.1=1". Use the latch/shadow registers instead of the ports and you'll avoid weird problems later.
 
Last edited:
wow wierd i did this:

Code:
#include <system.h>

#pragma DATA	_CONFIG1H, _INTIO2_OSC_1H
#pragma DATA	_CONFIG2L, _BOR_OFF_2L     
#pragma DATA	_CONFIG2H, _WDT_OFF_2H    
#pragma DATA	_CONFIG4L, _LVP_OFF_4L

#pragma	CLOCK_FREQ 8000000

void main(void)
{
    osccon=0x72;           //8 MHz

	trisb=trisa=0;
    porta=portb=0;

    lata.1=1;
    delay_s(1);
    lata.2=1;

	while(1){

	}
	
}

works fine now...
 
yeah its pretty wierd but as long as it works. ill be sure to use lata for pic18F from now on. by the way im away from home and am writing this on a psp.
 
Are you using current limiting resistors on the LEDs? If not, it is possible that the Read/Modify/Write instruction won't work properly using the porta register. Using lata is the preferred method anyway. Which PIC are you using? Some pins are TTL level and others are Schmitt Trigger level pins.
 
it was happening on 2 PICs. My Junebug(18F1320) and a 18F248. But all is well and im happy lol

edit: also i due have 2 resistors on it. (100ohm)
 
Last edited:
If you want, measure the voltage on the pins driving the LEDs when the LEDs are on. If it is equal or less than 2V, then that was the problem but with the 100Ω resistors it should be above 2V according to the spec sheet.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top