Jump to content

Recommended Posts

Here is a simple program. It builds ok. But I use another party's programmer (ISP Pro by BasicMicro). I load the hex file generated by SourceBoost and program it on my target (16F874A, 10 MHz). But nothing happens. The programmer thinks it programmed, but the LED is not lit.

 

The programmer, PIC etc. is working because I can program in MBasic and it works just fine.

 

What am I doing wrong?

 

Here is the source code in C:

 

#include <system.h>

 

void main()

{

while (1)

{

set_bit(porta,1);

//delay_s(10);

//clear_bit(porta, 0);

//delay_s(100);

}

}

Link to post
Share on other sites
You kind of need to set the tris registers ...

 

I added trisa.

 

The code is

 

#include <system.h>

trisa=0x00;

void main(void)

{

set_bit(porta, 0);

}

 

It still does not work.

 

My problem may be more basic.

 

What is the sequence in starting a project and adding a c source file?

 

Can someone please help this newbie with step by step instrux?

 

Thanks. ;)

Link to post
Share on other sites

#include <system.h>

void main()
{
 trisa=0x00; /* Set all Port A as outputs */
 while (1)
 {
     set_bit(porta,1);
     //delay_s(10);
     //clear_bit(porta, 0);
     //delay_s(100);
 }
}

 

Help->User Manual -> Getting Started

Edited by emte
Link to post
Share on other sites

You should consult Microchips datasheet on this device

 

http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf

 

On reset PORTA pins are assigned as analogue inputs for the ADC, its not just a matter of clearing the required TRISA bits, you have to unassign the port bits you equire. This is set in ADCON1.

 

See page 128 in the datasheet for further details.

Link to post
Share on other sites

coldfusion99,

It still does not work. 

 

My problem may be more basic. 

You also need to set the device configuration correctly, like oscillator type, disable watchdog etc.

 

Take a look at some of the supplied BoostC sample programs and go from there.

 

Regards

Dave

Link to post
Share on other sites
coldfusion99,
It still does not work. 

 

My problem may be more basic. 

You also need to set the device configuration correctly, like oscillator type, disable watchdog etc.

 

Take a look at some of the supplied BoostC sample programs and go from there.

 

Regards

Dave

 

Dave,

That's exactly what I did. I modified an example program that came with Source Boost C. i.e. randtest.c All I did was comment out everything, and just add a line to turn one LED on.

 

Then I build successfully. Of course, I chose the right target, Freq.

 

Then I program the chip. All's OK, except the program does not do what I expect which is turn on LED at porta.0.

 

Where can I get detailed info. on how to start a project, add files to project etc.?

Link to post
Share on other sites
coldfusion99,
It still does not work. 

 

My problem may be more basic. 

You also need to set the device configuration correctly, like oscillator type, disable watchdog etc.

 

Take a look at some of the supplied BoostC sample programs and go from there.

 

Regards

Dave

Picxie,

 

How do you change it to digital ports?

Link to post
Share on other sites
coldfusion99,
It still does not work. 

 

My problem may be more basic. 

You also need to set the device configuration correctly, like oscillator type, disable watchdog etc.

 

Take a look at some of the supplied BoostC sample programs and go from there.

 

Regards

Dave

Picxie,

 

How do you change it to digital ports?

 

Read page 128 in the data sheet.

Link to post
Share on other sites

#include <system.h>

 

void main()

{

trisb = 0; //configure port B

portb = 0;

adcon1 = 0x06; //turn off A/D

trisa = 0; //porta is output

while( 1 ) //endless loop

{

porta = 0xff;

}

}

 

Hello all, I am thoroughly frustrated. The above code should turn off the A/D in 16F874A at 10 MHz and turn on LEDs attached to PORTA.

 

It does not.

 

What *%$#@ is the problem?

 

Thanks in advance.

Link to post
Share on other sites
...

Hello all,  I am thoroughly frustrated.  The above code should turn off the A/D in 16F874A at 10 MHz and turn on LEDs attached to PORTA.

 

It does not.

 

What *%$#@ is the problem?

 

I suggest to look at the sample program called 'interrupt' that is included into SourceBoost installation and try it first. It does a very thimilar thing that what you try to do in your code except it uses port B. If you can run it than use it as base for your new development. If you can't than something wrong is in your setup because this code in known to work.

 

Regards,

Pavel

Link to post
Share on other sites
Hello all,  I am thoroughly frustrated.  The above code should turn off the A/D in 16F874A at 10 MHz and turn on LEDs attached to PORTA.

 

It does not.

 

What *%$#@ is the problem?

 

Thanks in advance.

 

 

You have yet to indicate that you have disabled the WDT(watchdog timer) which by default is enabled.

Link to post
Share on other sites

coldfusion99,

What *%$#@ is the problem?

Probably you haven't set the device configuration (#pragma DATA _CONFIG). You need to do this to turn off watchdog and configure the device oscillator (device oscillation config most likely your problem).

 

Regards

Dave

Link to post
Share on other sites

coldfusion99,

 

Dave, can you post a simple but full program that flashes LED attached to Porta.0 say 1 sec. on & 1 sec. off?  preferably for 874A?  at 10 MHz? 

Try this. I must admit I've only tried it on a PIC16F877.

 

// PIC16F874A 
#include<system.h>

// _LVP_OFF disables Low Voltage Programming, enabling use of the RB3 output.
#pragma DATA _CONFIG, _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC & _LVP_OFF

#pragma CLOCK_FREQ 10000000

void main()
{ 
// - turn PortA inputs that we are using into digital mode.
adcon1 = 00000110b;
trisa = 0x00;
while( 1 )
{
	porta = 0xFF;
	delay_s( 1 );
	porta = 0x00;
	delay_s( 1 );
}

}

 

Regards

Dave

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...