110 likes | 220 Views
Macros (as aliases). PBASIC: p4_sw_aux2 VAR oi_swB.bit7 'Aux input C: #define p4_sw_aux2 rxdata.oi_swB_byte.bitselect.bit7 /* Aux input*/. MUST be in left-most column!. Pre-Processor Note.
E N D
Macros (as aliases) • PBASIC: p4_sw_aux2 VAR oi_swB.bit7 'Aux input • C: #define p4_sw_aux2 rxdata.oi_swB_byte.bitselect.bit7 /* Aux input*/
MUST be in left-most column! Pre-Processor Note The # symbol denotes a pre-processor statement that is evaluated before the compiler takes over. #include “ifi_aliases.h”
Macros (as constants) • PBASIC: COMC CON 3 • C: #define FIELD_WIDTH 125 #define FIELD_LENGTH 300 #define FIELD_PERIMETER FIELD_WIDTH*2 + FIELD_LENGTH*2 Use ours in: ifi_aliases.h Put yours in: user_routines.h
Don’t forget the semicolon! Assignments • PBASIC: • relay3_fwd = p3_sw_trig • C: • relay3_fwd = p3_sw_trig;
Comparison and Logical Operators • PBASIC: • +, -, *, / • &, |, ^ • >, >=, <, <= • =, <> • C: • +, -, *, / • &, |, ^ • >, >=, <, <= • ==, !=
PBASIC: (if-then): if (CONDITION) then (ADDRESS) If CONDITION is true then the program will jump to the section of the program labeled with ADDRESS. C: (if-else): if (CONDITION 1) { DO THIS } else if (CONDITION 2) { DO THIS } else { DO THIS BY DEFAULT } Conditionals: if-then vs. if-else
Looping: while • The while loop repeats a statement until the test at the top proves false. count = 0; while(count < 7) { count = count + 1; } while(condition is TRUE) { execute this block }
! means NOT Looping: while • Thewhileloop can also be used for waiting. while(!rc_dig_in01) { /* wait here */ }
Looping: while • This is an infinite loop. while(1) { /* wait here forever */ }
Debug statements:printf • PBASIC: • DEBUG “PWM01 = “,DEC pwm01, CR • C: • printf(“PWM01 = %d\n”,(int)pwm01); Output: PWM01 = 127