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.

Blah, stupid problem. Need help,quick!!!

Status
Not open for further replies.

jhanus

New Member
Hello,

I found a part of code, but it's written in "old" way. So plz convert it that it uses bcf bank0...
I tried, but what is OPTION in middle of nowhere, argh...

CODE:
Code:
;ORIGINAL
start     clrf   PORTA
            clrf   PORTB

            movlw B'00010000'
            tris PORTA              ;<=PROBLEM
            movlw B'00000000'
            tris PORTB              ;<=PROBLEM
            movlw B'00000011'
                             


            option                 ;<=PROBLEM             
 
            movlw 0 
            movwf temp

            clrf work

            movlw B'10100000'
            movwf INTCON
return

;********************************
;My conversion, probably wrong, because it's not working
;********************************

start      clrf   PORTA
            clrf   PORTB
[COLOR="Red"]	    bsf	   STATUS,RP0[/COLOR]
            movlw  B'00010000' 
[COLOR="Red"]            movwf  TRISA[/COLOR]
            movlw  B'00000000
[COLOR="Red"]            movwf  TRISB[/COLOR]
            movlw  B'00000011'
          		     


[COLOR="Red"]            movwf	OPTION_REG    [/COLOR]
                                       ;
[COLOR="Red"] 	    bcf	        STATUS,RP0  [/COLOR]             
 
            movlw 0 
            movwf temp

            clrf work

            movlw B'10100000'
            movwf INTCON
return

Thanks :eek:
 
jhanus said:
Hello,

I found a part of code, but it's written in "old" way. So plz convert it that it uses bcf bank0...
I tried, but what is OPTION in middle of nowhere, argh...

CODE:
Code:
;ORIGINAL
start     clrf   PORTA
            clrf   PORTB

            movlw B'00010000'
            tris PORTA              ;<=PROBLEM
            movlw B'00000000'
            tris PORTB              ;<=PROBLEM
            movlw B'00000011'
                             


            option                 ;<=PROBLEM             
 
            movlw 0 
            movwf temp

            clrf work

            movlw B'10100000'
            movwf INTCON
return

;********************************
;My conversion, probably wrong, because it's not working
;********************************

start      clrf   PORTA
            clrf   PORTB
[COLOR="Red"]	    bsf	   STATUS,RP0[/COLOR]
            movlw  B'00010000' 
[COLOR="Red"]            movwf  TRISA[/COLOR]
            movlw  B'00000000
[COLOR="Red"]            movwf  TRISB[/COLOR]
            movlw  B'00000011'
          		     


[COLOR="Red"]            movwf	OPTION_REG    [/COLOR]
                                       ;
[COLOR="Red"] 	    bcf	        STATUS,RP0  [/COLOR]             
 
            movlw 0 
            movwf temp

            clrf work

            movlw B'10100000'
            movwf INTCON
return

Thanks :eek:

What PIC is it?,,,what are you trying to do?

The 'old' way, do you mean assembler, whats the new way?

The part code dosnt make much sense to me, can you post the full listing.
 
As far as I'm aware using the TRIS command still works on modern devices?, although they keep threatening to drop it. So does the original code work?, and why are you wanting to change it?.
 
Hello,

I scraped a part of code, there is no full listing. It's for PIC16f84a, under "old" way I was thinking on instructions like:

tris PORTB replaced with (for example) movwf TRISB
option replaced with OPTION_REG

at least I read somewhere that this way of writing should be avoided.
In other part I tried to write the same part of program, changes that I made are in red and probably wrong.

Yes it works, but I don't know what it means in that way, when are banks changed, ect.
 
Your conversion looks correct. The code you posted looks like it's for a 12 bit core which doesn't have bank switching.

Mike.
 
Thanks,

hmm, ok, can somebody explain exactly what this part of code does:

Code:
movlw B'00000011'
option

, because there is no bank switching, but option is in bank1 (16f84), how can it be simply written without bank change, and why is it 'alone', without any other instruction, like movwf option, or something.
 
Because the 12 bit core chips didn't have banking, the tris and option registers were given special instructions to write to them. The 12 bit cores lacked other features as well like having a stack that was only 2 deep and no return instruction - you had to use retlw.

Mike.
 
jhanus said:
Thanks,

hmm, ok, can somebody explain exactly what this part of code does:

Code:
movlw B'00000011'
option

, because there is no bank switching, but option is in bank1 (16f84), how can it be simply written without bank change, and why is it 'alone', without any other instruction, like movwf option, or something.

Set the RP0 bit to "1" in the STATUS Reg to switch to the OPTION_REG,,, BANK
 
Well thanks,

I didn't know that before there were no banks and such a weak stack, interesting.

So if I write in one line only "option", anything that is in wreg is copying to option reg?!
 
jhanus said:
Well thanks,

I didn't know that before there were no banks and such a weak stack, interesting.

So if I write in one line only "option", anything that is in wreg is copying to option reg?!

That's one reason not to use such an old PIC, the 16F628A replaced it ages ago.

and instead of option try

movlw xxxx
movwf OPTION_REG
 
Yes, I understand, I am using:

movlw xxxx
movwf OPTION_REG
and I will jump over to 16F628, probably even to bigger PIC, but my question remains:

If I write in one line only "option", anything that is in wreg is copying to option reg?!
 
Yes, option moves W to the option register. If your interested have a look at the 12F508 data sheet.

Bill, that doesn't work on the 12 bit pics - they can't do bank switching.

Mike.
P.S. the 84 is a 14 bit device.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top