Simple delay issue with ledblinking for PIC 16F628a

Status
Not open for further replies.

DanT29

Newbie level 4
Joined
Jul 5, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,345
Hey guys I'm new PIC microcontrollers and programming them in C. I started many months ago but had to stop since school started and I got busy with other things. But now I'm back to it determined to learn and I really need your help guys. I have a small issue in my program and I was wondering if you guys can help! I have an issue with the delay function...I'm not sure what to use for it. This is a newbie issue and I know you guys can help. I hope I don't need to make my own library for it.

I'm trying to make an led blink this is what I'm using:
MPLAB X
HI-TECH C complier
PIC KIT 2
PIC 16F628a

Here's my code:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
#include<pic.h>
#include<htc.h>
void main(){
    TRISB=0x00;
    PORTB=0x00;
    
    while(1){
        PORTB=~PORTB;
        __delay_ms(1000);
        PORTB=~PORTB;
    }
}


I tried a lot of functions but none worked. I appreciate the help!
 
Last edited by a moderator:

Two comments:

1. Only the htc.h header file needs to be included, not the pic.h header file.

2. To utilize the delay macro routines you must specify the system clock frequency by defining _XTAL_FREQ as the clock/oscillator frequency.


For example if your clock/oscillator frequency is 4MHz then include the following compiler/preprocessor directive:

Code:
#define _XTAL_FREQ 4000000

bigDog
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…