Searching \ for ' zero flag is never set!!!' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=zero+flag+never
Search entire site for: 'zero flag is never set!!!'.

No exact or substring matches. trying for part
PICList Thread
'[PICLIST] zero flag is never set!!!'
2000\06\20@085438 by Chunhee Song

flavicon
face
Good morning,

 I was trying to get a character 'c' from rxreg and if it is 'c'
my program has to do something.

'c' i saved in temp register.
;I already did bit processing in case,
movf    temp, w
andlw   oxff
movwf   temp;
.....
movlw   0x63    ; since c is 0x63 in hexadecimal
xorwf   temp, w
btfss   status, z
 goto  dosomething
dosometing....

but zero flag is never set. what's wrong with this code?

--chunhee

2000\06\20@091526 by Martin Hill

picon face
>
>   I was trying to get a character 'c' from rxreg and if it is 'c'
> my program has to do something.
>
> 'c' i saved in temp register.
> ;I already did bit processing in case,
> movf    temp, w
> andlw   oxff
> movwf   temp;

I can't really see the point of this section.  Surely it just moves temp
to w and then back again.



> .....
> movlw   0x63    ; since c is 0x63 in hexadecimal
> xorwf   temp, w
> btfss   status, z
>   goto  dosomething
> dosometing....

Apart from the fact you are executing the same code irrespective of
the state of Z this looks O.K.  The only thing that could be wrong is if
c is not 0x63.  I would use.

movlw   'c'
xorwf   temp, w
btfss   status, z
goto  dosomething
dosometingelse....
;whatever you do when it is a 'c'

dosomething
;whatever you do when it isn't a 'c'


Martin

2000\06\20@095941 by Chunhee Song

flavicon
face
thanks for your reply, Martin.

But still zero flag is never set.
I spent more than 4 hours for this part but didn't get right. I am very
sure I got 'c' in rxreg register. I tested it. Here is some more specific
code.

** cw_ccw has 'c' **
       bcf     status, rp0     ; cw_ccw is in bank 0
       movlw   'c'
       xorwf   cw_ccw, w               ; 0x63 is "c"
       btfss   status, z
         goto  coclockwise     ; zero flag occurred
clockwise
       bsf     STATUS,RP0      ; select page 1 registers
       bcf     trisc, 2
       bsf     trisc, 3        ; high
       bcf     trisc, 4        ; low
         goto  dirok
coclockwise
       bsf     STATUS,RP0      ; select page 1 registers
       bcf     trisc, 2
       bcf     trisc, 3        ; low
       bsf     trisc, 4        ; high
dirok
       bcf     STATUS,RP0      ; select page 0 registers
       movlw   0x01            ; prescaler 1:4
       movwf   t2con
       bsf     T2CON,tmr2on    ; enable timer2
       movlw   0x3f            ; pwm mode
       movwf   CCP1CON

This code always ends up heading to coclckwise even though cw_ccw has 'c'.
Any idea???

On Tue, 20 Jun 2000, Martin Hill wrote:

{Quote hidden}

2000\06\20@101840 by Andrew Kunz

flavicon
face
Is STATUS defined correctly?  Got the right EQU?  How about Z?

Please post the OBJECT code (the numbers) so we can verify that.

Also, how do you know it is only going to the same place?  By the output that
appears on the port pins?

You realize that TRISC is on BANK1 but PORTC is on bank0, I hope.  Did you set
PORTC to some value ___AND THEN NEVER READ PORTC?____  Otherwise, PORTC could
float high/low and confuse the outputs that you are seeing.

Are you doing this in an emulator or just on a real chip?

Is CW_CCW on BANK0 or BANK1?

Andy









Chunhee Song <spam_OUTchunheeTakeThisOuTspamLPL.ARIZONA.EDU> on 06/20/2000 09:59:04 AM

Please respond to pic microcontroller discussion list <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>








To:      PICLISTspamKILLspamMITVMA.MIT.EDU

cc:      (bcc: Andrew Kunz/TDI_NOTES)



Subject: Re: zero flag is never set!!!








thanks for your reply, Martin.

But still zero flag is never set.
I spent more than 4 hours for this part but didn't get right. I am very
sure I got 'c' in rxreg register. I tested it. Here is some more specific
code.

** cw_ccw has 'c' **
       bcf     status, rp0     ; cw_ccw is in bank 0
       movlw   'c'
       xorwf   cw_ccw, w               ; 0x63 is "c"
       btfss   status, z
         goto  coclockwise     ; zero flag occurred
clockwise
       bsf     STATUS,RP0      ; select page 1 registers
       bcf     trisc, 2
       bsf     trisc, 3        ; high
       bcf     trisc, 4        ; low
         goto  dirok
coclockwise
       bsf     STATUS,RP0      ; select page 1 registers
       bcf     trisc, 2
       bcf     trisc, 3        ; low
       bsf     trisc, 4        ; high
dirok
       bcf     STATUS,RP0      ; select page 0 registers
       movlw   0x01            ; prescaler 1:4
       movwf   t2con
       bsf     T2CON,tmr2on    ; enable timer2
       movlw   0x3f            ; pwm mode
       movwf   CCP1CON

This code always ends up heading to coclckwise even though cw_ccw has 'c'.
Any idea???

On Tue, 20 Jun 2000, Martin Hill wrote:

{Quote hidden}

2000\06\20@110744 by Alan B. Pearce

face picon face
Are you sure that you are not sending a capital "C" and only testing for a lower
case "c"???

2000\06\20@111946 by -1?Q?Martin_Sch=E4fer?=

flavicon
face
Is cw_ccw in Bank 0 or Bank 1 ? :-)

greetings Martin

;**********************************************
;**   name:      Martin Schaefer             **
;**   company:   elektronik 21 GmbH, Germany **
;**   e-mail:    .....schaeferKILLspamspam.....elektronik21.de    **
;**********************************************


> {Original Message removed}

2000\06\20@112157 by -1?Q?Martin_Sch=E4fer?=

flavicon
face
You also could do a

subwf   cw_ccw,W

instead.


Martin


;**********************************************
;**   name:      Martin Schaefer             **
;**   company:   elektronik 21 GmbH, Germany **
;**   e-mail:    EraseMEschaeferspam_OUTspamTakeThisOuTelektronik21.de    **
;**********************************************


> {Original Message removed}

2000\06\20@124105 by Chunhee Song

flavicon
face
part 1 758 bytes content-type:TEXT/PLAIN; charset=US-ASCII
Thanks, guys. Sadly nothing worked so far!

cw_ccw is in bank 0. I tried sublw but didn't work. I am
sending low capital 'c'. I am using real 16873.
About Andy's comment "Did  you  set PORTC to some value ___AND THEN NEVER
READ PORTC?____ ", I cleard portc in bank 0.
In fact, when I read datasheet, it talked about setting TRISC
but didn't mention about setting portc. Since I am a novice, I was
looking for how to set portc but didn't find it. Hopefully this is good
chance to learn it. Could you guys look at my all code? It is about 200
long. I am sending 2 bytes and the first one is for duty cycle and the
second one is for direction. When I used direction byte for duty cycle,
it worked! I am very desperate now.

Thanks again.

--chunhee


part 2 5692 bytes content-type:TEXT/PLAIN; charset=US-ASCII; name="motor620.asm"
(decoded base64)

;        6/20/00        pwm && uart
&& a/d
;        DUTY CYCLE #########  look at pwm_u3.asm #########

;        uart and duty cycle and a/d

;        !!!!!!! baud rate 19200!!!!!!

;        step response for dc motor

;        basically trying to reverse direction in this program

;
       usart partially from thomas mcgahee

       list        p=16f873



       #include         p16f873.inc

       list



       __config        _xt_osc & _wdt_off & _pwrte_on & _cp_off & _lvp_off



       CBLOCK 0x20

       savew

       savestatus

       savefsr

       savepclath

       rx_data

       tx_data

       pwm_out

       cw_ccw

       ENDC



xtal_freq        =        d'4000000'        ; 4Mhz

clock                =        xtal_freq/4



; reset vector address

       org     0x00

       goto    init





; interrupt vector address

       org     0x04

       goto    isr





isr

       movwf        savew

       swapf        status, w

       movf        savestatus

       movf        fsr, w

       movwf        savefsr

       movf        pclath, w

       movwf        savepclath



intreturn        bcf        intcon, t0if



intclean

       movf        savepclath, w

       movf        pclath

       movf        savefsr, w

       movwf        fsr

       swapf        savestatus, w

       movwf        status

       swapf        savew, f

       swapf        savew, w



       retfie

;********************************

; start main program





init

       bcf        status, rp0



       bcf        intcon, gie        ;gie turn off

       clrf        sspcon                ;sync serial not used

       clrf        pir1                ;clear all peripheral flags

       clrf        pir2

       clrf        tmr0

       clrf        porta

       clrf        portb

       clrf        portc

       clrf        rx_data

       clrf        tx_data



       bsf        status, rp0



       clrf        pie1                ; disable peripheral interrupt

       clrf        pie2



       movlw        0x00

       movwf        trisb                ;all output

       movlw        b'11000000'

       movwf        trisc



       movlw        b'11010111'        ; prescaler 1:256 timer0 internal clk

       movwf        option_reg



;;a/d initialize

       movlw        b'00000001'

       movwf        trisa                ; ra0 input

       movlw        b'00001110'

       movwf        adcon1                ;left justfied, ra0 input

       bcf        pie1, adie        



       bcf        status, rp0

       movlw        b'01000001'        ; a2d on, ch0, fosc/8

       movwf        adcon0



       movlw        d'61'                ; expecting 50msec sampling frequency  20hz

       movwf        tmr0                ; timer 0



       bcf        intcon, t0ie

;uart

       bsf        status, rp0

       movlw        b'00100000'

       movwf        txsta



baudrate = d'19200'

spbrg_value        =        (xtal_freq/(baudrate*d'64')) -1

       movlw        spbrg_value

       movwf        spbrg



       bcf        status, rp0



       movlw   b'10010000'     ; Enable continous reception

       movwf   RCSTA



       movf        rcreg, w

       movf        rcreg, w

       movf        rcreg, w



       movlw        0

       movwf        txreg                ; send out dummy character

                               ; to get transmit flag valid!



main

       bsf        intcon, gie



       call    srl_in



       call    init_pwm



;a/d conversion and transfer data to pc



tm0        btfss        intcon, t0if

         goto        tm0

       bcf        intcon, t0if

adcon_send

       bcf        status, rp0

       bsf        adcon0, go_done        ; start conversion

stillconverting

       btfsc        adcon0, go_done

         goto        stillconverting

conversionDone

       movf        adresh, w

       andlw        0xff        

xmit

       btfss        pir1, txif

         goto        xmit

       bcf        intcon, gie

       movwf        txreg

       bsf        intcon, gie



       goto        tm0





;********************************

;********************************

; subroutine to setup serial comm



srl_in

       bcf        status, rp0        ; THIS BANK SELECTION IS VERY IMPORTANT!!!!!!

       btfsc   RCSTA,oerr      ; check framing error  

       goto    overerror         ; Found error, flag it

       btfsc   RCSTA,ferr         ; check overrun error  

       goto    frameerror         ; Found error, flag it



       ; test for serial data available

dutyCycle

       btfss   PIR1,rcif          ; Check for serial data ready

       goto    dutyCycle       ;

       

       bcf        intcon, gie

       ; serial data rcvd, read to relax h/w + save

       movf    RCREG,W         ; queue input data

       bsf        intcon, gie

       movwf   rx_data

       movwf        pwm_out                ;

direction

       btfss        PIR1, rcif

       goto        direction



       bcf        intcon, gie

       movf        rcreg, w

       bsf        intcon, gie

       movwf        cw_ccw                ; ****** DIRECTION INPUT, EXPECT  'c' as clockwise

       return



overerror

       bcf        rcsta, cren

       movf        rcreg, w

       movf        rcreg, w

       movf        rcreg, w

       bsf        rcsta, cren



       goto        srl_in



frameerror

       movf        rcreg, w

       goto        srl_in



       

;********************************

; subroutine to setup pwm



init_pwm

       bsf     STATUS,RP0      ; select page 1 registers

       movlw   0xff            ; 1220 hz pwm

       movwf   PR2



       bcf     STATUS,RP0      ; select page 0 registers



;###############duty cycle#############################

       bcf        status, c

       movf        pwm_out, w

       andlw        0x0ff

       movwf        pwm_out



       bcf        status, c

       rlf        pwm_out, 1

       bcf        status, c

       rlf        pwm_out, 1

       bcf        status, c

       rlf        pwm_out, 1

       bcf        status, c

       rlf        pwm_out, 1

       movf        pwm_out, w

       

       movwf   CCPR1L

       bsf     CCP1CON,5       ; lsb+1 of 10 bits

       bsf     CCP1CON,4       ; lsb of 10 bits



; determine motor direction



       movlw        'c'

       xorwf        cw_ccw, w        ; 0x63 is "c"

       btfss        status, z        

         goto        coclockwise        ; zero flag not occurred

clockwise        

       bsf     STATUS,RP0      ; select page 1 registers

       bcf        trisc, 2

       bsf        trisc, 3        ; high

       bcf        trisc, 4        ; low



       bcf        status, rp0        ;  just added, but didn't work!!!!!

       bsf        portc, 3        ;

       bcf        portc, 4        ;

         goto        dirok

coclockwise

       bsf     STATUS,RP0      ; select page 1 registers

       bcf        trisc, 2

       bcf        trisc, 3        ; low

       bsf        trisc, 4        ; high



       bcf        status, rp0

       bcf        portc, 3

       bsf        portc, 4

dirok

       bcf     STATUS,RP0      ; select page 0 registers

       movlw        0x01                ; prescaler 1:4

       movwf        t2con

       bsf     T2CON,tmr2on    ; enable timer2



       movlw   0x3f            ; pwm mode

       movwf   CCP1CON



       return



       end




part 3 2 bytes
-

2000\06\20@124112 by Heinz Czychun

flavicon
face
At 5:52 AM 6/20/2000, Chunhee Song wrote:
> Good morning,
>
>  I was trying to get a character 'c' from rxreg and if it is 'c'
>my program has to do something.
>
>'c' i saved in temp register.
>;I already did bit processing in case,
>movf    temp, w
>andlw   oxff
               Martin's comments triggered these thoughts.
..........^.....I think this should be andlw 0x7F,
               since ASCII only defines 7bits, and 8th bit
               is dependent on the sending implementation.
{Quote hidden}

Regards,
Heinz

2000\06\20@142302 by -1?Q?Martin_Sch=E4fer?=

flavicon
face
I only started to read your code. But there is a serious error in pushing
the STATUS:

isr
       movwf   savew
       swapf   status, w
-->     movf    savestatus
       movf    fsr, w
       movwf   savefsr
       movf    pclath, w
       movwf   savepclath

It should read:

         movwf   savestatus
         bcf       STATUS,RP0

This error means, that if you are in Bank 1 in the Background-routine you
start with bank 1 in isr.

Same in popping:

intclean
       movf    savepclath, w
-->     movf    pclath
       movf    savefsr, w
       movwf   fsr
       swapf   savestatus, w
       movwf   status
       swapf   savew, f
       swapf   savew, w

It should read:
         movwf   pclath

If you clear the GIE you should verify, that it was really cleared:

xmit
       btfss   pir1, txif
         goto  xmit
-->     bcf     intcon, gie
       movwf   txreg
       bsf     intcon, gie

Correct would be:

         bcf       intcon,GIE
         btfsc   intcon,GIE
         goto    $-2


First you should check out these points.

Martin

;**********************************************
;**   name:      Martin Schaefer             **
;**   company:   elektronik 21 GmbH, Germany **
;**   e-mail:    schaeferspamspam_OUTelektronik21.de    **
;**********************************************


> {Original Message removed}

2000\06\22@084846 by Chunhee Song

flavicon
face
 Hello, Martin.

Sorry to email you directly. I have tested the code following your advice,
but no luck. Have you had a change to look at it more? That's ok even though
you haven't.

 My question is when I send 0V to i/o port, can I define the i/o port
as a output and clear the bit such as,

 bcf rp0
 bcf portb, 0
 bsf rp0
 movlw 0xff
 movwf trisb

or, i/o port could be input and clear the bit???
In old assembly, I just used "in" as a input and "out" as a output
but I don't know how to do this with PIC.

Thank you for reading my email. have a great day.

chunhee

2000\06\22@094417 by Byron A Jeff

face picon face
{Quote hidden}

A couple of points:

1) The settin of trisb makes all inputs. You need a 'clrw' instead of
  'movlw 0xff' to make them outputs.

2) Though contriversial using the TRISB instruction is much better here
  instead of fiddling with rp0. Though uChip has threatened discontinuation
  for years, the instruction is still available in all 16XXXX and 17XXXX
  chips.

So try this:

  bcf portb,0
  clrw
  trisb

This should set all of port B to outputs and set portb.0 to 0.

BAJ
>
> chunhee
>

2000\06\23@050006 by -1?Q?Martin_Sch=E4fer?=

flavicon
face
part 1 360 bytes content-type:text/plain;Chunhee,

I tried to look a little bit at your code.

Take a look at the file with my comments.


Greetings
Martin


;**********************************************
;**   name:      Martin Schaefer             **
;**   company:   elektronik 21 GmbH, Germany **
;**   e-mail:    @spam@schaeferKILLspamspamelektronik21.de    **
;**********************************************




part 2 7631 bytes content-type:application/octet-stream; (decode)

part 3 2 bytes
-

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