Jump to content
Sign in to follow this  
TheRyan

Led Test For 16f628a

Recommended Posts

'm new to both PIC microcontrollers and C programming alike, and recently downloaded SourceBoost. Very nice program! Well I am working on the usual, a blinking LED program to test a circuit I made on a PCB. Here's the code:

 

#include <system.h>

//Target PIC16F628A configuration word
#pragma DATA _CONFIG, _PWRTE_ON & _WDT_OFF & _XT_OSC & _CP_OFF

//4 MHz quartz
#pragma CLOCK_FREQ 4000000

void main( void )
{
   //Configure tris A and B
   trisa = 11100000b;
   trisb = 11000000b;

  while(1)
   {
porta = 00000000b;     //Set all pins OFF
portb = 00000000b;
delay_ms(1000);        //Delay for program recognition    
porta = 00011111b;    //Set all input pins ON
portb = 00111111b;
delay_ms(1000);
  }
}

 

I want to set the clock under #pragma to the chip's internal oscillator. What is the code for this? I looked through the Boost C Help section on #pragma and didn't find much. Is there a list somewhere of the possible commands? Also, if it's not too much work, could anyone tell me if the above code is missing anything? I have seen code with <system.h> as part of it, but do you need to put the actual file name (<p16f628a.h>) here before programming to the PIC, or leave it as-is? Thanks for any help, I've been looking around the forums and you guys are good at this stuff! :unsure: Gotta learn from the pros.

Share this post


Link to post
Share on other sites

Ryan, you check this:

 

 

 

_INTOSC_OSC_CLKOUT //can be used if you want the RB6 as CLOCK OUT pin

_INTOSC_OSC_NOCLKOUT //can be used if you want RB6 as normal I/O pin

 

 

 

complete pragma statement that can be used is as follow

 

#pragma DATA _CONFIG, _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _BODEN_OFF & _CP_OFF

 

 

Moreover the inbuilt oscillator has two clock rates, 4Mhz and 37Khz.

 

Therefore the PCON register has to be set accordiong to the required clock:

 

pcon.3 = 1 //for 4 MHz

pcon.3 = 0 //for 37 KHz

Edited by c58_4311

Share this post


Link to post
Share on other sites

Thank's for the bits of code, c58, but unfortunately the compiler gives me errors every time. Here's my new source code for the project, ledtest.c :

#include <system.h>
#pragma CLOCK_FREQ 4000000

#pragma DATA _CONFIG,_INTOSC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _BODEN_OFF & _CP_OFF

pcon.3 = 1; //Set PCON register to 4 MHz

void main()
{
trisa = 11100000b;   //Configure I/O
trisb = 11000000b;

   while(1)
{
 porta = 00000000b; 	//Set all pins OFF
 portb = 00000000b;
 delay_ms(1000);		//Delay for program recognition	
 porta = 00011111b;	//Set all input pins ON
 portb = 00111111b;
 delay_ms(1000);
   }
}

 

I get this error log on the "Output" section of the SourceBoost IDE:

 

"D:\Program Files\SourceBoost\boostc.pic16.exe" -t PIC16F628A  ledtest2.c

(etc...)

ledtest2.c

internal error: can't parse input file name 'ledtest2.c'

 

failure

ledtest2.c(4): error:  failure

Failed to locate output file 'ledtest2.obj'

Done

 

Failed

 

I've got the settings all right, the clock speed to 4,000,000 Hz, chip to '628a... Is something wrong with the ordering of my #pragma DATA _CONFIG? That's the only problem the program can see, so something's gone funny.

Share this post


Link to post
Share on other sites

TheRyan,

 

I fink you tried to set a register bit outside a function.

And the compiler error code wasn't very helpful.

 

Try this:

 

#include <system.h>
#pragma CLOCK_FREQ 4000000

#pragma DATA _CONFIG,_INTOSC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _BODEN_OFF & _CP_OFF

void main()
{
    pcon.3 = 1; //Set PCON register to 4 MHz
    
   trisa = 11100000b;   //Configure I/O
   trisb = 11000000b;

    while(1)
    {
         porta = 00000000b;     //Set all pins OFF
         portb = 00000000b;
         delay_ms(1000);        //Delay for program recognition    
         porta = 00011111b;    //Set all input pins ON
         portb = 00111111b;
         delay_ms(1000);
    }
}

 

Regards

Dave

Share this post


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...
Sign in to follow this  

×
×
  • Create New...