Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 22nd June 2007, 04:10 PM   (permalink)
Default LED blinking problems with 16F628A

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.
George L. is offline   Reply With Quote
Old 22nd June 2007, 04:48 PM   (permalink)
Default

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.
v1r05 is offline   Reply With Quote
Old 22nd June 2007, 06:03 PM   (permalink)
Default

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?
Norlin is offline   Reply With Quote
Old 23rd June 2007, 03:06 PM   (permalink)
Default

Is X being used somewhere else is the program?

Last edited by donniedj; 23rd June 2007 at 04:34 PM.
donniedj is offline   Reply With Quote
Old 23rd June 2007, 03:14 PM   (permalink)
Default

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.
Pommie is online now   Reply With Quote
Old 23rd June 2007, 04:38 PM   (permalink)
Default

Does this approximate what you are trying to achieve?

http://www.anothercoilgunsite.com/sample.wmv
donniedj is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Flashing a LED with Mouse Gayan Soyza Electronic Projects 12 28th March 2007 10:53 PM
Accessing EEPROM Clayton Micro Controllers 15 23rd March 2007 03:00 AM
Very Simple LED Clock Using 16F84A or 16F628A pasanrobotics Micro Controllers 6 14th February 2007 11:30 PM
Reason behind blinking LED signs in Boston that shut city down.. Terrorism after all! Analog Chit-Chat 3 13th February 2007 01:13 AM
problems with PWM and 16F628A POWERMAN Micro Controllers 19 24th September 2006 07:46 PM



All times are GMT. The time now is 12:07 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.