Searching \ for 'Code Problem... What is wrong?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=code+problem+what
Search entire site for: 'Code Problem... What is wrong?'.

Truncated match.
PICList Thread
'Code Problem... What is wrong?'
1998\01\19@140715 by Radboud Verberne

flavicon
face
Hello EveryOne,

I've written a piece of code... But unfortualy it doen not work right...
The 16c84 communicates with 3 CD4094 IC's. (Serial to parrallel). The error
MUST be in the hef4094 routine, but i can't finft the error... Who can find
the problem?

(-----Cut----)
SendOne
       bsf DATA
       call wait
       bsf CLOCK
       call wait
       bcf DATA
       nop
       bcf CLOCK
       return

SendZero
       bcf CLOCK
       call wait
       bsf CLOCK
       call wait
       bcf CLOCK
       return

hef4094
       movwf txbyte
       movlw 0x07
       movwf bitcount
Sendbit
       btfss txbyte, bitcount  ; Skip next line if bit is set.
       call SendZero           ; Sends a 0
       call SendOne            ; Sends a 1
       decfsz bitcount,1       ; Decrement bitcount, SKip if Zero
       goto Sendbit
      return

(----Cut-----)

main
       movlw 0xFF
       call hef4094
       movlw 0x00
       call hef4094
       movlw 0x00
       call hef4094
       goto main
end

This piece of code should make 8 of the 24 bits high... But when I look at
the outputs of the CD4094 it isn't...
He problably sends one Bit to much or something...
Greetz,
       Radboud Verberne.


ICQ: 918640 (I Seek You)

AX25: spam_OUTNL1DDUTakeThisOuTspamNL3SMG.NBO.NLD.EU (27.405Mhz)
     PE1RUH@PI8SHB.#NBO.NLD.EU (144.925Mhz)

Yes! I've succeeded my Radio Examenation! My call is PE1RUH!
I've rebuilt a Teletron T813 and i'm most of the time QRV on
145.2125 or 145.7000 (Relais Eindhoven).

S-Mail: Eerste Vijverstraat 6
       5258 HR Berlicum, The Netherlands
Phone:  +31-73-503-4733

"Er is hier niks te doen, maar begin er maar alvast mee..."

1998\01\19@154603 by Michael S. Hagberg

flavicon
face
every time you send a '1' bit it works find, but every time you send a '0'
bit it will then send a '1' bit when it returns from the call.

solution 1. change call's to goto's and return to goto label just after the
goto sendone line.

solution 2. use straightline coding and get rid of the call's and goto's

michael


>Sendbit
>        btfss txbyte, bitcount  ; Skip next line if bit is set.
>        call SendZero           ; Sends a 0
>        call SendOne            ; Sends a 1

1998\01\19@174413 by Greg Maki

flavicon
face
At 07:32 PM 1/19/98 +0100, you wrote:
{Quote hidden}

Radbound,

I believe your biggest problem is trying to use a variable to select the
bit number. BTFSS needs a constant for the bit number so what it does is
use the address (probably truncated to 3 bits) of the variable <bitcount>.
Also, when you call SendZero, it returns and calls SendOne immediately.

You might try:

Sendbit
               rrf     txbyte,f        ;rotate LSB into carry bit
               btfss   STATUS,C        ;is it a 0
                goto   Zero            ;yes, send a zero bit
               call    SendOne ;no, send a one bit
               goto    Nextbit ;go check bit counter
Zero            call    SendZero        ;go send a zero bit
Nextbit decfsz  bitcount,f      are we done?
                goto   Sendbit
               return

I haven't tested this code or optimized it but it should work. Hope this
helps!

Greg Maki

1998\01\19@182505 by TONY NIXON 54964

flavicon
picon face
>hef4094
>        movwf txbyte
>        movlw 0x07
>        movwf bitcount
>Sendbit
>        btfss txbyte, bitcount  ; Skip next line if bit is set.
>        call SendZero           ; Sends a 0
>        call SendOne            ; Sends a 1
>        decfsz bitcount,1       ; Decrement bitcount, SKip if Zero
>        goto Sendbit
>       return

You will never transmit bit 0 using this routine, and it will always
transmit an extra 1 bit if you try to send a 0 bit. Also any new data
that you send will not appear at the outputs of the 4094 until the
next bit send is executed. ie CLOCK = high.

Try this.....

hef4094
     movwf txbyte
     movlw 0x08
     movwf bitcount
Sendbit
     rlf txbyte
     btfss status,carry
     goto send0
     call SendOne
     goto OneLess
Send0
     call SendZero
OneLess
     decfsz bitcount
     goto Sendbit
     return

Also try this for the SendOne/Zero routine.....

     ; Clock bit is normally HIGH, so that previous data is already
     ; at the output gates.

SendZero
     bcf Port(x),DATA    ; send 0 bit
     goto ClkOut

SendOne
     bsf Port(x),DATA    ; send 1 bit
ClkOut
     call wait
     bcf Port(x),CLOCK   ;  strobe data to latches
     call wait
     bsf Port(x),CLOCK    ; send data to output pins
     ; the next instruction depends on how many instructions
     ; are executed before this routine is called again
     ; (may not be needed if clock speed is low)
     call wait
     return


I know you have already tried it, but it's fairly easy to trap
errors like these by using MPSIM or MBLAB simulator and single step
through the code. Another thing that is sometimes hard, but very necessary,
is to make sure the code is compatable with any external devices, or
you may suffer many frustrated hours of fruitless debugging.
This means a close examination of the device data sheet.

Tony

For the beginner....
PicNPoke Multimedia 16F84 Simulator Assembler, and Tutorial.
Now with PicNPlay circuit simulator.
Plus animated Address Mode Tutor.

http://www.dontronics.com/picnpoke.html

1998\01\20@054947 by paulb

flavicon
face
Radboud Verberne wrote:

> SendOne
>         bsf DATA
>         call wait
>         bsf CLOCK
>         call wait
>         bcf DATA
>         nop
>         bcf CLOCK
>         return

> SendZero
>         bcf CLOCK
>         call wait
>         bsf CLOCK
>         call wait
>         bcf CLOCK
>         return

 Presumably DATA and CLOCK are defined as a register,bit combination?
Non-critical: Why are these routines assymetric?  What is that NOP doing
there?  Why do you need "wait" calls anyway (is the CPU too fast)?  Is
DATA initialised as clear in case SendZero is called first?

> hef4094
>         movwf txbyte
>         movlw 0x07
>         movwf bitcount
> Sendbit
>         btfss txbyte, bitcount  ; Skip next line if bit is set.

 How did bitcount get into this line?  You can't use a variable as a
bit index into another variable (register)!

>         call SendZero           ; Sends a 0
>         call SendOne            ; Sends a 1

 Hey!  Since when do you want every zero to be succeeded by a one?

{Quote hidden}

 If you leave it looping all the time, the output states will be
changing so fast you'll never see what they are!  (You forgot the strobe
function just before the loop.)

 How about:

SendByte
       movwf txbyte
       movlw 8
       movwf bitcount
clockit
       movlw ck0dt1            ; default data high
       rlf   txbyte            ; MSB first convention, alter if needed
       skcs                    ; macro
       movlw ck0dt0            ; C bit zero: alter data to low
       movwf serio             ; write DATA, CLOCK low
       iorlw ck1dt0            ; add in CLOCK bit
       movwf serio             ; write DATA, CLOCK high
       andlw ck0dt1            ; clear CLOCK bit
       movwf serio             ; write DATA, CLOCK low
       decfsz bitcount         ; loop 8 times
       return

main
       movlw ck0dt0            ; initialise clock & data values
       movwf serio             ; write DATA, CLOCK low
       movlw 0xFF
       call SendByte
       movlw 0x00
       call SendByte
       movlw 0x00
       call SendByte
       movlw ck0dt0+strobe     ; Strobe
       movwf serio             ; the data
       goto main

 Is that all OK?  By setting the I/O register with a pure write each
time, you can safely ignore read-modify-write problems.  The reload of
W between every I/O write should be adequate time for the CMOS to settle
but if you do need a delay routine, you put the "movwf serio" at the
beginning of it and make sure it doesn't alter W.  The following doesn't
alter W but uses up to three stack locations:

dely16  call dely8
dely8   call dely4
dely4   return

 Cheers,
       Paul B.

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...