Searching \ for 'first 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/index.htm?key=first+program
Search entire site for: 'first program'.

Truncated match.
PICList Thread
'first program'
1998\11\07@142726 by aureo

flavicon
face
I got my programmer going today and I am trying to assemble a program.
A switch on port A is ment to turn a LED on/off on port B.

loop    BFTSC   porta,0 ;if bit 0 porta is set then
       BSF     portb,0 ;turn on bit 0 port b else
       BCF     portb,0 ;turn of bit 0 port b
       goto    loop

I am using Charles Mannings development system.  (same as the Kits R Us
kit, I think) Below is the error message I get.

Can anyone give me a few tips?  Thanks.

-----------------------------------error
message--------------------------
C:\Seth\PIC>a84 seth.pic seth.obj
A84: Assembler for PIC16C84 V1.01
    Charles Manning 1996
seth.pic:25 loop    BFTSC   porta,0
ERROR AT            ^
INSTRUCTION: Bad instruction or directive
seth.pic:26         BSF     portb,0
ERROR AT                    ^
ARG 1: Need value in range 0..7fh, (0 to 127)
seth.pic:27         BCF     portb,0
ERROR AT                    ^
ARG 1: Need value in range 0..7fh, (0 to 127)
--------------------------------------------------------------------------------
---
--
Seth Fischer
Auckland, New Zealand

1998\11\07@150712 by Dave Johnson

flavicon
face
>I got my programmer going today and I am trying to assemble a program.
>A switch on port A is ment to turn a LED on/off on port B.
>
>loop    BFTSC   porta,0 ;if bit 0 porta is set then
>        BSF     portb,0 ;turn on bit 0 port b else
>        BCF     portb,0 ;turn of bit 0 port b
>        goto    loop
>
>I am using Charles Mannings development system.  (same as the Kits R Us
>kit, I think) Below is the error message I get.
>
>Can anyone give me a few tips?  Thanks.
I can help a little:

First, there's a typo: BFTSC should be BTFSC, I think that's why you're
getting the "Bad instruction" error.

As for the other errors, apparently the assembler doesn't recognize
"portb." Did you include the appropriate file for your processor?

Second, this program will ALWAYS turn off the led: the BCF instruction
will always be executed (there is no "else" here), so if the switch is
on, the led will go on for one cycle (too fast to see) then get turned
off. Try this:

loop
    bcf       potrb, 0  ; always turn led off first
    btfsc     porta, 0  ; if switch is on...
         bsf       portb, 0  ; ...turn led back on
    goto      loop

or this:

loop
    btfsc     porta, 0  ; if switch is on...
         bsf       portb, 0  ; ...turn led on
    btfss     porta, 0  ; if switch is off...
         bcf       portb, 0  ; ...turn led off
    goto      loop

The second one will always take exactly the same amount of time to
execute: not important here, but it's worth remembering this structure
for later.

Hope this helps...

Dave Johnson

1998\11\08@093532 by Radboud Verberne

flavicon
face
>I got my programmer going today and I am trying to assemble a program.
>A switch on port A is ment to turn a LED on/off on port B.
>
>loop    BFTSC   porta,0 ;if bit 0 porta is set then
>        BSF     portb,0 ;turn on bit 0 port b else
>        BCF     portb,0 ;turn of bit 0 port b
>        goto    loop


you need to use CAPITAL letters for PORTx. There's also a error in you
program! The LED on PORTB will not go on.
If PORTA,0 is "1" then the program executes BSF PORTB, 0 AND after that it
clears the PORTB, 0 bit again. So your led wil always be off.


Have you also set the TRIS register to configure PORTB as an output?

bsf STATUS, RP0            ; Select BANK 1
clrf TRISB                            ; POrtB pins are all outputs
bcf STATUS, RP0

Do somthing like this:

loop
   BTFSC PORTA, 0        ; Check if PORTA, 0 is high
   goto ledon                      ; Yes it is High
   bcf PORTB, 0                ; No it is Low
   goto loop
ledon
   bsf PORTB, 0
   goto loop


{Quote hidden}

--------
>--
>Seth Fischer
>Auckland, New Zealand

1998\11\08@182214 by James Cameron

flavicon
face
Radboud Verberne wrote:
> you need to use CAPITAL letters for PORTx.

Only certain assemblers require this.  On some assemblers, you can
enable case folding which will permit lowercase letters.

--
James Cameron                                      (spam_OUTcameronTakeThisOuTspamstl.dec.com)

OpenVMS, Linux, Firewalls, Software Engineering, CGI, HTTP, X, C, FORTH,
COBOL, BASIC, DCL, csh, bash, ksh, sh, Electronics, Microcontrollers,
Disability Engineering, Netrek, Bicycles, Pedant, Farming, Home Control,
Remote Area Power, Greek Scholar, Tenor Vocalist, Church Sound, Husband.

"Specialisation is for insects." -- Robert Heinlein.

1998\11\09@170732 by Hanafi Tanudjaja

flavicon
face
>Radboud Verberne wrote:
>> you need to use CAPITAL letters for PORTx.
>
>Only certain assemblers require this.  On some assemblers, you can
>enable case folding which will permit lowercase letters.
>
I used MPASM and I can use lowercase letters.

Hanafi Tan

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