Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 18th July 2008, 12:25 AM   #1
Angry BoostC Flaw?

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?
AtomSoft is offline  
Old 18th July 2008, 01:22 AM   #2
Default

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);

Quote:
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.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 18th July 2008 at 01:29 AM.
futz is offline  
Old 18th July 2008, 01:37 AM   #3
Default

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...
AtomSoft is offline  
Old 18th July 2008, 01:41 AM   #4
Default

Quote:
Originally Posted by AtomSoft View Post
wow wierd i did this:
works fine now...
So it's happy with lata.1/2, but not with porta.1/2? How strange! Oh well, you should be using the LAT's anyway on 18F's.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 18th July 2008 at 01:43 AM.
futz is offline  
Old 18th July 2008, 03:40 AM   #5
Default

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.
AtomSoft is offline  
Old 18th July 2008, 04:15 AM   #6
Default

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.
__________________
Inside every little problem, is a big problem trying to get out.
kchriste is online now  
Old 18th July 2008, 11:12 AM   #7
Default

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 by AtomSoft; 18th July 2008 at 11:13 AM. Reason: Forgot to say
AtomSoft is offline  
Old 19th July 2008, 04:32 AM   #8
Default

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.
__________________
Inside every little problem, is a big problem trying to get out.

Last edited by kchriste; 19th July 2008 at 04:32 AM.
kchriste is online now  
Reply

Tags
boostc, flaw

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
BoostC Charlieplexed PWM 32 Mike, K8LH Micro Controllers 140 27th March 2009 11:19 AM
BoostC 12F683 Serial I/O Example Mike, K8LH Micro Controllers 5 2nd October 2008 07:21 PM
BoostC USART 18F AtomSoft Micro Controllers 9 29th June 2008 05:02 PM
BoostC question.. AddressOf Mike, K8LH Micro Controllers 8 25th June 2008 12:20 AM
math.h and lib for BoostC? futz Micro Controllers 3 31st March 2008 06:29 AM



All times are GMT. The time now is 05:20 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker