PDA

View Full Version : subroutine for picbasic



jojokatada
- 19th February 2005, 04:26
hi i want to make a subroutine for checking the status of each bit of portb and set a high on corresponding to porta.

here is the assembly code

checking portb

btfsc portb, 0
bsf porta, 0
btfsc portb, 1
bsf porta, 1
btfsc portb, 2
bsf porta, 2
btfsc portb, 3
bsf porta, 3

return


please help me to translate this code into picbasic pro
appreciate for any help

TurboLS
- 19th February 2005, 06:26
OK, let me get this straight. You want your program to do the following:

check if portb.0 is high, if so set porta.0 high and so on?

If that's the case, then it's pretty easy,

IF PORTB.0 = 1
THEN PORTA.0 = 1
ELSE PORTA.0 = 0
IF PORTB.1 = 1
THEN PORTA.1 = 1
ELSE PORTA.1 = 0
IF PORTB.2 = 1
THEN PORTA.2 = 1
ELSE PORTA.2 = 0
IF PORTB.3 = 1
THEN PORTA.3 = 1
ELSE PORTA.3 = 0

That is the bulk of what I think you are trying to do. You will have to set the TRISB registers to outputs. In addition, I don't know how fast you would want these changes to occur, so I would see if you could get something like this up and running and check to see if the speed meets your requirements.

mister_e
- 19th February 2005, 10:10
more easy than if then stuff...



TRISA=0 'output on all PORTA pin
TRISB=255 'Input on all PORTB pin
'
'

'
'

'
'
'
CheckingPORTA:
PORTA=PORTB
Return


1 line do everything ;)

jojokatada
- 19th February 2005, 18:46
hi Turbols

appreciate your help i am trying to use in pic16f877a by checking each bit and send a high to porta to activate a relay.

mister_e
- 19th February 2005, 18:58
MyInput var Byte
TestLoop var byte

Start:
MyInput = PORTA
For testloop = 0 to 7
PORTB.0[testloop]=Myinput.0[TestLoop] ' send the state of the bit to
' the according PORTB bit
next
goto start