Menu

What is wrong with that

Help
2009-05-25
2013-05-30
  • Nobody/Anonymous

    1.I find that code and I try it in PIC IDE SIMULATOR but always stops at
    line 2 - syntax error.

    2.Can somebody post a working code for a 8 series of led which can do a chaser - old led chaser. I try to have an image how the code looks like.

    'chip settings
    #chip 16f684, 4
    #Config wdt_off

    start
    set PORTA.0 off
    wait 1s
    set PORTA.0 On
    wait 1s

    Goto start

     
    • kent_twt4

      kent_twt4 - 2009-05-25

      "start" should be "start:"  Are you using the internal oscillator? if so then that would have to be in the config also (i.e. INTRC_OSC_NOCLKOUT).

       
    • J Olson

      J Olson - 2009-05-25

      A few things, you got a syntax error on your timer call.

      Need a space after the "s" amd it needs to be "sec" not "s"
      Try this way, assuming all your leds are on port A.
      There probably are 50 ways to write a led tracer, this is just one.

      You could do it like you have it in your code above but it would be twice the size calling out each bit and then turning it on or off.
      If your just after an led tracer you can do it on the whole port at one time.

      #chip 16f684, 4
      #Config wdt_off

      Dir PORTA out

      PORTA = 0

      start

          PORTA = 1
            wait 1 sec
          PORTA = 2
            wait 1 sec
          PORTA = 4
            wait 1 sec
          PORTA = 8
            wait 1 sec
          PORTA = 16
            wait 1 sec
          PORTA = 32
            wait 1 sec
          PORTA = 64
            wait 1 sec
          PORTA = 128
            wait 1 sec
          PORTA = 0
           wait 1 sec

      goto start

       
    • J Olson

      J Olson - 2009-05-25

      Ah you beat me by one minute kent. LOL
      I also did not change the start header as you mentioned. doh

       
    • Gabi Balsanu

      Gabi Balsanu - 2009-05-26

      Thank you for code but I have 12 led's 4 (first 4)of them are connected to port A and the other 8 to port B. How can wrote the code to make a chaser from all 12?

      Regards
      Gabi

       
    • J Olson

      J Olson - 2009-05-26

      Sorry, didn't look up your chip datasheet until now, just assumed PortA had 8 io.

      The 16F684 does not have a port B (did you mean PortC?) so not sure what you have.

      If you can tell us what pins you are using for your leds we can help more. Check the datasheet for you chip and report back what ports and pins you are using like:

      led 1 is connected to PortA.0
      led 2 is connected to PortA.1
      ...
      ...
      led 5 is connected to PortC.0
      etc etc

      I will post some code then.

      The above code will still work, just need to add more and change the port names.

      Zm

       
      • Gabi Balsanu

        Gabi Balsanu - 2009-05-26

        Hi,

        I changed my design to PIC16F84A sorry for that. Connection are:
        RA3 - LED1
        RA2 - LED2
        RA1 - LED3
        RA0 - LED4
        RB7 - LED5
        RB6 - LED6
        RB5 - LED7
        RB4 - LED8
        RB3 - LED9
        RB2 - LED10
        RB1 - LED11
        RB0 - LED12

        If you post some code for all leds will be awesome. Until now I have that:

        Define CONF_WORD = 0x3ff1
        Define CLOCK_FREQUENCY = 4
        AllDigital

        Dim i As Byte

        TRISB = 0

        loop:
            For i = 0 To 255
            PORTB = i
            WaitMs 10
            Next i
        Goto loop

        but movement is not very smooth and I dont use all LED's.

        Thank you in advance
        Gabi

         
    • Gabi Balsanu

      Gabi Balsanu - 2009-05-26

      I have some question's:

      1. What book do you guy's recommend to a beginer?
      2. Where I can find a list with all commands (with syntax) supported by GCBasic compiler?

      Regards
      Gabi

       
    • J Olson

      J Olson - 2009-05-26

      That is because you are counting in binary not turning on leds in a row. The reason I am using these numbers below (1,2,4,8,16 etc) is they will only turn on one led at a time, all others will be off. I also changed the timer to 350 ms, it looks better faster than a sec between leds. ;o)

      Next to your led ports I put the binary equiv of the whole number for reference only. Hopefully you can see the pattern.
      It is much easier to see in binary than in a whole number value. Do not put that in your code. The code example I did for you starts with #defines etc here...

      ----- For ref only ---------------
      RA3 - LED1 (00001000) = 8
      RA2 - LED2 (00000100) = 4
      RA1 - LED3 (00000010) = 2
      RA0 - LED4 (00000001) = 1

      RB7 - LED5   (10000000) = 128
      RB6 - LED6   (01000000) = 64
      RB5 - LED7   (00100000) = 32
      RB4 - LED8   (00010000) = 16
      RB3 - LED9   (00001000) = 8
      RB2 - LED10  (00000100) = 4
      RB1 - LED11  (00000010) = 2
      RB0 - LED12  (00000001) = 1
      ----------------------------------

      #defines etc here...

      Dir PORTA  out
      Dir PORTB  out

      start:

            PORTA = 0
            PORTB = 0

             wait 350 ms
             PORTA.3 = 8
             wait 350 ms
             PORTA.2 = 4
             wait 350 ms
             PORTA.1 = 2
             wait 350 ms
             PORTA.0 = 1
             wait 350 ms
             PORTB.7 = 128
             wait 350 ms
             PORTB.6 = 64
             wait 350 ms
             PORTB.5 = 32
             wait 350 ms
             PORTB.4 = 16
             wait 350 ms
             PORTB.3 = 8
             wait 350 ms
             PORTB.2 = 4
             wait  350 ms
             PORTB.1 = 2
             wait 350 ms
             PORTB.0 = 1
               
      goto start

      Zm

       
    • Gabi Balsanu

      Gabi Balsanu - 2009-05-27

      Thank you for code - very nice. Nothing about books, commands and syntax in GCBasic...

      Regards
      Gabi

       
    • J Olson

      J Olson - 2009-05-27

      Sorry I do not have any good suggestions on books, commands etc besides the gcb help and this forum. Maybe get an old/new book on just Gbasic or Visual Basic and look at that. It will not be exactly the same as gcb but could give you a jump on understanding basic as a programming language. Syntax will be a little different between compilers but very similar overall.

      So I assume you got your leds chasing now?

      Zm

       
    • Gabi Balsanu

      Gabi Balsanu - 2009-05-27

      Yeah THANK YOU. This forum dosen't have points, help and reputation... :). If I have 7 or 8 rows of leds how code look like? I think I should use something like arrays. I have some experience in Pascal and C++ but none in Basic.
      Anyway many thanks for that piece of code.

      Regards
      Gabi

       
    • Gabi Balsanu

      Gabi Balsanu - 2009-05-28

      Hi,

      I just see, in your example you use only 11 leds. I need to move 12. Since 256 is more than 255 (byte) how can I modify code for all 12 leds?

      Again if I have more rows (lines) of led's how code look like.

      If I upset you with my beginner question tell me and I will stop that and I don't disturb you.

      Regards
      Gabi

       
    • J Olson

      J Olson - 2009-05-28

      No there are 12 leds there, look again.
      4+8 = 12
      4 on Port A
      8 on Port B

      Doesn't sound like you have put this in your chip and ran it, as you would see 12 leds turning on and off in a row.

      Try that first.

      Zm

       
      • Gabi Balsanu

        Gabi Balsanu - 2009-05-28

        You are right, my fault. I make some modification and I didn't delete the sign for comment. Nothing about more rows...

        thank you
        Gabi

         
    • Gabi Balsanu

      Gabi Balsanu - 2009-05-28

      That code is writen to chase only one? How code look like if I want to put a loop running forever?

      Regards
      Gabi

       
    • J Olson

      J Olson - 2009-05-28

      Ah, so you did finally put it in and run it. lol
      My leds are connected reverse of yours, but doesn't matter at all. Just a quick code change.

      The code above will loop over and over.
      (start -> goto start) ?

      All you do is change the numbers as so (below).
      As mentioned above there are 100's of ways to do this
      I am only showing one way and not assuming anything on your side. If things don't seem to work right play around with the numbers, order etc.

      For mutliple rows of leds, you will need to do it completly differnt as your pic cannot do that many rows without more hardware or a matrix style connection to your led array.

      ----- For ref only ---------------
      RA3 - LED1 (11110111) =  247
      RA2 - LED2 (11111011) =  251
      RA1 - LED3 (11111101) =  253
      RA0 - LED4 (11111110) =  254

      RB7 - LED5 (01111111) = 127
      RB6 - LED6 (10111111) = 191
      RB5 - LED7 (11011111) = 223
      RB4 - LED8 (11101111) = 239
      RB3 - LED9 (11110111) = 247
      RB2 - LED10 (11111011) = 251
      RB1 - LED11 (11111101) = 253
      RB0 - LED12 (11111110) = 254
      ---------------------------------

      start:

      PORTA = 0
      PORTB = 0

      wait 350 ms
      PORTA.3 = 247
      wait 350 ms
      PORTA.2 = 251
      wait 350 ms
      PORTA.1 = 253
      wait 350 ms
      PORTA.0 = 254
      wait 350 ms
      PORTB.7 = 127
      wait 350 ms
      PORTB.6 = 191
      wait 350 ms
      PORTB.5 = 223
      wait 350 ms
      PORTB.4 = 239
      wait 350 ms
      PORTB.3 = 247
      wait 350 ms
      PORTB.2 = 251
      wait 350 ms
      PORTB.1 = 253
      wait 350 ms
      PORTB.0 = 254

      goto start

       
    • Nobody/Anonymous

      PORTA = 0 
      PORTB = 0 

      wait 350 ms 
      PORTA.3 = 247 
      wait 350 ms 
      PORTA.2 = 251 
      wait 350 ms 
      'you are wrong!
      'must be this way..

      set PORTA = 253  ' or out porta, 253
      wait 350 ms 
      set PORTA = 254 
      wait 350 ms 
      set PORTB = 127
      wait 350 ms 
      set PORTB = 191 
      wait 350 ms 
      set PORTB = 223
      wait 350 ms 
      set PORTB = 239
      wait 350 ms 
      set PORTB = 247 
      wait 350 ms 
      set PORTB = 251
      wait 350 ms 
      set PORTB = 253 
      wait 350 ms 
      set PORTB = 254 

      goto start 

       
    • J Olson

      J Olson - 2009-05-28

      Umm? No I'm not.
      Works fine without the "Set".

      Chezz. Where you been then for the past few days?

      Didn't see you helping him...

      I'm out...

       
      • Gabi Balsanu

        Gabi Balsanu - 2009-05-29

        C'mon guy's, I am trying to learn something here ;). Your code ZM its working fine (THANK YOU). I didn't try the second solution. About more leds I know I must use more hardware something like ULN or HC but my question's are:
        - for scrolling and some efects with text and numbers(1 to 4 numbers and 1 to 3 characters) which is the best approach?
        - how the code look like (with new hardware)?

        Regards
        Gabi

         
    • Gabi Balsanu

      Gabi Balsanu - 2009-05-30

      Hey ZM you are really out? You don't want to help a newbie? If that comment offend you I think is forum fault (let people to post without registration). So, can you post some code for more rows and columns? Point me in the right direction - some links...

      Thank you in advance
      Gabi

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.