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.

Simple flashing LEDs project PIC16F628A

Status
Not open for further replies.

George L.

New Member
Hello,

I have just started working with PIC and my first project is a two led flasher. I write in BASIC and use the mikrobasic compiler for PIC. The first two patterns work but when I try to lite both the leds at the same time, they don't go on!

Here is my code:
------------------------------------------------------------
program dom_led_show3

const q = 80
const m = 50
const n = 300
const s = 50
const d = 80
const l = 40

dim y as byte
dim p as byte
dim j as byte

trisa = 0

main:

inc(y)
delay_ms(q)
porta.3 = 1
delay_ms(s)
porta.3 = 0
delay_ms(q)
porta.2 = 1
delay_ms(s)
porta.2 = 0
if y=10 then
goto ver1
else
goto main
end if

VER1:

inc(p)
delay_ms(d)
porta.3 = 1
delay_ms(m)
porta.3 = 0
delay_ms(d)
porta.3 = 1
delay_ms(m)
porta.3 = 0
delay_ms(n)
porta.2 = 1
delay_ms(m)
porta.2 = 0
delay_ms(d)
porta.2 = 1
delay_ms(m)
porta.2 = 0
if p=7 then
p=0
y=0
goto vere
else
goto ver1
end if

VERe:

inc(j)
porta = 1
delay_ms(l)
porta = 0
delay_ms(l)
if j=20 then
j=0
goto main
else
goto vere
end if

end.
-------------------------------------------
In main: the leds alternate, in ver1: they flash twice...delay...then the other the same. In vere:(3rd section) they are supposed to light at the same time and go off at the same time very quickly, but they don't light up.

The leds are super-bright blue >5mm. They work fine in other patterns, but not in the third one.

could someone please tell me what I am doing wrong?

thanks.

George L.
 
Hi George,

I am not familar with mikrobasic but try this:

VERe:

inc(j)
porta.2 = 1
porta.3 = 1
delay_ms(l)
porta.2 = 0
porta.3 = 0
delay_ms(l)
if j=20 then
j=0
goto main

You may also want to initalize the count variables y,p and j at the start of the program.

y = 0
p = 0
j = 0


Regards,
John
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top