Hi,
I want to learn how to use "CLEAR_BIT and SET_BIT".
Could you please give me some example to set/clear bit using above code?
All the best, Mehmet
There is no "above code". There isn't even a chip name/model in your post.
And what's the reason you want personal help with code instead of looking at available sample code and datasheets? You don't think the chip manufacturer has already documented their chip?
Hi Westermark,
I'd like to control just one bit as "1" and "0", "int" variable is 8 bit but I need just one bit.
Also If you help me how to create just one bit variable, I appreciated
IDE: Keil uVision-5 MCU: STM32F030R8- Cortex M0 CPU
/*ON-OFF Control with BUTTON*/ #define BUTTON GPIO_PIN_0 #define LED GPIO_PIN_8 int a=0x1; int b=0x1; while(1) if(!HAL_GPIO_ReadPin(GPIOA, BUTTON)) { a=0; // How to use CLEAR_BIT instead of "a=0;" b=1; // How to use SET_BIT instead of "b=1;" } if(a==1) { HAL_GPIO_WritePin(GPIOC, LED, GPIO_PIN_SET); b=1; a=0; } if(a==0) { HAL_GPIO_WritePin(GPIOC, LED, GPIO_PIN_RESET); b=0; a=1; } }
Thanks, Mehmet
So - how to set a single bit in a byte? Isn't that a part of the C language course you are taking?
And why do you need it for your own variables, if you already have HAL_xx() functions to operate on the actual GPIO pins?
Another thing - you don't think it's a good thing to use your while statement with a {} around the body? And who will ever known the meaning of variables named "a" and "b"? The variable names would possibly be meaningful if they stored the number of "a" and "b" found in a text file.
What makes you think that?!
As noted, setting/clearing/testing individual bits is standard 'C' programming stuff - so check your 'C' textbook. Hint: think how the word "bitwise" might be relevant ...
www.avrfreaks.net/.../tut-c-bit-manipulation-aka-programming-101
Here are some 'C' learning & reference resources: blog.antronics.co.uk/.../
In addition to the standard 'C' facilites, some processors also have special facilities for accessing individual bits - fo details, you will need to study the documentaion for the processor in question.