Announcement

Collapse
No announcement yet.

Bonehead Part VI

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bonehead Part VI

    I've been bashing my head and wasting electrons for two straight days now. There must be something wrong with my code because the damned LED just sits there dark as sin. Can anybody lead me into the path of righteousness on this sucker? Thanks, Jim

    ' Name : 7segjw1.bas
    ' Compiler : PICBASIC PRO Compiler 3.1
    ' Assembler : MPLAB X IPE v5.15
    ' Target PIC : 16F630
    ' Hardware : Lab Protoboard
    ' Oscillator : Internal 8 MHz.
    ' Keywords : 7 segment display
    ' Description : PICBASIC PRO program to blink an LED connected
    ' to PORTC.0 about once a second.
    ' PORTC.0 is pin 10 of the 16F630.

    #CONFIG
    __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
    #ENDCONFIG

    TRISA = %001000
    TRISC = %000000

    SA var PORTC.0 ' Alias PORTC.0 to SA

    mainloop:
    High SA ' Turn on segment A connected to PORTC.0
    Pause 500 ' Delay for .5 seconds

    Low SA ' Turn off segment A connected to PORTC.0
    Pause 500 ' Delay for .5 seconds

    Goto mainloop ' Go back to loop and blink LED forever

    End

  • #2
    Have you cleared all the ANSEL bits? The PORTC defaults to analog input.
    Dave Purola,
    N8NTA
    EN82fn

    Comment


    • #3
      I didn't think that the 630 had any analog inputs. Maybe I missed it. Anyway, problem solved with a 100 nf capacitor right at the chip Vdd to ground.

      Thanks for the help.

      Jim

      Comment


      • #4
        Oh, Excuse me, I was looking et the combined data sheet for the 16F630/16F676. You are correct. I need to slow down....
        Dave Purola,
        N8NTA
        EN82fn

        Comment


        • #5
          Well, shucks. Another modification, another stumbling block. I don't care for bells and whistles, or printout of values, I just want to step through the program one line at a time to see if it is doing what I'm asking it to do. Anybody got a quick and dirty way of doing this? It compiles just fine, but I might as well be programming a rock for the output I get.

          JIm

          Comment


          • #6
            Jim,
            If you're using MicroCodeStudio it has a built in soft/firmware assisted debugger where you can set breakpoints, singlestep and so on. It relies on the UART peripheral in the PIC and unfortunately the 16F630 does not have one but if you're open to changing out the '630 for something that does have an onboard UART then the MCS ICD might be something for you to look into.

            Note that the free version of MicroCodeStudio supports a limited number of parts where the ICD will work. The Plus version supports a larger number of parts "directly" and comes with (what they call) a model creator so it can create ICD build files for "any" part - as long as it has an UART.

            If you're interested in this then I suggest you click Help in MicroCodeStudio, look up ICD Overview and start from there.

            If that's not an option then you have to resort to MPLAB and the use of an actual debugger (like a PICKit3 for example). Setting up PBP inside of MPLAB can be a pain and the source level debugging is (unfortunatley) quite limited.

            /Henrik

            EDIT: You can always post the code for us to look at.

            Comment


            • #7
              OK, I've got the WHOLE thing working right now just fine with one exception. I want the user to have to push a button to run it through its routine. I do NOT want to use the BUTTON command in PBPro but something that i can explain to the students how it works. Using the simplest commands possible, could somebody post a code snippet on how to do that.

              I have PORTA.0, PORTA.1, and PORTA.2 available to use and I know how to set each one to an input and I can pull each or all of them high with a simple resistor and a NO pushbutton switch. I canNOT seem to get it to not let the user in as soon as power is applied. Frustrating.

              Thanks,

              Jim

              Comment


              • #8
                IF PORTA.0 = 0 THEN. ;Button is pushed
                PAUSE 10. ;You can play with this value to adjust sensitivity
                IF PORTA.0 = 0 THEN. ;Button is still pushed, Debounced
                ;Take Action, Do Something
                ENDIF
                ENDIF
                ;Then don't pay attention to PORTA.0 for at least 500 ms.
                We can crack this cotton PIC'n thang!

                Comment


                • #9
                  Mike ... your code does exactly what my code does....the buttonpush routine does not stop execution, it just goes right through it to mainloop;. I hope you can see where I screwed up your code. Thanks, Jim

                  ' Name : 7segjw4.bas
                  ' Compiler : PICBASIC PRO Compiler 3.1
                  ' Assembler : MPLAB X IPE v5.20
                  ' Target PIC : 16F630
                  ' Hardware : Lab Protoboard
                  ' Oscillator : Internal 4 MHz.
                  ' Keywords : 7 segment display
                  ' Description : PICBASIC PRO program to blink a 7-segment digital
                  ' LED display.
                  '
                  ' Definitions segment dp is Port C.0 Pin 10
                  ' segment a is port C.1 pin 9
                  ' segment b is port C.2 pin 8
                  ' segment c is port C.3 pin 7
                  ' segment d is port C.4 pin 6
                  ' segment e is port C.5 pin 5
                  ' segment f is port A.5 pin 2
                  ' segment g is port A.4 pin 3
                  '
                  ' number 0 is a,b,c,d,e,f
                  ' number 1 is b.c
                  ' number 2 is a,b,d,e,g
                  ' number 3 is a,b,c,d,g
                  ' number 4 is b,c,f,g
                  ' number 5 is a,c,d,f,g
                  ' number 6 is c,d,e,f,g
                  ' number 7 is a,b,c
                  ' number 8 is a,b,c,d,e,f,g
                  ' number 9 is a,b,c,f,g
                  '

                  #CONFIG

                  __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF

                  #ENDCONFIG

                  TRISA = %00000001
                  TRISC = %00000000




                  DP var PORTC.0 ' Alias PORTC.0 to DP
                  SA var PORTC.1 ' Alias PORTC.1 to SA
                  SB var PORTC.2 ' Alias PORTC.2 to SB
                  SC var PORTC.3 ' Alias PORTC.3 to SC
                  SD var PORTC.4 ' Alias PORTC.4 to SD
                  SE var PORTC.5 ' Alias PORTC.5 to SE
                  SF var PORTA.5 ' Alias PORTA.5 to SF
                  SG var PORTA.4 ' Alias PORTA.4 to SG



                  IQ var byte ' Loop variable
                  NN var byte ' number variable

                  gosub portset

                  pushbutn:

                  IF PORTA.0 = 0 THEN ;Button is pushed
                  PAUSE 50 ;debounce sensitivity
                  IF PORTA.0 = 0 THEN ;Button is still pushed, debounced
                  GOTO mainloop ;Go to the main program
                  ENDIF
                  ENDIF
                  PAUSE 500 ;Wait 500 milliseconds for things to settle down
                  GOTO pushbutn


                  mainloop:

                  NN=5
                  Gosub decpt
                  PAUSE 500

                  NN=2 'segment a
                  HIGH SA
                  gosub decpt
                  Pause 1000
                  gosub portset


                  HIGH SB 'segment b
                  gosub decpt
                  Pause 1000
                  gosub portset

                  *****************************************
                  LOTS OF OTHER CODE IN HERE TO LIGHT SEGMENTS AND DIGITS
                  *****************************************


                  goto pushbutn
                  goto mainloop
                  end


                  decpt:
                  FOR IQ = 1 to NN

                  High DP
                  Pause 500
                  Low DP
                  Pause 500
                  NEXT IQ
                  return

                  portset:

                  PORTC.0 = 0
                  PORTC.1 = 0
                  PORTC.2 = 0
                  PORTC.3 = 0
                  PORTC.4 = 0
                  PORTC.5 = 0

                  PORTA.0 = 1
                  PORTA.4 = 0
                  PORTA.5 = 0
                  Return



                  Comment


                  • #10
                    Code:
                    TRISA = %00000001
                    PORTA.0 = 1
                    Initially you set PORTA.0 as an Input with TRISA =. Then you inadvertently set it as an output (actually the compiler did it for you) when you used the command PORTA.0 =. Get rid of PORTA.0 = if you're using it as a button input.
                    We can crack this cotton PIC'n thang!

                    Comment


                    • #11
                      nonsense

                      Initially you set PORTA.0 as an Input with TRISA =. Then you inadvertently set it as an output (actually the compiler did it for you) when you used the command PORTA.0 =. Get rid of PORTA.0 = if you're using it as a button input.
                      if you went

                      HIGH PORTA.0

                      OR


                      LOW PORTA.0


                      Then yes that would happen but NEVER with porta.0 = xx

                      Comment


                      • #12
                        Did you try deleting that line & trying it?
                        We can crack this cotton PIC'n thang!

                        Comment


                        • #13
                          Yes, I've tried a whole bunch of stuff, including deleting the line you told me to. Here is the WHOLE listing if you can find why it is just blowing through the button routine without the button being pressed/

                          ' Name : 7segjw4.bas
                          ' Compiler : PICBASIC PRO Compiler 3.1
                          ' Assembler : MPLAB X IPE v5.20
                          ' Target PIC : 16F630
                          ' Hardware : Lab Protoboard
                          ' Oscillator : Internal 4 MHz.
                          ' Keywords : 7 segment display
                          ' Description : PICBASIC PRO program to blink a 7-segment digital
                          ' LED display.
                          '
                          ' Definitions segment dp is Port C.0 Pin 10
                          ' segment a is port C.1 pin 9
                          ' segment b is port C.2 pin 8
                          ' segment c is port C.3 pin 7
                          ' segment d is port C.4 pin 6
                          ' segment e is port C.5 pin 5
                          ' segment f is port A.5 pin 2
                          ' segment g is port A.4 pin 3
                          '
                          ' number 0 is a,b,c,d,e,f
                          ' number 1 is b.c
                          ' number 2 is a,b,d,e,g
                          ' number 3 is a,b,c,d,g
                          ' number 4 is b,c,f,g
                          ' number 5 is a,c,d,f,g
                          ' number 6 is c,d,e,f,g
                          ' number 7 is a,b,c
                          ' number 8 is a,b,c,d,e,f,g
                          ' number 9 is a,b,c,f,g
                          '

                          #CONFIG

                          __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF

                          #ENDCONFIG

                          TRISA = %00000001 ;sets Port A.0 to input, all the rest to output
                          TRISC = %00000000 ;sets all C ports to output




                          DP var PORTC.0 ' Alias PORTC.0 to DP
                          SA var PORTC.1 ' Alias PORTC.1 to SA
                          SB var PORTC.2 ' Alias PORTC.2 to SB
                          SC var PORTC.3 ' Alias PORTC.3 to SC
                          SD var PORTC.4 ' Alias PORTC.4 to SD
                          SE var PORTC.5 ' Alias PORTC.5 to SE
                          SF var PORTA.5 ' Alias PORTA.5 to SF
                          SG var PORTA.4 ' Alias PORTA.4 to SG



                          IQ var byte ' Loop variable
                          NN var byte ' number variable

                          gosub portset

                          pushbutn:

                          IF PORTA.0 = 0 THEN ;Button is pushed
                          PAUSE 50 ;debounce sensitivity
                          IF PORTA.0 = 0 THEN ;Button is still pushed, debounced
                          GOTO mainloop ;Go to the main program
                          ENDIF
                          ENDIF
                          PAUSE 500 ;Wait 500 milliseconds for things to settle down
                          GOTO pushbutn


                          mainloop:

                          NN=5
                          Gosub decpt
                          PAUSE 500

                          NN=2 'segment a
                          HIGH SA
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SB 'segment b
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SC 'segment c
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SD 'segment d
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SE 'segment e
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SF 'segment f
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SG 'segment g
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SA 'all segments
                          HIGH SB
                          HIGH SC
                          HIGH SD
                          HIGH SE
                          HIGH SF
                          HIGH SG
                          gosub decpt
                          Pause 1000
                          gosub portset


                          NN=2 'digit 1
                          HIGH SB
                          HIGH SC
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SA 'digit 2
                          HIGH SB
                          HIGH SD
                          HIGH SE
                          HIGH SG
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SA 'digit 3
                          HIGH SB
                          HIGH SC
                          HIGH SD
                          HIGH SG
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SB 'digit 4
                          HIGH SC
                          HIGH SF
                          HIGH SG
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SA 'digit 5
                          HIGH SC
                          HIGH SD
                          HIGH SF
                          HIGH SG
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SC 'digit 6
                          HIGH SD
                          HIGH SE
                          HIGH SF
                          HIGH SG
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SA 'digit 7
                          HIGH SB
                          HIGH SC
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SA 'digit 8
                          HIGH SB
                          HIGH SC
                          HIGH SD
                          HIGH SE
                          HIGH SF
                          HIGH SG
                          gosub decpt
                          Pause 1000
                          gosub portset


                          HIGH SA 'digit 9
                          HIGH SB
                          HIGH SC
                          HIGH SF
                          HIGH SG
                          gosub decpt
                          Pause 1000
                          gosub portset



                          HIGH SA 'digit 0
                          HIGH SB
                          HIGH SC
                          HIGH SD
                          HIGH SE
                          HIGH SF
                          gosub decpt
                          Pause 1000
                          gosub portset

                          goto pushbutn
                          goto mainloop
                          end


                          decpt:
                          FOR IQ = 1 to NN

                          High DP
                          Pause 500
                          Low DP
                          Pause 500
                          NEXT IQ
                          return

                          portset:

                          PORTC.0 = 0
                          PORTC.1 = 0
                          PORTC.2 = 0
                          PORTC.3 = 0
                          PORTC.4 = 0
                          PORTC.5 = 0

                          PORTA.4 = 0
                          PORTA.5 = 0
                          Return



                          Comment


                          • #14
                            you have not disabled the comparator, a0 a1 a2 are controlled by it , a0 a1 are configured as analog i/p's


                            Did you try deleting that line & trying it?
                            myths and legend help nobody

                            Comment


                            • #15
                              Originally posted by richard View Post
                              you have not disabled the comparator, a0 a1 a2 are controlled by it , a0 a1 are configured as analog i/p's



                              myths and legend help nobody
                              Then again, neither do answers that do not shed any light on the original question. If you would stop trying to pick the nits from other folks that answered and explain in a line or two what you find the error is it would help greatly. I had teachers in college that would simply snap "the answer is in chapter 4 of the text, look it up yourself" and others that would open the text and explain what the answer is and a little bit about it, The time taken would be about the same, but I can name the helpers from the snots some 60 years later. And I still, after 40 years of answering the same questions of MY college students, will give them a few minutes of my time to be sure they understand what the right answer is.

                              Capiche?

                              jim

                              Comment

                              Working...
                              X