I'm a novice working with 16f628a

Started by sr_gamer May 1, 2009
I've been searching around for examples, but learning is slow going.

At the moment I'm trying to program a 16f628a to light one LED for a controlled length of time and then light another for a controlled length of time and then the program should end.

This is just a learning exercise. I'm using the HiTech C compiler with MPLAB and programming with a PICkit2.

When I run the code that I've included below, both LEDs come on and stay on.

Here is my code:

#include

__CONFIG(INTCLK & WDTDIS & PWRTDIS & BORDIS & LVPDIS & UNPROTECT);

void main( void )
{
TRISB = 0b00000000; //set port B pins as outputs

PORTB = 0b00000010; //turn on LED at pin 7 RB1
_delay(1000); //Delay

PORTB = 0b00000001; //turn on LED at pin 6 RB0
_delay(1000);
}

Hello,

Looking at your code, first off I always put an infinite loop at the end of the program. There isn't an "end" command. Instead the program counter continues to run until it overflows back to 0. Then your program runs again.

I usually add a while(1); statement at the end of main() to send it off into a nice coma.

Also, the software simulator is your friend. I sure do use it a lot. Try removing the delay statements and step through the code while using the watch window to look at PORTB. I've forgotten little things, like a CCP peripheral forcing some ports to be inputs, etc... that drove me mad before I found the answer.
--- In p..., "sr_gamer" wrote:
>
> I've been searching around for examples, but learning is slow going.
>
> At the moment I'm trying to program a 16f628a to light one LED for a controlled length of time and then light another for a controlled length of time and then the program should end.
>
> This is just a learning exercise. I'm using the HiTech C compiler with MPLAB and programming with a PICkit2.
>
> When I run the code that I've included below, both LEDs come on and stay on.
>
> Here is my code:
>
> #include __CONFIG(INTCLK & WDTDIS & PWRTDIS & BORDIS & LVPDIS & UNPROTECT);
>
> void main( void )
> {
> TRISB = 0b00000000; //set port B pins as outputs
>
> PORTB = 0b00000010; //turn on LED at pin 7 RB1
> _delay(1000); //Delay
>
> PORTB = 0b00000001; //turn on LED at pin 6 RB0
> _delay(1000);
> }
>