Searching \ for '[PIC:] 16c54 scanner' 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/microchip/devices.htm?key=16C
Search entire site for: '16c54 scanner'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] 16c54 scanner'
2004\01\11@213931 by Michael Johnston

picon face
Hi guys
 I wrote a program that i adaptive with help from a friend to flash 12 leds tied to  the 12 I/O Pins on c54. I have four routines that rotate the bit pattern through porta and portb forwards and backwards.  My problem is that when the routine is going from porta to portb forward ra3 flashes so fast and jumps to portb bit0 so fast you can not see this happening. It also does this when going backwards from portb to porta. But it portb bit 7 that you dont see flashing. My friend told me the reason this was happening was because of the part i am using so i ported it to F84 and the program did the same thing in this port. I need so type of a delay but everything i try seems to mess my code up.
Thanks
Mike Johnston

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu

2004\01\11@231019 by Tony Nixon

flavicon
picon face
Michael Johnston wrote:

>Hi guys
>  I wrote a program that i adaptive with help from a friend to flash 12 leds tied to  the 12 I/O Pins on c54. I have four routines that rotate the bit pattern through porta and portb forwards and backwards.  My problem is that when the routine is going from porta to portb forward ra3 flashes so fast and jumps to portb bit0 so fast you can not see this happening. It also does this when going backwards from portb to porta. But it portb bit 7 that you dont see flashing. My friend told me the reason this was happening was because of the part i am using so i ported it to F84 and the program did the same thing in this port. I need so type of a delay but everything i try seems to mess my code up.
>Thanks
>Mike Johnston
>
>--
>http://www.piclist.com hint: To leave the PICList
>.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu
>
>
Can you post the code so we can PIC through it :-)

regards

Tony

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu

2004\01\12@004034 by Nick Masluk

picon face
If all you need is a simple delay, here's what I use:


Small delay, up to 769 cycles:

       movlw   n               ;}1 cycle
       movwf   TEMP            ;}1 cycle
       decfsz  TEMP            ;/\
       goto    $-1             ;__> 3n-1 cycles

c=3n+1
where:
c = cycles
n = literal at first instruction, 1 =< n =< 256 (0x001
=< n =< 0x0100, where 0x000=0x0100)


Nested delay, unlimited cycles:

       movlw   n               ;}1 cycle
       movwf   TEMP            ;}1 cycle
loop    (nested delay loop)     ;/\
       decfsz  TEMP            ;  > nd+3n-1 cycles
       goto    loop            ;_/

c=nd+3n+1
where:
c = cycles
n = literal at first instruction, 1 =< n =< 256 (0x001
=< n =< 0x0100, where 0x000=0x0100)
d = number of cycles in nested delay loop

To calculate the length of delay, find the number of
instruction cycles it will complete, and divide that
by the number of instructions per second your PIC is
running at (equal to the frequency of the internal
oscillator divided by four).  Chances are you will
have to use a nested loop if what your are doing is a
visual effect, where you can just plug in the first
delay above into the second (max 197,633 cycles, about
2ms at 4MHz).  If more cycles were needed, you could
then take this delay, and nest it once again in
another loop (max 50,594,817 cycles, about 51s at
4MHz, just make sure that the TEMP register is
different in each loop.  If all you are doing is
blinking lights, delays this long will not matter, but
in other applications this would be a considerable
amount of dead potential processing time, and other
methods of timing would be used.  For more time
critical applications, if there are no possible
combinations of literals to get the exact number of
cycles you need, you would simply find the combination
with the closest number of cycles possible below the
desired number, then add a few nop's.

--Nick


--- Michael Johnston <.....stoney40KILLspamspam.....EARTHLINK.NET> wrote:
{Quote hidden}

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@184357 by Michael Johnston

picon face
part 1 1689 bytes content-type:text/plain; (decoded 7bit)

Tony
   Here is my code you asked for. My delay was adapted from some code on
the pic list archive.
thanks
Mike Johnston
{Original Message removed}
part 2 3841 bytes content-type:application/octet-stream; (decode)

2004\01\12@193926 by Tony Nixon

flavicon
picon face
part 1 1012 bytes content-type:text/plain; charset=ISO-8859-1; format=flowed (decoded 7bit)

Hi Michael,

See new attached code.

Assemble it in MPLAB and add the variabled PB_A and PB_B to the watch
window in binary format.

Comment out the delay_write subroutine calls like this...

       call delay_write

to...

       ; call delay_write

Now assemble and step through the code to see how it works.

When happy, un comment the delay_write subroutine calls and program a
chip to test.

regards

Tony

Michael Johnston wrote:

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads




part 2 3282 bytes content-type:text/plain; name=54.asm
(decoded 7bit)

;*********************************************************************************************
       LIST    p=16c54c
       include "p16c5x.inc"
       radix   hex
;*********************************************************************************************
       cblock  0x08
       D1
       D2
       C1
       PB_A
       PB_B
       endc
;
same    equ     0x01
;**********************************************************************************************
       org     0x000
;**********************************************************************************************
start
       movlw   0x00
       movwf   PORTA   ;porta all bits low
       tris    PORTA   ;porta  all pins output
       movlw   0x00
       movwf   PORTB   ;portb  all bits low
       tris    PORTB   ;aportb all pins output

       movlw b'00000001'
       movwf PB_A      ; used for PORTA LED on, RA0 = 0N to start
       clrf PB_B       ; used for PORTB LED on, all OFF to start

;*********************************************************************************************
; Port A,b Forward
;********************************************************************************************
A_Left
       call delay_write        ; write to port and delay to see it

       bcf STATUS,C    ; shift LED bit left once
       rlf PB_A,same
       btfss PB_A,4    ; if PB_A bit 4 = 1, scan moves into PB_B
       goto A_Left         ; not 1

       clrf PB_A               ; clear bits in PB_A
       movlw b'00000001'       ; set LED ON in PORTB 0
       movwf PB_B

B_Left
       call delay_write        ; write to port and delay to see it
       bcf STATUS,C    ; shift LED bit left once
       rlf PB_B,same
       btfss STATUS,C  ; PB_B = 0 and carry = 1 if all done
       goto B_Left

       movlw b'01000000'       ; start portB moving right
       movwf PB_B

B_Right
       call delay_write        ; write to port and delay to see it
       bcf STATUS,C    ; shift LED bit right once
       rrf PB_B,same
       btfss STATUS,C  ; PB_B = 0 and carry = 1 if all done
       goto B_Right

       movlw b'00001000'       ; set LED ON in PORTA 3
       movwf PB_A      ; PB_B = 0

A_Right
       call delay_write        ; write to port and delay to see it
       bcf STATUS,C    ; shift LED bit right once
       rrf PB_A,same
       btfss STATUS,C  ; PB_A = 0 and carry = 1 is all done
       goto A_Right

       movlw b'00000001'       ; start port A moving left again
       movwf PB_A
       goto A_Left

;**********************************************************************************************
delay_write
       movf PB_A,W     ; set port A and B LED
       movwf PORTA
       movf PB_B,W
       movwf PORTB

         movlw   0x7f        ; delay
         movwf   D1
         clrf    D2
delay_0
         decfsz  D1,f
         goto    $-1
         decfsz  D2,f
         goto    delay_0
         retlw   0x00



;**********************************************************************************************
       end





--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads



2004\01\12@221234 by Michael Johnston

picon face
Tony
thank you I will run this and see what happens
Thanks again
Michael Johnston
----- Original Message -----
From: "Tony Nixon" <KILLspamTony.NixonKILLspamspamENG.MONASH.EDU.AU>
To: <RemoveMEPICLISTTakeThisOuTspamMITVMA.MIT.EDU>
Sent: Monday, January 12, 2004 6:28 PM
Subject: Re: [PIC:] 16c54 scanner


{Quote hidden}

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


>
;***************************************************************************
******************
>         LIST    p=16c54c
>         include "p16c5x.inc"
>         radix   hex
>
;***************************************************************************
******************
>         cblock  0x08
>         D1
>         D2
>         C1
>         PB_A
>         PB_B
>         endc
> ;
> same    equ     0x01
>
;***************************************************************************
*******************
>         org     0x000
>
;***************************************************************************
*******************
{Quote hidden}

;***************************************************************************
******************
> ; Port A,b Forward
>
;***************************************************************************
*****************
{Quote hidden}

;***************************************************************************
*******************
{Quote hidden}

;***************************************************************************
*******************
{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\12@231337 by Michael Johnston

picon face
Tony
thanks again i got a good look at your code and its much eaiser than the
route i was going with this thing.
thank you
Michael
{Original Message removed}

2004\01\12@234240 by Tony Nixon

flavicon
picon face
Hi Michael,

No problem. A scanner is a bit tricky over 1 1/2 ports.

Have fun.

Tony

Michael Johnston wrote:

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\01\13@002417 by Rob Stockley

flavicon
face
On Tue, 2004-01-13 at 12:43, Michael Johnston wrote:
> Tony
>     Here is my code you asked for. My delay was adapted from some code on
> the pic list archive.
> thanks

You've a lot of unnecessary stuff and the delays are misplaced. I'm
relatively new to PICs but these are my observations and example code,

* don't need counter since last bit already serves as a limit so no need
to check Z either.
* before you set the next bit check it is not the last bit
* set the next bit then delay not the other way around
* don't need to clear C since your rotates should never carry and you
never checked it anyway

;put your setup stuff here

start_condition
       clrf    PORTB           ;clear all portb
       movf    0x01
       movwf   PORTA           ;set only pin0 on porta
pointaf
       btfsc   PORTA,3         ;if bit 3 is lit
       goto    change_ab       ;then we're ready to change ports
       rlf     PORTA,same      ;otherwise rotate
       call    delay
       goto    pointaf
change_ab
       clrf    PORTA           ;finished with porta for now
       bsf     PORTB,0         ;set bit 0 on portb
                               ;others are already off
pointbf
       btfsc   PORTB,7         ;if bit 7 is lit
       goto    pointbr         ;then we're ready to reverse
       rlf     PORTB,same      ;otherwise rotate
       call    delay
       goto    pointbf
pointbr
       btfsc   PORTB,0         ;if bit 0 is lit
       goto    change_ba       ;then we're ready to change ports
       rrf     PORTB,same      ;otherwise rotate
       call    delay
       goto    pointbr
change_ba
       clrf    PORTB           ;finished with portb for now
       bsf     PORTA,3         ;set bit 3 on porta
                               ;others are already off
pointar
       btfsc   PORTA,0         ;if bit 0 is lit
       goto    pointaf         ;then we're ready to start again
       rrf     PORTA,same      ;otherwise rotate
       call    delay
       goto    pointar

       goto    start_condition ;should never get to here
                               ;but just in case

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\01\13@003511 by Rob Stockley

flavicon
face
Doh!

On Wed, 2004-01-14 at 07:00, Rob Stockley wrote:
> start_condition
>         clrf    PORTB           ;clear all portb
>         movf    0x01
         ^^^^^^
         movlw   0x01

/me ducks

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\01\13@221058 by Michael Johnston
picon face
Rob
This was added to make sure all 12 leds would come on and they did. I didnt
understand it either because the code examples I showed nothing like this
but it did work witht the exception of the fore mentioned problem.
thanks
Michael Johnston
{Original Message removed}

2004\01\13@232850 by Rob Stockley

flavicon
face
Michael,

Let me try to explain what is going wrong by rewriting the comments in
your code. I have not changed or removed any commands, just the
comments.

pascnt1
       movlw   0x05
       movwf   C1              ;counter contains value 5

setbitaf
       clrf    PORTB           ;portb leds all off
       bsf     PORTA,0         ;first led of porta is lit
pointaf
       decf    C1,f            ;decrease counter by one
       call    delay           ;wait a bit
       bcf     STATUS,C
       rlf     PORTA,same      ;change to the next led in porta
       btfsc   PORTA,3         ;if the fourth led is lit
       goto    pascnt2         ;time to switch ports
                               ;but hang on we only just lit the
                               ;fourth led. Don't we need to wait
                               ;a bit?
       movf    C1,f            ;when PORTA,3 is lit, C1=2 so Z will
                               ;never be set by this command
       btfss   STATUS,Z        ;Z is never set so we always execute
                               ;the next instruction
       goto    pointaf         ;keep processing porta
pascnt2
       movlw   0x09            ;switching to portb so
       movwf   C1              ;load counter with 9
setbitbf
       clrf    PORTA           ;turn all porta off
                               ;remember this is only 5 instructions
                               ;since we turned it on!!
       bsf     PORTB,0         ;turn on portb's first led
..........etc

Do you see how your delays are misplaced? A simple fix would be to
insert another "call delay" immediately after pascnt2. You'll need to
modify your reverse routines in a similar way.

Also, to tidy up your code, ask yourself these questions;

       What does the counter do?
       What does checking PORTA,3 do?

If the answers to these are the same then you most likely only need one
of them.

       When will the Z flag be set?
       Can this ever happen?

I hope all this is helpful. PICs are great fun to work with. Out of
interest, what are you using to program them?

Rob

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\01\14@001754 by Michael Johnston

picon face
Rob
Thanks for the information.I am using a picstart plus from microchip to
program my chip. My friend, a local engineer came up with this idea and i
implemented his idea and ran into this problem. He keeps telling its my part
this is causing this problem. But  I modify the program to run in an F 84
and it did the same thing. . The idea about the pass counter was to make
sure that all the leds would come on and they do. This was old idea that i
had some years back
thanks again
Mike Johnston
{Original Message removed}

2004\01\18@000537 by Michael Johnston

picon face
Hey Tony
I assembled the code and it works great and now its in the c54.
Thanks Again for your help
Michael Johnston
{Original Message removed}

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