Announcement

Collapse
No announcement yet.

Variable Altering

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

  • Variable Altering

    I know this code is a little wanky but I get it to the section (I'll mark it with a '*') where I'm displaying, through 'debug', 'PULSE' and a value in variable B0. I expect to display the value B0 initially obtained from section/label: 'LOOK' but instead I get usually) a number '1' or '0'. Missing something in there.
    Not sure if the pasting of the code is infuriating. If it is then what's the best way to show it on the forum?

    '****************************************************************
    '* Name : Bob.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2021 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 11/16/2021 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '****************************************************************
    PAUSE 10
    DEFINE DEBUG_REG PORTC
    DEFINE DEBUG_BIT 1
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 0
    DEFINE DEBUG_PACING 1000
    TRISA=52
    TRISC=32
    ANSELA=0 'turn off A/D
    ANSELC=0
    CM1CON0=0 'turn off comparators
    CM1CON1=0
    CM2CON0=0
    CM2CON1=0
    OSCCON=%01101010
    DEFINE OSC 4
    debug $FE, $58 'clear screen
    pause 10
    B0 var byte 'here's where you store #miliseconds
    B0=0 'put a '0' in there
    B1 var byte 'button debounce 1
    B1=0
    B2 var byte 'button debounce 2
    B2=0
    B3 var byte 'button debounce 3
    B3=0

    show:debug $FE, $58 'clear screen
    debug dec B0 'show B) value
    pause 100
    Look:BUTTON porta.4,1,255,10,B1,1,Startup 'plus's B0
    button porta.5,1,255,10,B2,1,Startdown 'minus's B0
    button portc.5,1,255,10,B3,1,FIRE 'start looking to check sensor pulse
    goto look
    Startup:B0=B0+1 'add 1 unit
    debug $FE, $58
    debug dec b0
    goto look
    Startdown:B0=B0-1 'minus 1 unit
    debug $FE, $58
    DEBUG DEC B0 'show value of milliseconds on screen
    GOTO look 'keep looking for up-down values and FIRE

    FIRE:debug $FE, $58
    debug "PULSE=",dec B0 'show screen B0 value in 'FIRE' mode
    Pause 100
    button portc.5,1,255,10,B3,1,show 'go to back to beginning

    if porta.2=1 then HIT 'looking for sensor 'on'
    'P
    goto FIRE
    HIT:B0=B0*100 'makes screen value true milliseconds 'convert number to milliseconds
    pulsout portc.2,B0 'turn relay on #milliseconds
    B0=B0/100 'brings count back to screen value
    Goto FIRE

  • #2
    You may have an issue in "HIT". "B0=B0/100" can only yield 0, 1, or 2 because B0 is a BYTE that cannot exceed 255. If B0 never exceeds 199, that would explain your 0 or 1 output. You may want to create a new variable for the /100 value and display that in HIT.

    As for posting code in a tidy manner, use bracket then the word CODE in all caps, then an end bracket [ CODE ] to start code. At the end type [ / CODE ] with no spaces in either one. It looks like this:

    Code:
    var = reg
    We can crack this cotton PIC'n thang!

    Comment


    • #3
      That did it Mike. Made a variable word length then called that variable B0.
      Now on the 'button' command, 'Delay' I am guessing is how long things wait before auto-repeating starts with the larger number being the longest time. But on 'Rate' in 'Button', means the time waited between repeats of the button pushed, the larger the number the longer the wait?

      Comment


      • #4
        Thanks for your support mike mine problem solved by your answer keep supporting.
        upsers
        Last edited by Kling121; 01-11-2022, 07:57 PM.

        Comment

        Working...
        X