# pic16f84 bit command not working

Status
Not open for further replies.

#### d@nny

##### Full Member level 5
the bsc portb , 0 should only hi RB0 but the whole port i mean the 8 pins of portb going to hi with this command.

processor 16f84
include <p16f84.inc>
__config _RC_OSC & _WDT_OFF & _PWRTE_ON
J equ 21h
org 00h
main:
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
bsf PORTB , 0
fin:
goto fin

end

the whole portb becomes hi with this command bsf

#### Tahmid

Code ASM - [expand]1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
processor 16f84
include <p16f84.inc>
__config _RC_OSC & _WDT_OFF & _PWRTE_ON
J equ 21h
org 00h
main:
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
clrf PORTB
bsf PORTB , 0
fin:
goto fin

end

This should work.

You can see that I added the line:

Code ASM - [expand]1
clrf PORTB

This makes sure that before you do anything on PORTB, the initial value that it holds is cleared.

Hope this helps.
Tahmid.

d@nny

### d@nny

Points: 2

#### d@nny

##### Full Member level 5
i have added the line but same result means that the pic mcu is damadge or the assembler is courpt

#### Tahmid

Are you sure your PIC is 16F84 and not PIC 16F84A? Did you connect the RC oscillator correctly?

d@nny

### d@nny

Points: 2

#### bigdogguru

How are you programming the PIC16F84? With what programmer?
After programming have you ran a "verify" to ensure the program is correctly stored in the flash?
What RC values are you using for your RC OSC?

d@nny

### d@nny

Points: 2

#### d@nny

##### Full Member level 5
Is my code 100 % correct?

#### Tahmid

It looks okay and simulates okay. If your hardware is alright, it should work. Take a look at your RC oscillator, if you configured it correctly, etc. You might try with a crystal and change the config bits in the code to a crystal.

Hope this helps.
Tahmid.

d@nny

### d@nny

Points: 2

#### d@nny

##### Full Member level 5
how to change it crystal do i need to put XT in place of RC as i am driving on 8 MHz crystal

#### bigdogguru

how to change it crystal do i need to put XT in place of RC as i am driving on 8 MHz crystal

Actually you need to use the HS for an 8MHz, refer to the appropriate datasheet for details.

d@nny

### d@nny

Points: 2

#### d@nny

##### Full Member level 5
actually i am making a digital combination lock and multisim only have pic16f84. in multisim pic work ok on 8 KHz . i have tried that code in mplab and it is working fine. The clrf also working fine in mplab. now on 8khz it is also fine with multisim. Thank you so much for help me
bye

#### Tahmid

Just to let you know, to use crystal oscillator at 8MHz, change:
Code:
__config _RC_OSC & _WDT_OFF & _PWRTE_ON
to
Code:
__config _HS_OSC & _WDT_OFF & _PWRTE_ON

Hope this helps.
Tahmid.

Status
Not open for further replies.