#BIT--------------------------------------------------------------------------------Syntax: #bit id = x.yElements: id is a valid C identifier,x is a constant or a C variable,y is a constant 0-7. Purpose: A new C variable (one bit) is created and is placed in memory at byte x and bit y. This is useful to gain access in C directly to a bit in the processors special function register map. It may also be used to easily access a bit of a standard C variable.Examples: #bit T0IF = 0xb.2... T0IF = 0; // Clear Timer 0 interrupt flagint result;#bit result_odd = result.0...if (result_odd)
int flags;#bit flag_settings=flags.0
if(flag_settings) { disable_interrupts(INT_EXT); scope_settings(); enable_interrupts(INT_EXT); }
sineset mo ba ang flag_settings to 0 ulit bago matapos mga statements sa loob ng if?
flag_settings = false;
if (this_BIT) execute_this_functon();
if (this_BYTE == certain_value) execute_this_function();
if(flag_settings) { disable_interrupts(INT_EXT); scope_settings(); flag_settings=0; enable_interrupts(INT_EXT); }
#int_EXTvoid EXT_isr(){ flag_settings = true;}
ito lang yung interrupt routine ko:Code: [Select]#int_EXTvoid EXT_isr(){ flag_settings = true;}
Code: [Select]if(flag_settings) { disable_interrupts(INT_EXT); scope_settings(); flag_settings=0; enable_interrupts(INT_EXT); }
.. anong interrupt ba yan? INT0?
try mo na lang ito#int_EXTvoid EXT_isr(){clear_interrupt(INT_EXT); flag_settings = true;}-- di ako nagamit ng CCS, kaya di ako sure kung clear interrupt nga ba ang gamit pang clear ng interrupt flag..heheh
tinitignan niyo ba yung code listing kung ano pinaka-efficient at optimized?merong Python for PIC...
mas mabilis ba ang execution ng:Code: [Select]if (this_BIT) execute_this_functon();compared sa:Code: [Select]if (this_BYTE == certain_value) execute_this_function();
>kapag nag-declare ba ako ng function tapos di ko naman nagamit,>magko-consume ba sya ng memory? On smart compilers, this should be automatically removed. AFAIR, It is called dead code removal. I don't have extensive experience on CCS but on Hitech and GCC removes this.>same as sa variables, kapag nag-define ba ako ng variable tapos di ko naman nagamit,>magko-consume din ba sya ng space? No. Global RAM variables are not removed. The compiler does not know if you used the variable using a pointer. So this is not removed to be safe.But dynamic variables defined inside the functions are re-used other functions on same level by using a dynamic stack space employed by these new compilers if the micro has no hardware stack.
... You may also use unions (if applicable to your app) to save RAM and instead of passing arrays, you pass a pointer...
union { long train; char loByte; char hiByte; byte _loByte; byte _hiByte;} ex_union ;
/* somewhere in the beginning of the main */ long x; /* .........................*/ ex_union.train = x; ex_union.loByte= 0x3f; ex_union.hiByte= 0; ex_union._hiByte = 45;
Union allows you to store different types of data in the same location...
di kaya magkalito-lito ang compiler nito, o kaya yung pic mismo magkamali-mali ang processing ? Huh