Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LED blinking problems with 16F628A

Status
Not open for further replies.

George L.

New Member
Hello,

I have been working on programming a PIC 16F628A-I/P to blink two banks of LEDs in two different patterns.

I am using MikroBASIC for PIC to write the code and I program it with ICprog. The code is supposed to make the LED banks blink back and forth ten times and then do the same for the second pattern, but double flash each bank.

When I run this code with the circuit, it only runs though the first pattern and doesn't do the double blink pattern. I have been at it for 7 hours and really need some help.

Here is the code:

program LED_blinkz

Dim x as byte
Dim y as byte

TRISB.4 = 0
TRISB.3 = 0

x = 0
y = 0

Main: ;Start of pattern one

x = x+1

PORTB.4 = 1

Delay_MS(40)

PORTB.4 = 0

Delay_MS(150)

PORTB.3 = 1

Delay_MS(40)

PORTB.3 = 0

Delay_MS(150)

If x>10 then ; tells it do repeat 10 times

goto AUX

else

goto main

end if

AUX: ; start of second pattern (IT NEVER GETS HERE!!!!!!!!THIS IS THE PROBLEM)

y = y + 1

PORTB.4 = 1

Delay_MS(1000)

PORTB.4 = 0

Delay_MS(100)

PORTB.4 = 1

Delay_MS(1000)

PORTB.4 = 0

Delay_MS(200)

PORTB.3 = 1

Delay_MS(1000)

PORTB.3 = 0

Delay_MS(100)

PORTB.3 = 1

Delay_MS(1000)

PORTB.3 = 0

Delay_MS(100)

PORTB.3 = 1

Delay_MS(1000)

If y>10 then ; tells it to repeat 10 times

goto main

else

goto AUX

end if

End.

-------------------------

The 1st pattern is just repeated over and over, it never does the second pattern. I think there is something wrong with the way I am writing the If/then statements.

If anyone can help, please do.

thanks in advance,

George L.
 
hi

i cant read code that dosent have a semi-colon at the end of each statment.

anyway try using the debugger that came with the IDE you got there this is what i always do and always solves it.
 
I'm not a basic programmer, but I do notice that you never reset your x and y variables
I don't know why it never goes to the aux part, but from what I read it should be doing main 10 times, then do aux 10 times, then do main once, aux once and keep doing each of them once over and over (not 10 times, since you never set x or y back to 0)
also, you say it's supposed to flash two LED banks? but it looks like it's just changing bits 3 and 4 on port B, both main and aux seem to flash the same two bits?
 
Is X being used somewhere else is the program?
 
Last edited:
My guess would be that the watch dog timer is reseting the pic before the second pattern can execute. Try turning off the WDT.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top