Menu

Problem with PEEK

Help
2007-04-18
2013-05-30
  • Nobody/Anonymous

    Hi all,

    I'm in the middle of a project using a 16F690 to control an LCD and a scoreboard via a RS-232 link to marshall events. At this stage, I'm only as far as working with the LCD and 4 input buttons. The LCD is connected to Port C and the input buttons are on B.4-7.

    The LCD seems to be working correctly as when I power the circuit, line one shows "`Marshalling... " and line two shows "    00 - 00     ".

    The numbers then go up and down randomly while no buttons are pressed at all e.g. from 00 up to 01, then down to 255 (using LCDInt -1 seems to equal 255). The numbers are not restricted to 00, 01 and 255, they continue up and down in no particular pattern except that they are sequential.

    My code is below - if someone can review and see if there's anything in what I have that might cause this? If anywhere, I would expect it to be something to do with the PEEK commands not working as they should. I should also mention that I have the circuit put together on a breadboard, so perhaps shorting between the pins might be the cause?

    Thanks,

    Grant

    #chip PIC16F690, 20
    #config _CP_OFF & _CPD_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_CLKOUT

    #define LCD_IO 4
    #define LCD_DB4 PORTC.0
    #define LCD_DB5 PORTC.1
    #define LCD_DB6 PORTC.2
    #define LCD_DB7 PORTC.3
    #define LCD_RS PORTC.4
    #define LCD_RW PORTC.5
    #define LCD_Enable PORTC.6

    dir PORTB.4 IN
    dir PORTB.5 IN
    dir PORTB.6 IN
    dir PORTB.7 IN

    Dim Marshalling(16)
    Dim Marshall As Byte
    Dim MarshallButton As Word

    Marshall = 0
    Marshalling() = "Marshalling...  "

    Locate 0,1
    Print Marshalling()

    Locate 1,4
    Print "00 - 00"

    Main:

    MarshallButton = Peek(6)
    If MarshallButton.4 = ON THEN
        Marshall = Marshall + 1
        Locate 1, 4
        GoSub PrintMarshall
    END IF

    IF MarshallButton.5 = ON THEN
        Marshall = Marshall - 1
        Locate 1, 4
        GoSub PrintMarshall
    END IF

    MarshallButton = Peek(6)
    IF MarshallButton.6 = ON THEN
        Marshall = Marshall + 1
        Locate 1, 9
        GoSub PrintMarshall
    END IF

    IF MarshallButton.7 = ON THEN
        Marshall = Marshall - 1
        Locate 1, 9
        GoSub PrintMarshall
    END IF

    goto Main

    PrintMarshall:

        Wait 10 10ms

        IF Marshall < 10 THEN
           Marshalling() = "0" & Marshall
           LCDInt 0
           LCDInt Marshall
        END IF
        IF Marshall >= 10 THEN
           Marshalling() = "" & Marshall
           LCDInt Marshall
        END IF

    Return

     
    • Nobody/Anonymous

      Not sure what all you are trying to score.  Looks like you are trying two different ways to get the same effect?

      Just some random thoughts:

      Marshalling() is only used in the initial setup, and not in Main:.  If thats what you intend, then skip the string variable and just use, Print "Marshalling..."

      Delete or comment out the code that includes the above, in your PrintMarshall sub.  Trying to stick a string "0" or " "  and a variable Marshal into Marshalling(), seems suspect at best.

      Have not used the Peek command.  More likely to use:
      #define MarshallButton PortB

      Maybe picking up some noise on the pushbutton pins?  Should use some debounce or time delays on the buttons like:

      If MarshallButton.4 On Then
      for count = 1 to 3
      wait 10 ms
      If MarshallButton.4 Off Then goto Button5
      Next
      ...
      ...
      End if
      Button5:

      Good Luck.
      Kent

       
    • Grant

      Grant - 2007-04-25

      Thanks Kent,

      Got it sorted - code is below.

      The time delay with a second Peek following fixed the problem. This with some cleaning up of the code - man was it a mess! I must have been drunk or something while writing that!

      > Trying to stick a string "0" or " " and a variable Marshal into Marshalling(), seems
      > suspect at best.

      I'd forgotten to delete this from my code... it was something I had been playing with for sending the numbers out serially. Being a Newbie, I'm still learning and this is what would compile.

      Which brings me to my next problem. The code below displays the "events" being marshalled on the LCD of the console. I need to send this out to the display boards.

      Each board (there's two) has 5 x 7 segment displays. Each 7 segment needs to have a PIC behind it controlling it. I know I could do all 5 off a single PIC, but i'd like to recycle these displays into other projects (I have one in the planning for 10+ displays).

      My thoughts were to give each display an address. I would then separate the digits to be displayed and pass these to the various addresses via a serial connection. For example, if the LCD display showed 01-12, I'd pass to address 1 the digit 0, 2 would receive 1, 3 would get "-" etc.

      I'm going to do some experimenting with this, however is someone has any ideas on the best way to do this, I'd appreciate it.

      Also if anyone has any schematics for sending a serial data signal from one PIC to several PIC's over a distance of about 25m (using UTP cable), then I'd appreciate this too.

      Thanks!

      Grant

      ----------------------------------------------------------------

      #chip PIC16F690, 20
      #config _CP_OFF & _CPD_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_CLKOUT

      #define LCD_IO 4
      #define LCD_DB4 PORTC.0
      #define LCD_DB5 PORTC.1
      #define LCD_DB6 PORTC.2
      #define LCD_DB7 PORTC.3
      #define LCD_RS PORTC.4
      #define LCD_RW PORTC.5
      #define LCD_Enable PORTC.6

      wait 10 10ms

      dir PORTA.3 OUT
      dir B 1

      Dim Marshalling(2)
      Dim MarshallHigh As Byte
      Dim MarshallLow As Byte
      Dim MarshallButton As Word

      MarshallHigh = 0
      MarshallLow = 0

      GoSub ScreenRefresh

      Locate 1,4
      Print "00"

      Locate 1,9
      Print "00"

      Main:

      MarshallButton = Peek (6)
      If MarshallButton.4 ON THEN

          wait 2 10 ms
          MarshallButton = Peek (6)
          If MarshallButton.4 Off Then
              MarshallLow = MarshallLow + 1
              Goto PrintMarshall
          END IF

      END IF

      IF MarshallButton.5 ON THEN

          wait 2 10 ms
          MarshallButton = Peek (6)
          If MarshallButton.5 Off Then
              MarshallLow = MarshallLow - 1
              Goto PrintMarshall
          END IF

      END IF

      If MarshallButton.6 ON THEN

          wait 2 10 ms
          MarshallButton = Peek (6)
          If MarshallButton.6 Off Then
              MarshallHigh = MarshallHigh + 1
              Goto PrintMarshall
          END IF

      END IF

      If MarshallButton.7 ON THEN

          wait 2 10 ms
          MarshallButton = Peek (6)
          If MarshallButton.7 Off Then
              MarshallHigh = MarshallHigh - 1
              Goto PrintMarshall
          END IF

      END IF

      goto Main

      PrintMarshall:

          Gosub ScreenRefresh

          IF MarshallLow < 10 THEN
             Locate 1, 4
             LCDInt 0
             LCDInt MarshallLow

          END IF

          IF MarshallLow >= 10 THEN
             Locate 1, 4
             LCDInt MarshallLow
          END IF

          IF MarshallHigh < 10 THEN
             Locate 1, 9
             LCDInt 0
             LCDInt MarshallHigh
          END IF

          IF MarshallHigh >= 10 THEN
             Locate 1, 9
             LCDInt MarshallHigh
          END IF

      goto Main

      Sub ScreenRefresh

      CLS
      Locate 0,1
      Print "Marshalling..."
      Locate 1,7
      Print "-"

      Return

       
    • Nobody/Anonymous

      Congrats, on an interesting project!  The multiple pic idea, seems like a lot of extra code floating around, with each pic polling for an address all the time.  Using a 74HC595 like device would be cheaper, easier to code, and modular because of its ability to cascade.

      In either case, how about using two software serial lines, one for each board?  Curious to know what the signal quality would be at 25m tho, and whether rs232 transceiver chips would work for the extra distance?

      Kent

       

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.