1 / 11

Macros (as aliases)

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.

thor-slater
Download Presentation

Macros (as aliases)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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*/

  2. 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”

  3. 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

  4. Don’t forget the semicolon! Assignments • PBASIC: • relay3_fwd = p3_sw_trig • C: • relay3_fwd = p3_sw_trig;

  5. Comparison and Logical Operators • PBASIC: • +, -, *, / • &, |, ^ • >, >=, <, <= • =, <> • C: • +, -, *, / • &, |, ^ • >, >=, <, <= • ==, !=

  6. 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

  7. 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 }

  8. ! means NOT Looping: while • Thewhileloop can also be used for waiting. while(!rc_dig_in01) { /* wait here */ }

  9. Looping: while • This is an infinite loop. while(1) { /* wait here forever */ }

  10. Debug statements:printf • PBASIC: • DEBUG “PWM01 = “,DEC pwm01, CR • C: • printf(“PWM01 = %d\n”,(int)pwm01); Output: PWM01 = 127

  11. That’s all the C knowledge you really need!

More Related