Problems with PIC16F628A LED flashing

General discussion on mikroC.
Post Reply
Author
Message
jacofaj
Posts: 4
Joined: 06 May 2009 07:21

Problems with PIC16F628A LED flashing

#1 Post by jacofaj » 06 May 2009 07:32

Hi,

This is my first time using Micro C, I am tring to program a simple LED flashing on a PIC16F628A.
But I can't get it to work. My code looks like this:

#include "built_in.h"

void main(){

TRISA = 0x00;
PORTA = 0x00;
CMCON = 0x07;

while(1){

PORTA = 1;
Delay_ms(1000);
PORTA = 0;
Delay_ms(1000);
}
}

Please Help!

pepesz
Posts: 62
Joined: 04 Feb 2009 15:33
Location: Rotterdam/Delft, NL

#2 Post by pepesz » 06 May 2009 09:01

Where is your LED connected? Should be to RA0 if it has to work with your code.
If you want to modify only one pin use PORTA.F0 = 1 or 0; where Fx is PORT pin number

Stefan Uhlemayr
Posts: 158
Joined: 17 Jan 2009 21:33

Re: Problems with PIC16F628A LED flashing

#3 Post by Stefan Uhlemayr » 06 May 2009 11:48

jacofaj wrote:Hi,

This is my first time using Micro C, I am tring to program a simple LED flashing on a PIC16F628A.
But I can't get it to work. My code looks like this: ...
Have a look to this compilation of useful links:
http://www.microchip.com/forums/fb.aspx?m=358934
In the second chapter "General Circuit-Design-Questions:", you will find the link "Help, my first PIC-project won't work:". In this post from Dale you will find the most common problems mentioned, why the PIC doesn't work as expected.
Btw, your code looks good, as far as I can say.

Hope this helps,
Stefan

jacofaj
Posts: 4
Joined: 06 May 2009 07:21

Still not working

#4 Post by jacofaj » 08 May 2009 19:42

Hi,

I tried all the advice, but no success.

I think it is in my configuration.
so if any one can give me an example of
the required config for a PIC16F628A with internal osc,
it will help.

Thanks
Jaco

CVMichael
Posts: 239
Joined: 30 Apr 2009 02:36
Location: Canada, Toronto

#5 Post by CVMichael » 08 May 2009 20:34

Are you aware that PORTA = 1 only sets the first bit ON ?

I think you should have:
PORTA = 255;
Or
PORTA = 0xFF;
Or
PORTA = 0b11111111;

(All 3 above are doing exactly the same thing).

If you want to set only one bit (pin), then you should call it like this: PORTA.F0 = 1;

MD5
Posts: 21
Joined: 25 Apr 2009 23:12

#6 Post by MD5 » 08 May 2009 21:32

Thx Michael,

Can we set in the application the porta status in Decimal, portb in hex or binary?

Example:
PORTA = 255;
Or
PORTB = 0xFF;

Just for info...

Regards,
Sam

Mince-n-Tatties
Posts: 2780
Joined: 25 Dec 2008 15:22
Location: Scotland

#7 Post by Mince-n-Tatties » 10 May 2009 10:19

MD5 wrote:Thx Michael,

Can we set in the application the porta status in Decimal, portb in hex or binary?

Example:
PORTA = 255;
Or
PORTB = 0xFF;

Just for info...

Regards,
Sam
yes you can... and the format is as shown by CVMichael above. you can have any combination within the same source code. you can even use different formats on the same port at different times in the same source.

e.g this is perfectly valid (duplication for demo purpose, but you could do it if you want)

TRISA = 0x0;
TRISA = 0b00000000;
TRISA = 0;

// an 8 bit memory walk
PORTA = 255;
PORTA = 0xAA;
PORTA = 0b01010101;
PORTA = 0;

jacofaj
Posts: 4
Joined: 06 May 2009 07:21

Solved

#8 Post by jacofaj » 17 May 2009 19:53

Hi,
Solved the problem.
It was in the config.

Thanks for all your help!!!

congduc1352
Posts: 3
Joined: 09 Jun 2014 09:19

Re: Solved

#9 Post by congduc1352 » 01 Apr 2019 14:17

jacofaj wrote:Hi,
Solved the problem.
It was in the config.

Thanks for all your help!!!
how you config sir?
im stucking here for afew day

Post Reply

Return to “mikroC General”