Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIc16F628A LED Chaser

Status
Not open for further replies.

vijayanmct

Newbie level 4
Joined
Sep 18, 2013
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
44
Hi, kindly correct my code for LED Chaser on PORTB in a PIC16F628A. I am using MikroBasic Pro.
I wish to have a continuous loop from RB0 to RB7 and back to RB0 to RB7.
By using my code, given below, LED moves from RB0 to RB7 and goes off for ever and required a reset for the next run.
thank you.

Code:
  '4Mhzs internal Osc
  Dim Cnt as Byte
main:
  trisB = 0
  portB = 0
  Cnt = 1
      loop: 
             portB = Cnt
             delay_ms(1000)
             Cnt = Cnt*2
             goto  loop
End.
 
Last edited by a moderator:

The software should work, if it runs once then crashes I would guess the 'Cnt' variable is overflowing and trashing whatever is next in memory. If that is the case, and the electronics is OK, it suggests a compiler bug but the simple fix should be to ask if Cnt has reached 128 (RB7 lit) and then reset it back to 1.

Brian.
 
Thank you for the post. I am not using any X'tals in this circuit and I included the INTOSC option in the Project wizard dialogue box. Please help me.
thank you.
Best Regards,
Vjn

- - - Updated - - -

Thank you Mr.Brian, your post is much appreciative.I confess, I am a newbie! and this is my first post. I modified my code to Scroll the Leds left as follows and the result is quite impressive.Now leds lit from RB0 - RB6 and goes back to RB0 and the loop continue for ever, but RB7 is not coming on at all,the time delay between RB6 and Rb0 is same, as between other leds.Please guide me to include RB7 also in the loop. Thank you!
(electronic circuit, PIC ic, LEDs etc , tested separately, they are ok)
With Best Regards,
S.Vijayan, Muscat, Oman

Code:
Dim Cnt as Byte
main:
trisB = 0
portB = 0
Cnt = 1
loop: 
portB = Cnt
delay_ms(1000)
Cnt = Cnt*2
  If Cnt = 128 then
     Cnt =1
  end if
Goto Loop
end.
 
Last edited by a moderator:

Thank you for the post. I have attached here with the project file named LED_CHASER_LEFT.RAR
thank you

Best Regards,
S.Vijayan
 

Attachments

  • LED_Chacer_scrolling left.mbppi_callertable.txt
    6 bytes · Views: 106
  • PIC16F628A _LED Chacer_Scroll_left.jpg
    PIC16F628A _LED Chacer_Scroll_left.jpg
    87 KB · Views: 115
  • LED_CHASER_Scroll_Left.rar
    75.2 KB · Views: 117

It is working for me. Change resistor values to 330E if you are not using Superbright LEDs. Test my .hex file. Proteus simulation attached.

Cnt = 128 means Cnt = 0b10000000

According to your code when Cnt becomes 128 it is reset. So, the last value it displays is 127 which is 0b01111111. Change value in If Then condition to 255.
 

Attachments

  • LED_Chacer_scrolling left.rar
    42.3 KB · Views: 86

Code:
Dim Cnt as Byte
main:
trisB = 0
portB = 0
Cnt = 1
loop:
portB = Cnt
delay_ms(1000)
Cnt = Cnt*2
If Cnt = 255 then
Cnt =1
end if
Goto Loop
end.

Try above code i changed cnt=128 by 255(FFH)....this will work
 
Last edited by a moderator:
The code multiplies the variable by 2 each time so it shifts the '1' in the variable one position to the left. The sequence should be:

00000001
00000010
00000100
00001000
00010000
00100000
01000000
10000000

so it should reset AFTER 10000000 = 128 decimal. It should never reach 255 or any other number than those I listed.

Brian.
 
Thank you Mr.Brian, the information is very much valuable for me. I tried your code It did not work the way we were discussing. I found one from the Book 'PIC BASIC PROJECTS' of Mr.DOGAN IBRAHIM, and its woking fine the code is as follows

DIM Cnt as Byte
Main:
TRISB = 0
PORTB =0
INIT:
Cnt = 1
LOOP:
PORTB = Cnt
Delay_ms(1000)
If Cnt = 128 then
GOTO INIT
Else Cnt = Cnt*2
End if
GOTO LOOP
End.

Thanks again Mr.Brian and my other friends to spend your valuable time for me.
We will meet again in this forum, till then Good Bye!!!

Thanks & Best regards

S.Vijayan,Muscat
 

The code multiplies the variable by 2 each time so it shifts the '1' in the variable one position to the left. The sequence should be:

00000001
00000010
00000100
00001000
00010000
00100000
01000000
10000000

so it should reset AFTER 10000000 = 128 decimal. It should never reach 255 or any other number than those I listed.

Brian.


thanks brian......
 

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Dim Cnt as Byte
 
main:
 
    trisB = 0
    portB = 0
 
    Cnt = 1
 
loop:
    portB = Cnt
    delay_ms(1000)
    Cnt = Cnt << 1
    
    If Cnt = $00 then
        Cnt = 1
    end If
 
    Goto Loop
end.

 
Wooooooooooooooooooooh! its working with your code.Thank you very much. Thanks again! for your for your valuable time and dedications to help others.
Best Regards,

S.Vijayan,Muscat, Oman
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top