Bear code test

The bear

Senior Member
Indent failed again.

Rich (BB code):
;IRRIGATION using Buzby timer v1.0a 12.06.19
#picaxe 08m2 ;274 Bytes Toggle C.1 = 12v present
#No_data ;1 HR delay, ON for 1 Hr, OFF for 2 Hrs, ON for 1 HR
#Com 3 ;Resets after 24 Hrs

Sertxd("IRRIGATION using Buzby timer v1.0a 12.06.19",13,10)
Symbol minutes = w2
Symbol hours = w3
Symbol valve = C.2 'was C.4
Symbol valveSupplyLed = C.1
Symbol valvepower = pinC.3
' Start of code
minutes = 0
hours = 0
Do
Do ' Hours loop
time = 0 ' Reset in-built seconds counter
Do ' Minutes loop
;----------------------------------------------------
If valvepower = 0 Then '+12v present
Toggle valvesupplyled 'Flash Led
Endif
;------------------------------------------------
Pause 1000
;Sertxd (#hours,":",#minutes,":",#time,Cr,Lf) 'Com'd out when in use.
Loop Until time > 59 ' *** Should be 59 for one minute
minutes = minutes + 1
Loop Until minutes > 59 ' *** Should be 59 for one hour
hours = hours + 1
minutes = 0
If hours = 1 Then
Sertxd ("Valve operated ON",Cr,Lf)
High valve ' Operate Valve ON for 1 Hour
Endif
If hours = 2 Then ;was 24
Sertxd ("Valve operated OFF",Cr,Lf)
Low valve 'Valve OFF
Endif
If hours = 4 Then ;was 24
Sertxd ("Valve operated ON",Cr,Lf)
High valve 'Valve OFF
Endif
If hours = 5 Then ;was 24
Sertxd ("Valve operated OFF",Cr,Lf)
Low valve 'Valve OFF
Endif
If hours = 24 Then ;was 24

Reset 'Every 24 Hours
Endif
Loop
 

Buzby

Senior Member
Buzby code test ......

Rich (BB code):
; Ultrasonic Triangulation ; AllyCat June 2019
#picaxe 28X2 ;        And most others
#no_data
symbol AL = w1                         ; Low word of Range A
symbol AH = w2                         ; High word of Range A
symbol BL = w3                         ; Low word of Range B
symbol BH = w4                         ; High word of Range B
symbol DL = w5                        ; Baseline spacing
symbol DH = w6                      ; Auxiliary register
symbol rangeA = w1                    ; Input values
symbol rangeB = w3                    ; 
symbol rangeD = w5                    ; Transducer spacing
symbol sign = w4                    ; Sign (flag) used for division subroutine (Overlays BH)

init:
    rangeA = 5000                        ; Test values
    rangeB = 5000
    rangeD = 6000                        ; Transmitter spacing (baseline)
;*  A = a2 - b2 + d2 {s / 2d s}     ; Base formula (s = Signed functions)
[noparse];*  A = a2 - b2 [s / d s] + d / 2   ; Revised formula[/noparse]
Yaxis:
    DH = AL                         ; Store for X-Axis Pythagoras calculation
    AH = rangeA ** rangeA            ; High word of A squared
    AL = rangeA * rangeA            ; Low word of A squared
    BH = rangeB ** rangeB                ; High word of B squared
    BL = rangeB * rangeB                ; Low word of B squared
     call subAB:                      ; Calculate AH:AL = AH:AL minus BH:BL   
div32:
    BL = rangeD                     ; Divisor
    call sdiv                                ; Signed division 32 bits / 16 bits := 16 bits
result:
    AL = AL + rangeD
    if AL > 32767 then                ; Negative value
        AL = -AL / 2
        AL = -AL
    else
        AL = AL / 2
    endif  
    sertxd("Y= ",#AL,cr,lf)          ;  Result
     DL = AL                                    ; Store for later

Xaxis:         ; ** Insert Pythagoras program and Additional subroutine here **  
end

; SUBROUTINES:
sdiv:                                     ; 32 bit Signed division
    sign = 0                             ; Use BH for loop counter and sign flag
    if AH > 32767 then                 ; Negative input
        sign = 1
negateA:                               ; Twos complement of AH:AL
        AL = not AL + 1
        AH = not AH
        if AL = 0 then
         inc AH
        endif
    endif           
div31:                                   ; Divide numerator (AH:AL) by divisor (BL)
   for BH = sign to 63  step 4          ; Repeat for 16 bit positions
       AH = AL / 32768 + AH + AH        ; Add carry and shift numerator left (top bit lost)
       AL = AL + AL                    ; Shift done
       if AH >= BL then                ; Skip if can't subtract
          AH = AH - BL                  ; Subtract divisor, then..
          AL = AL + 1                   ; Add the flag into result (in low word)
        endif    
   next BH                                        ; Result in AL, remainder in AH
    if sign = 65 then                  ; Negative result
       AL = -AL
   endif  
return

subAB:                           ; Calculate AH:AL = AH:AL minus BH:BL  
    AH = AH - BH                 ; Subtract high words    :
    if AL < BL then              ; Borrow if minuend < subtrahend
       dec AH                     ; Borrow for low word
    endif     
    AL = AL - BL                 ; Calculate low word
return
 

lbenson

Senior Member
Bear,

Try typing
[ code]
[ /code]
Without the spaces. Then position the cursor before "[" on the second line and paste in your code. That's what I always do. No colors, but indentation is preserved.
 

Buzby

Senior Member
The opening tag is [CODE=rich] to get the colours.

Why does 'Copy for Forum' not do this automatically ?

BuzbyCodeTest.PNG
 
Last edited:
Top