Searching \ for 'pic16c84 SAMPLE PROGRAM?' 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: 'pic16c84 SAMPLE PROGRAM?'.

Truncated match.
PICList Thread
'pic16c84 SAMPLE PROGRAM?'
1997\01\16@104824 by Thompson, Michael

flavicon
face
Hi, everyone!

I finally built a programmer for the 16C84 (the AN589 version with
the Andrew Errington software) but now have to figure out how to use
the damned thing. I've written some simple programs to turn on and off
a couple of LEDs but now want to read some switches. Would someone
mind sending me a sample prorgam to read, say, four bits/switches and
send the four switch positions to four LEDs? I know this seems
ridiculously simple but I'm unsure of the paging thing with the FSRs.
Once I can do this I can figure out the rest (I've used the 8031 and
a couple others for a long time so microcontrollers aren't exactly
new to me).

Thanks to anyone who will take the time to do this for me.

Mike Thompson

1997\01\16@222622 by Tony Matthews

flavicon
face
Thompson, Michael wrote:
>
> Hi, everyone!
>
> I finally built a programmer for the 16C84 (the AN589 version with
> the Andrew Errington software) but now have to figure out how to use
> the damned thing. I've written some simple programs to turn on and off
> a couple of LEDs but now want to read some switches. Would someone
> mind sending me a sample prorgam to read, say, four bits/switches and
> send the four switch positions to four LEDs? I know this seems
> ridiculously simple but I'm unsure of the paging thing with the FSRs.
> Once I can do this I can figure out the rest (I've used the 8031 and
> a couple others for a long time so microcontrollers aren't exactly
> new to me).
>
> Thanks to anyone who will take the time to do this for me.
>
> Mike Thompson

Hi try this one novice to another
PORTA   equ     5               ; I/O register F5
PORTB   equ     6               ; I/O register F6
TRISA   equ     85              ; I/O direction register F85
TRISB   equ     86              ; I/O direction register F86
STATUS  equ     3               ; STATUS register F3
RPO     equ     5               ; page select bit
DELAY   equ     0Ch             ; inner delay loop
X_DELAY equ     0dh             ; outer delay loop

;FIRST initialize porta as inputs & portb as outputs.
LOOP
       BTFSS   PORTA,0         ; if portb bit zero is high skip next instructio
n
       GOTO    BUTTON_1        ; jump directly to the instruction after the lab
el
BUTTON_1
       BTFSS   PORTA,1         ; if portb bit one is high skip next instruction
       GOTO    BUTTON_2        ; jump directly to the instruction after the lab
el
BUTTON_2
       ;repeat as necessary.....
       GOTO    LOOP            ; back around again
BUTTON_1
       INCF    PORTB,F         ; make the output pins of port b count up in bin
ary to
11111111 then 0
       MOVLW   03h             ; call delay with length of desired delay in W r
egister
       CALL    X_DELAY         ; ""
       GOTO    LOOP            ; back around again
BUTTON_2
       CLRF    PORTB           ; sets portb pins LOW
       MOVLW   03h             ; call delay with length of desired delay in W d
elay
       CALL    X_DELAY         ; ""
       GOTO    LOOP            ; back around again

       ;******* a delay of 'W' * Inner Loop subroutine
X_DELAY         MOVWF   X_DELAY      ; put value of w register into x_delay
variable (GPR)
               MOVLW   D'10'        ; constant number of loops ( inner ) pick a
number that works for you
X_DELAY_LOOP    MOVWF   DELAY
DELAY_LOOP      DECFSZ  DELAY, F     ; inner loop
               GOTO    DELAY_LOOP   ; ""
               DECFSZ  X_DELAY,F    ; outer loop
               GOTO    X_DELAY_LOOP ; ""
               RETURN
       END
; you will need a variable delay in lots of things and if you omit it
here the port pins will increment to fast for you to see and will appear
all on dimly or off.also I assume you have the code to initialize the
ports. Have fun !  Tony M.
oh yeah not responsible for ensuing addictions or misspellings 8)

1997\01\17@151749 by l Curtis Bennett

flavicon
face
{Quote hidden}

instruction
>         GOTO    BUTTON_1        ; jump directly to the instruction after the
label
> BUTTON_1
>         BTFSS   PORTA,1         ; if portb bit one is high skip next
instruction
>         GOTO    BUTTON_2        ; jump directly to the instruction after the
label
> BUTTON_2
>         ;repeat as necessary.....
>         GOTO    LOOP            ; back around again

<snip>

From another novice...

I am pretty sure that you can dispense with the BTFSS for each bit.
Simply write 0xFF (8 1's) or 0x00(8 0's) to the proper register.
True, it's not elegant, but it saves a *bunch* of lines
of code, which can be important.

Sample, from memory:

(use equ's as above, replace loop procedure to initialize as input/output)

       movlw   0xFF    ;put 11111111 in w
       movf    TRISA   ;put 11111111 in port a direction register

       movlw   0x00    ;put 00000000 in w
       movf    TRISB   ;put 00000000 in port b direction register

now do the output to ports and stuff.

(or something like that, I dont have my manual handy!)

Paul Bennett
spam_OUTpbennettTakeThisOuTspamkilby.elee.calpoly.edu

"And therefore as a stranger give it welcome, there are more things in
Heaven and earth, Horatio, than are dreamt of in your philosophy..."
                                         -- Hamlet, Act 1, Scene 5

1997\01\17@201235 by Tony Matthews

flavicon
face
Paul Curtis Bennett wrote:
{Quote hidden}

Tony replied Wow this looks so much different than it did when I sent it
out What happened to my formatting ? Oh yeah and my code such as it is
is not meant to initialize the ports but to manipulate them afterwards I
as I said assumed the port initializationbuisness had been conquered. ;)
{Quote hidden}

1997\01\17@203447 by l Curtis Bennett

flavicon
face
<Big snip of code/text/etc>

> > >
> > >  ;FIRST initialize porta as inputs & portb as outputs.
> > > LOOP
> > >         BTFSS   PORTA,0         ; if portb bit zero is high skip next
> >  instruction
> > >         GOTO    BUTTON_1        ; jump directly to the instruction after
the
> >  label
> > > BUTTON_1
> > >         BTFSS   PORTA,1         ; if portb bit one is high skip next
> >  instruction
> > >         GOTO    BUTTON_2        ; jump directly to the instruction after
the
> >  label
> > > BUTTON_2
> > >         ;repeat as necessary.....
> > >         GOTO    LOOP            ; back around again

> Tony replied Wow this looks so much different than it did when I sent it
> out What happened to my formatting ? Oh yeah and my code such as it is
> is not meant to initialize the ports but to manipulate them afterwards I
> as I said assumed the port initializationbuisness had been conquered. ;)

Oops!  Sorry!  I apparently misunderstood what you were trying to do...

However, I think that you should still read the Port as one word/byte
whatever, and then you can write the state of the port to the output,
instead of doing it bit by bit.

(But then again, this is coming from someone who just smoked his
16c84 -- Important tip:  Vdd and Vss are NOT interchangeable... ;)

Paul Bennett
pbennettspamKILLspamkilby.elee.calpoly.edu

"And therefore as a stranger give it welcome, there are more things in
Heaven and earth, Horatio, than are dreamt of in your philosophy..."
                                         -- Hamlet, Act 1, Scene 5

1997\01\17@214306 by John Payson

picon face
> (But then again, this is coming from someone who just smoked his
> 16c84 -- Important tip:  Vdd and Vss are NOT interchangeable... ;)

One investment (in dollars or time-to-build) I'd highly recommend is an--
at least crudely--current-limitted supply.  Even something simple such as
a 12-volt wallbrick feeding a 7805 through a 100-ohm resistor should be
quite effective (a 100-ohm resistor will yield a useable current of 50mA
and a max current of 100mA).  While I would not recommend leaving a PIC
reverse-connected to such a supply for very long, PICs can--from my
experience--survive brief power-up attempts with even more than that.  Of
course, if your project needs more than 50mA you'll have to change the
resistor or use a real current-limitting supply; upping the current, how-
ever, will increase the likelihood of PIC damage from incorrect insertion.

1997\01\18@012813 by l Curtis Bennett

flavicon
face
> > (But then again, this is coming from someone who just smoked his
> > 16c84 -- Important tip:  Vdd and Vss are NOT interchangeable... ;)
>
> One investment (in dollars or time-to-build) I'd highly recommend is an--
> at least crudely--current-limitted supply.  Even something simple such as

<snip>

Thanks for the suggestion on the current limiting supply!
As it happens, I was using a 7805 driven by an electronics power
supply (with current limiting), but I had mentaly swapped power
and ground when I drew my schematic, so miswired the circuit! Oops!


On a more positive note, when I receive my replacement parts from
DigiKey, I plan on building some cirtuits that will need to
communicate through RS232.  I have been told the Max232 chip is the
way to go.  Can someone who has used it tell me what you need to
do to work with this chip? (ie, power requirements, etc). Thanks

Paul Bennett
.....pbennettKILLspamspam.....kilby.elee.calpoly.edu

"And therefore as a stranger give it welcome, there are more things in
Heaven and earth, Horatio, than are dreamt of in your philosophy..."
                                         -- Hamlet, Act 1, Scene 5

1997\01\18@023439 by Clyde Smith-Stubbs

flavicon
face
Thus spake Paul Curtis Bennett (EraseMEpbennettspam_OUTspamTakeThisOuTKILBY.ELEE.CALPOLY.EDU):

> On a more positive note, when I receive my replacement parts from
> DigiKey, I plan on building some cirtuits that will need to
> communicate through RS232.  I have been told the Max232 chip is the
> way to go.  Can someone who has used it tell me what you need to
> do to work with this chip? (ie, power requirements, etc). Thanks

The MAX202 is actually a better bet - it requires only 4 x 0.1uF caps
instead of tantalums. Apart from that the '202 and 232 are the same. They run
off 5V, and provide 2 each receive and transmit buffers for RS232. The
caps are the only other components needed.

--
Clyde Smith-Stubbs    | HI-TECH Software,       | Voice: +61 7 3354 2411
clydespamspam_OUThtsoft.com      | P.O. Box 103, Alderley, | Fax:   +61 7 3354 2422
http://www.htsoft.com | QLD, 4051, AUSTRALIA.   |
---------------------------------------------------------------------------
Download a FREE beta version of our new ANSI C compiler for the PIC
microcontroller! Point your WWW browser at http://www.htsoft.com/

1997\01\18@031314 by William Chops Westfield

face picon face
   The MAX202 is actually a better bet - it requires only 4 x 0.1uF caps
   instead of tantalums. Apart from that the '202 and 232 are the same. They
   run off 5V, and provide 2 each receive and transmit buffers for RS232.

A recent "EDN Design notes" column (Oct 24, 1996) pointed out that one
of these 5-V RS-232 drivers makes a fine (is somewhat slow) power mosfet
driver as well...  I thought that was pretty clever...

BillW

1997\01\18@114143 by Bryan Mumford

flavicon
face
>While I would not recommend leaving a PIC
>reverse-connected to such a supply for very long, PICs can--from my
>experience--survive brief power-up attempts with even more than that.

I too have been amazed to find PIC chips that had gone into a snit on power
up and become SO HOT they would burn your fingers, but would still run fine
after they cooled down.

As for the MAX232, they work great and need little power, but I'd look into
one that uses few or small capacitors. They cheapest ones require several
biggish caps.


Bryan Mumford
Santa Barbara, California

1997\01\18@182805 by Tony Matthews

flavicon
face
Paul Curtis Bennett wrote:
{Quote hidden}

Been there  Learned to use sockets  Was cheaper
I'm curious as to your reasoning, If you read the port as a whole would
you not still need to determine the state of the individual bit in
question.And since the port register can be manipulated like the other
registers where is the benefit in moving the values elsewhere?I mean in
this particular application of course. Tony M.

1997\01\18@234409 by John Payson

picon face
> >While I would not recommend leaving a PIC
> >reverse-connected to such a supply for very long, PICs can--from my
> >experience--survive brief power-up attempts with even more than that.
>
> I too have been amazed to find PIC chips that had gone into a snit on power
> up and become SO HOT they would burn your fingers, but would still run fine
> after they cooled down.

This is another reason I'd forgotten to mention for current-limitting your
supply: if you bounce /MClr negative, the PICs will often latch up, burning
half a volt times whatever current you'll let 'em have.  If you have a PIC
latch up when it's connected to, e.g., a +5V, 10A, supply it'll toast it
pretty well, but if the supply is current-limitted the device will avoid
damage.

1997\01\19@023941 by l Curtis Bennett

flavicon
face
<snip>

> Been there  Learned to use sockets  Was cheaper
>  I'm curious as to your reasoning, If you read the port as a whole would
> you not still need to determine the state of the individual bit in
> question.And since the port register can be manipulated like the other
> registers where is the benefit in moving the values elsewhere?I mean in
> this particular application of course. Tony M.
>

Well, if I understand the application correctly, the intent was to
read the state of some switches on one port, and write that state to
the other.  Ie, if switches are "on", turn on the LED attached to
the other port.  So, if you 'match' pins (say switch one is on porta
pin 1, led 1 is on portb pin 1) you can do the whole operation in
only a couple of instructions. It doesn't matter what the states of the
individual bits are, 'cause they are all 'tested' at the same time.
If you try to set a bit that is already set (or cleared), it'll just
stay in it's original state.  No need to check each one, just treat
them as a lump.  The whole point of moving them, though, is that you
have to tell the other port which pins to set or clear (to turn on
or off the LED's), so you just copy one register (input port) to another
register (output port) and you are done.

Of course, if you want to know  (have the controller know, I mean) which
individual pins are on, then you'd have to do the bit test scheme
presented originally.

And, if you don't want to use the whole of both ports
for this exercise, you can use a mask to get just the bits you want,
but you still save lots of work (and program space).

(not trying to tread on any toes, just throwin' in my 14 bits worth...)

;)

Paul Bennett
KILLspampbennettKILLspamspamkilby.elee.calpoly.edu

1997\01\19@113014 by Tony Matthews

flavicon
face
Paul Curtis Bennett wrote:
>
> <snip>
>

> Well, if I understand the application correctly, the intent was to
> read the state of some switches on one port, and write that state to
> the other.  Ie, if switches are "on", turn on the LED attached to
> the other port.  So, if you 'match' pins (say switch one is on porta
> pin 1, led 1 is on portb pin 1) you can do the whole operation in
> only a couple of instructions. It doesn't matter what the states of the
> individual bits are, 'cause they are all 'tested' at the same time.
> If you try to set a bit that is already set (or cleared), it'll just
> stay in it's original state.  No need to check each one, just treat
> them as a lump.  The whole point of moving them, though, is that you
> have to tell the other port which pins to set or clear (to turn on
> or off the LED's), so you just copy one register (input port) to another
> register (output port) and you are done.

I comprehend thanks Tony M.

> RemoveMEpbennettTakeThisOuTspamkilby.elee.calpoly.edu

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