Elements of IC n IC interface instructions l file types, loading, debugging n Data Objects l data types, constants, variables, characters n Expressions.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
ARDUINO CLUB Session 1: C & An Introduction to Linux.
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Computer Programming w/ Eng. Applications
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
An Introduction to C Adam Gleitman – IAP 2014.
Team 5220 Roboknights. Outline  Getting Started  Hardware Setup/Wiring  Software Setup/Pragmas  Programming with RobotC  Grammar/Syntax  Basic Statements.
Handy Board. Why the Handy Board Designed to be the controller of small, mobil robots Has many features that make it ideal for robotics projects –Integrated.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
CMT Programming Software Applications
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Chapter 2 Getting Started in C Programming
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Python  By: Ben Blake, Andrew Dzambo, Paul Flanagan.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Robot Building Lab: Introduction Lab 1 The Handy Board and Interactive-C (IC) es/robotlab/labs/lab1.ps.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
CPS120: Introduction to Computer Science Decision Making in Programs.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Basic Java Syntax COMP 401, Spring 2014 Lecture 2 1/14/2014.
Slide 1 Project 1 Task 2 T&N3311 PJ1 Information & Communications Technology HD in Telecommunications and Networking Task 2 Briefing The Design of a Computer.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CSE 1320 Basics Dr. Sajib Datta
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Introduction to Programming the Arduino Dr Gaw 3/21/14.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Information and Computer Sciences University of Hawaii, Manoa
The Machine Model Memory
Week 3 - Friday CS222.
Tokens in C Keywords Identifiers Constants
C Short Overview Lembit Jürimägi.
Chapter 3: Understanding C# Language Fundamentals
CET 3640 – Lecture 2 Java Syntax Chapters 2, 4, 5
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Lectures on Numerical Methods
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Your questions from last session
Elementary Programming (C++)
C Programming Getting started Variables Basic C operators Conditionals
Introduction to Java Applications
Fundamental Programming
Homework Finishing Chapter 2 of K&R. We will go through Chapter 3 very quickly. Not a lot is new. Questions?
Chapter 11 Programming in C
C++ Programming Basics
Unit 3: Variables in Java
Module 2 Variables, Data Types and Arithmetic
Programming Languages and Paradigms
C Language B. DHIVYA 17PCA140 II MCA.
Presentation transcript:

Elements of IC n IC interface instructions l file types, loading, debugging n Data Objects l data types, constants, variables, characters n Expressions and Operators n Statements n Program Flow Control n Functions l main( ), library, yours n LCD Printing n Multi-Tasking and Processes n Good Programming Practices

Good Programming Practices n Use LOTS of /* Comments */ l task description is a good start l no storage penalty n Use Descriptive Names l constants, variables, & functions n Add more /* Comments */ n Never put number constants in code n /* Comments */ Really help you & the team. n Use Text Formatting l indents, capitalization, etc. n Debugging is easier with /* Comments */ n Use Functions Extensively n Did I mention use of /* Comments */ ?

/********************************************** Meaningful Encounter with a Wall Program JFY, 9/17/99; Go forward until I hit wall; stop, reverse and stop. ************************************************/ /* GLOBAL CONSTANTS */ int L_MOTOR = 0;/* motor port #s */ int R_MOTOR = 1; int BUMPER_SWITCH = 0; /* digital port # */ int OPEN = 0; int CLOSED = 1; float DELAY = 0.5; /* Back-up time */ void main() { Go_Forward(); while(digital(BUMBER_SWITCH)==OPEN){;} /* wait until I hit the wall */ alloff();/* stop the motors */ beep(); Go_Backward(); sleep(DELAY); /* back away from wall a bit */ alloff(); printf(“I found the wall! \n”); beep(); beep(); beep(); }/* END of main() */

IC Interface n Program types l A-Program-File.c l Find-the-Wall.lis persistent variables.c constants.c go-forward3.c go-backward2.c my-main.c l Location of files n IC Instructions l load file.c or file.lis l unload file.c [to get rid of main()] l list files, list functions, list globals l help l quit n Line Recall & Editing l , , etc.

Variables & Constants Type must be declared at 1st Use n Data or Number Types: l integer: 16 bits, ±32,767 int m=12; l long: 32 bits, ±2 32 or 2B long k=0L; l floating point, ±10 ±32 ; 7 decimal digits float foo = 70.; float foo = 70.0; float foo = 7E1; float Zero = 0.0; l Characters, 8-bit ASCII Code ‘x’ yields its ASCII value, 120 char string[ ] = “Hello World!”; n Arrays, a sequence of data elements l int foo[6]; elements 0 to 5 l int foo[ ] = {4, 0, 5, 13, 7, 127}; foo[3] has value 13

Variables & Constants n Names case sensitive l No spaces -- use under_score n Scope: l Global declared outside a function valid within all functions, all files. l Local: valid only within a function or {} declared in that function, or as its argument. n Initialized when l new code loaded l main( ) is run l hardware reset (power on, or RESET) n Persistent Global Variables l Never initialized l persistent int m; l Place at beginning of code to preserve l Use for calibration values

Operators n Assignment l a = a + 2; or a += 2; n Integers l Arithmetic: +, –, *, / l Increment & Decrement b = a++; increment after assignment b = ++a; increment before assignment l Boolean: 0 represents FALSE OR ||, AND &&,, NOT ! l Comparison >, =, <= l Bitwise Logic OR |, AND &, XOR ^, NOT ~ n Long Integers: l Arithmetic, but No Division l Comparisons n Floating Point l Arithmetic & Comparisons; math functions

Statements & Expressions n Operators act upon objects of a certain type and specify what is to be done to them. n Expressions combine variables and constants using operators to create new values. l Association and precedence: ( ), [ ] l Object types must match Changing type: (float) 3 n Statements are expressions, assignments, function calls, or flow control statements which make up C programs. l Every statement ends with ; Not required for function definition, before { l Group into meta-statement blocks with { } Each inside statement needs a ; No ; following the right brace Local variables may be assigned

Functions n A block of statements that performs a single, well defined task or computation. n Use of functions is critical to good programming practice, program development & debugging. n A function may return a value, & must be typed l void, int, long, float n Arguments optional, but must be typed. n One unique function: main( ) l Only one version may be loaded l Starts on reset, unless “Choose” n Example function definition: int square(int n) { return(n*n); } /* end of square() */

n Functions within functions: float hypotenuse(int a, int b) { /* define local variable */ float h; h = sqrt( (float) [square(a) + square(b)] ); return(h); } /* end of hypotenuse() */ sqrt() is a pre-defined library function of type float with argument type float. l Note the coercion of integer type to float l h, a, & b are variables local to hypotenuse() n Function Libraries l Floating point math; RoboBoard; Yours.

Function Libraries n IC\libs\robo.lis l floating point math functions l Input & Output functions l IR beacon functions l Time and Process functions l Sound functions n IC\libs\encoders.lis l shaft encoder functions n Test Programs: IC\libs\ l testports.lis l QT.c n Your Function Definitions l In IC\libs\ or l IC\my-lib [specify directory] l IC\libs\my-lib [specify directory]

Floating Point Functions n Trigonometric, angles in radians l float sin(float angle) l float cos(float angle) l float tan(float angle) l float atan(float tangent) n Log and Exponential l float log10(float num) l float exp10(float num) l float log(float num) l float exp(float num) n Other l float sqrt(float num) l (float) a ^ (float) b (float) 2 ^ (float) 3 returns 8

IC Library Functions n Motor Control l motor(p,s); forward(p); reverse(p); off(p); alloff(); ao(); motor_force(p); n Other Outputs l led_out0(n); led_out1(n); l digital_out(p,n); n External Sensor Input l digital(p); 0 <= p <= 7 & 30 l analog(p); 20 <= p <= 27 n On-Board Conditions l dip_switch(n); dip_switches(); robo_knob(); choose_button(); escape_button(); voltage(); n Time l reset_system_time(); seconds(); mseconds(); msleep(msec); sleep(sec);

IC Library Functions n Shaft Encoding l enable_encoder(p); read_encoder(p); reset_encoder(p); disable_encoder(p); l digital ports 0, 1, 2, & 3 n Sound l beep(); set_beeper_pitch(freq); beeper_on(); beeper_off(); tone(freq, sec); play(song); n IR Beacon l set_ir_transmit_frequency(freq); set_ir_receive_frequency(freq); freq = 100 or 125 l ir_transmit_on(); ir_transmit_off(); l ir_receive_on(); ir_counts(p); ir_receive_off(); digital ports 2, 3, 4, & 5 n Process Functions

Program Flow Control n while ( expression ) statement n if ( expression ) statement-1 else /* optional */ statement-2 n for ( expr-1; expr-2; expr-3 ) statement /* Example */ int n; for (n=0; n<100; n++) printf(“&d\n”, n) n break

LCD Printing printf( “format-string”, arg-1, arg-2, … arg-N); n Format elements: l Character string: Hello World! l end of line: \n l Integer number in decimal: %d l Integer number in hex: %x l Integer number in binary: %b low byte only l Integer (low byte) as ASCII: %c l Floating point number: %f l NO formatting for long type n Arguments: constants, variables, expressions. n Treated as a single line even in two-line LCD; truncated if too long.

Multiple Processes n Processes can be created and destroyed dynamically to perform particular tasks with their own local variables. l Unique process id number: pid n Processes run sequentially for a given time, or “ticks” in milliseconds l default is 5 ticks n Processes can communicate through global variables n Commands l int start_process(funct( ), [ticks,] [stack,]); l int kill_process(pid); l void defer();

/************************ Quick Test of RoboBoard, JFY 9/99; A version of "testports" that doesn't take so many button pushes. *******************/ /* Global Definitions */ float DELAY = 0.5; /* A timing delay parameter */ int BEACON_PORT = 2;/* port for IR sensor test */ int ON = 1; int OFF = 0; int n;/* General counter variable */ void main() { beep(); printf("Quick Test:Push Choose to Start\n"); clear_board(); wait_for_choose(); /* Wait for Choose button to start; tests beeper, LCD, and Choose */

motor_test(); LED_test(); beacon_test(); digital_port_test(); analog_port_test(); RoboKnob_test(); DIPswitch_test(); printf("End: Quick Test\n"); }/* End of main() */ void clear_board() /* Turn off motors, LEDs, and beacon. */ { ao(); led_out0(OFF); led_out1(OFF); ir_transmit_off(); ir_receive_off(); }/* end clear_board() */ void wait_for_choose() /* Debounce "choose" button */ { while(!choose_button()); while(choose_button()); }/* End wait_for_choose() */

void digital_port_test() /* Read all the digital ports in sequence until "choose" */ { printf("Digital Ports Test: Choose\n"); wait_for_choose(); while(!choose_button()) {for(n=0;n<8;n++) {printf("Port: %d = %d\n", n, digital(n)); sleep(2.0*DELAY); if(choose_button()) break; /* don't wait whole loop */ }/* end "for" */ }/* end "while" */ printf("End Digital Ports Test\n"); sleep(2.0*DELAY); }/* end digital_port_test() */