Brian Hoskins
New Member
Hi everyone,
I am part way through writing some software for an 8-bit PIC Microcontroller that will receive an RC5 datastream. I am writing the software in C, which is a new adventure for me (previously I've always written in Assembly).
I'm at the point in my program where I am reading in the RC5 datastream. I have setup two 8-bit variables for this (Address and Command). The idea is that the input pin is sampled at the correct time, and then the value (0 or 1) is loaded into the LSB of "Address". Then I will shift Address left, and at the appropriate time the input pin will be sampled again and the new value stored in bit 0 of "Address". Sampling will continue in this manner until all 6 bits of the RC5 Address (inc Toggle bit) are collected. The same will then be done for the Command.
I've been thinking about the best way to go about this. I already have my timing sorted out, but I'm unsure of the best way to set or clear a bit in a variable. Of course I could use a mask, but surely that's not the most efficient way to go about this for an embedded system. In assembly it can be done using BCF and BSF instructions, does anyone know if there is a globally accepted way of doing the same thing in C?
If not, I guess I'll just revert to assembly for the set and clear bit operations.
Thanks all,
Brian
I am part way through writing some software for an 8-bit PIC Microcontroller that will receive an RC5 datastream. I am writing the software in C, which is a new adventure for me (previously I've always written in Assembly).
I'm at the point in my program where I am reading in the RC5 datastream. I have setup two 8-bit variables for this (Address and Command). The idea is that the input pin is sampled at the correct time, and then the value (0 or 1) is loaded into the LSB of "Address". Then I will shift Address left, and at the appropriate time the input pin will be sampled again and the new value stored in bit 0 of "Address". Sampling will continue in this manner until all 6 bits of the RC5 Address (inc Toggle bit) are collected. The same will then be done for the Command.
I've been thinking about the best way to go about this. I already have my timing sorted out, but I'm unsure of the best way to set or clear a bit in a variable. Of course I could use a mask, but surely that's not the most efficient way to go about this for an embedded system. In assembly it can be done using BCF and BSF instructions, does anyone know if there is a globally accepted way of doing the same thing in C?
If not, I guess I'll just revert to assembly for the set and clear bit operations.
Thanks all,
Brian