PDA

Click to See Complete Forum and Search --> : [RESOLVED] BTFSC and BTFSS "siblings"


BillGeek
Oct 26th, 2009, 12:22 AM
Hi All

I'm extremely new to Assembler, but got the hang of most of the stuff required for PIC programming.

I was able to build a circuit this weekend for RS232 communication between the PC and the PIC and got a test message sent from the PIC to the PC when connecting, as well as an "echo" routine that takes the input and sends it back.

What I want to do now is to check what is being sent to the PIC, and perform certain actions based on the input. (A basic "IF" statement) The only instructions I'm aware of that can do something like this is BTFSC and BTFSS, but aren't these to only check a certain bit of something? So, for example, to perform an action when the 0 bit of port A is set, I would require the below:
btfsc PORTA,0
call DoSomething
If this is correct, then it's not what I need. I will essentially send the PIC an 8-bit character (EG: 0xFA = character 250) from a set list and, based on this character, it will do something different.

Is there any "easy" way of doing this? Something similar to BTFSC / BTFSS but that checks the whole byte instead of a single bit?

Liami
Nov 2nd, 2009, 09:34 AM
There is no "if" statement in assembly for pic's, however there is always a work-around.

movfw PORTA
sublw .250
btfss STATUS,Z
goto elseif

;code here to perform if PORTA = 250


basically move your register you want to check to W
sub literal from W
check if the zero bit was set in STATUS
if it was then they are equal!

such is the life of an 8bit mcu :(

BillGeek
Nov 2nd, 2009, 11:29 PM
Thanks for the reply. I tried something similar, yet it didn't seem to work. My code is / was as below. I think the problem here is that I'm not using proper software to communicate with the PIC. In Visual Studio 2005, I'm using the "WriteLine" method of the SerialPort component, which sends a string through the RS232. While this should theoretically work, I doubt it does the right thing.

What I will try to do tonight is:

1. Move the input I get from RS232 to the LCD display. (Will have to operate in 4 bit)
2. If found that the input does not work correctly, I will try using the "Write" method which I can use to dump bytes to the SerialPort.


sublw 65 ;65 = Ascii for character "A"
btfss STATUS,Z
call LightGreenLED ; If "A" received through com, light the RED otherwise the GREEN
call LightRedLED
return

LightGreenLED
bsf PORTA,1
bcf PORTA,0
return

LightRedLED
bsf PORTA,0
bcf PORTA,1


such is the life of an 8bit mcu :(
lol - yeah, it sucks. :) Unfortunately here in SA we don't get the 16-bit MCU's as cheap as the 8-bit ones, so I'm "forced" to use them... until I get a bonus, that is. :D

Liami
Nov 3rd, 2009, 03:07 AM
One thing you need to be careful of when using btfss or btfsc is that in your code described above say Z isn't set

LightGreenLED will be executed, then LightRedLED will also be executed as it is all sequential and essentially just skips the next code line based on your condition, if it doesn't skip then it will execute the next line. I generally use goto's to avoid this and to avoid overloading the stack with calls.

btfss STATUS,Z
goto LightGreenLED
goto LightRedLED

I quite enjoy working with 8bit mcu's, they are so limiting it really gives your brain a chance to flex it's programming muscles, especially when you're so used to writing 32bit software for PC's.

I assumed you'd already got the serial transfer working on the PIC, if not take a look into the SPI (depending on the mcu you're using, not all have it). Last time i was working with RS232 i ended up using hyperterminal in XP to send/receive data. Unfortunately we don't have VS installed at work :(

BillGeek
Nov 16th, 2009, 04:32 AM
Sorry for the excessively late reply... I had burnt out the last of my 16F628's so had to buy a couple more. This time I opted for the 16F876A's and they work quite brilliantly if I might add. :)

Anyway, I now first have to get the RS232 working again as, somehow, I stuffed something up. (I think it has something to do with the crystal in the circuit or something) I can't get the test message sent from the PIC to the PC. :( I'm thinking along the lines of timing perhaps, or even the registers I'm using.

Nevertheless, you have helped me find a solution to checking conditions, so this thread is now resolved. :thumb: