Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Assembly

Status
Not open for further replies.

GatorGuy

New Member
I have been reading some assembly tutorials and I am starting to understand some of the basic functions. One thing that I havent seen is IF...THEN type coding. Examples:

I am use to VB/Qbasic so forgive me, none of this is correct assembly.

if PORTB, 1 = 1 then
bsf PORTB, 4
End

Or is this even possible with assembly?
 
upand_at_them said:
btfsc PORTB, 1
bsf PORTB, 4

-Mike

I am sorry Mike, I have not read on the btfsc command yet. :oops: Could you explain how this works?
 
You should have the datasheet for the PIC you intend to use. Every PIC datasheet contains a command set summary.

-Mike
 

Attachments

  • btfsc.gif
    btfsc.gif
    16 KB · Views: 770
Code:
ADC     bsf     ADCON0,ADON     ; turn on AD module               |B0 
        bcf     PIR1,ADIF       ; clear AD interrupt flag         |B0 
        movlw   d'33'           ; use 33 (20 mhz) or 13 (8 mhz)   |B0 
        movwf   TEMP            ;                                 |B0 
ACQ     decfsz  TEMP,F          ; wait 20 usec  to acquire        |B0 
        goto    ACQ             ;                                 |B0 
        bsf     ADCON0,GO_DONE  ; start conversion                |B0 
ADX     btfsc   ADCON0,GO_DONE  ; conversion complete?            |B0 
        goto    ADX             ; no, loop                        |B0 
        movf    ADRESH,W        ; get result high byte            |B0 
        bcf     ADCON0,ADON     ; turn off AD module              |B0 
        return                  ;                                 |B0 
;******************************************************************
the label ADX uses the btfsc command..
it is testing for a flag bit , and looping till the flag is cleared..
 
The best thing I recommend is to grab the data sheet from the manufacturer of your microcontroller and study their instruction set.

Next, think about your program.

and then write it using their instruction set, with the following things in mind:

All jump related statements are equivalent to QuickBasic's GOTO statements.

All return statements (like RET and RETF) are equivalent to QuickBasic's End Sub, Exit Sub, and Return.

All Call related statements are equivalent to Quickbasic's CALL sttements.

Because you are injecting code into the hardware directly (right?) it is best to use the opcodes for each instruction instead of the mnenomics (<- I can't spell that word :( ) because if you don't then your code will not work correctly. Also, your code must be within the available ROM (not RAM) space on your chip.
 
Okay I have been studying the datasheets. Let me see if I have this right.

I have a 16F628A with a push button switch on an input pin. When pushed the pin gets pulled high. When pulled high the PIC tells another pin of choice to go high.

loop
BTFSC PORTB, 7
GOTO PIN_IS_HIGH
GOTO LOOP

PIN_IS_HIGH
BSF PORTA, 4
GOTO LOOP

END

Am I close?
 
Yep, that'll work, Gator.

One note, though, is that most inputs are tied high and pulled low. Pulling an input high means that it is untied and floating when the button isn't pushed. So, tie the input pin high with a resistor and use the switch to pull it low. And change your code accordingly.

Mike
 
GatorGuy said:
Okay I have been studying the datasheets. Let me see if I have this right.

I have a 16F628A with a push button switch on an input pin. When pushed the pin gets pulled high. When pulled high the PIC tells another pin of choice to go high.

loop
BTFSC PORTB, 7
GOTO PIN_IS_HIGH
GOTO LOOP

PIN_IS_HIGH
BSF PORTA, 4
GOTO LOOP

END

Am I close?
Don't forget to Initialze the PIC at the beginning. (eg set some PINs to output...)
 
upand_at_them said:
Yep, that'll work, Gator.

One note, though, is that most inputs are tied high and pulled low. Pulling an input high means that it is untied and floating when the button isn't pushed. So, tie the input pin high with a resistor and use the switch to pull it low. And change your code accordingly.

Mike

Thanks Mike. That is good to know. I was just using that as an example for myself. For now most of what I will be doing will be with outputs.

I'm not totally sure if I pulled the pin in the PIN_IS_HIGH sub right. If I wanted to pull RB1 high, what would I use?
 
GatorGuy said:
I'm not totally sure if I pulled the pin in the PIN_IS_HIGH sub right. If I wanted to pull RB1 high, what would I use?

"BSF PORTA, 4" sets bit 4 of PORTA. Just make sure you turn off analog functions if you're using PORTA as digital I/O.

To pull a pin high with hardware you just need a pullup resistor. 10K is a good value. Then your switch is tied from the pin to GND when it closes.

Check out Nigel's tutorials. He has all this stuff and walks you through the assembly code. I think it will help you a lot.

Mike
 
Status
Not open for further replies.

Latest threads

Back
Top