Presentation is loading. Please wait.

Presentation is loading. Please wait.

Instructor: Chien-Ho Ko

Similar presentations


Presentation on theme: "Instructor: Chien-Ho Ko"— Presentation transcript:

1 Instructor: Chien-Ho Ko
Introduction to C Instructor: Chien-Ho Ko

2 Outlines Introduction to Computers Programming Language
C Programming Environment How to Run C Programs First Program

3 Introduction to Computers
Computer VS Computer Systems Computer Hardware Categories of Software

4 Computer VS Computer Systems

5 Computer VS Computer Systems
Hardware (the computer) Data (information) Software (program) People (User)

6 Computer Hardware

7 Computer Hardware Memory Storage Processor Output Input Output

8 Categories of Software
System software: tells computers how to use its own components: Windows, Unix, Linux, Macintosh… (interpreter between Hardware & application) Application software: tells computers how to accomplish specific tasks

9 Programming Language What is Programming Language Machine Languages
Assembly Languages High Level Languages

10 What is Programming Language
A set of instructions that perform a specific task What is Programming Language An artificial & formal language making up instructions and a set of precise grammar rules

11 Machine Languages The natural language of a computer Drawbacks
Instructions are extremely difficult Simple problems require large number instructions Machine-dependent Un-portable

12 Assembly Languages Instructions consists of English-like abbreviations to make computers easier to program. Drawbacks Simple problems require large number instructions Machine-dependent Un-portable L 1, GROSSPAY S 1, TAX ST 1, NETPAY

13 High Level Languages Instructions are quite English-like
Single instruction: operations Drawback Must be converted to machine languages High level Assembly Machine NETPAY = GROSSPAY - TAX;

14 C Programming Environment
Why C How Does C Work How Does NXC Work IDE Language & Libraries

15 Why C-Never Out of Date 1970’s Dennis Ritchie, Bell Lab.
High level (convenient) + assembly (powerful) Approved by American National Standard Institute Portable C++=C + OO + New Feature

16 Why C-Never Out of Date NXC adopts C grammar
The most popular language for NXT

17 How Does C Work After loader transfers load module to main memory, CPU executes Process Text (source program)  Preprocessor (special instructions)  Translator (compiler)  Object Program (machine language)  Linker (library)  Load module (Executable machine language)

18 How Does NXC Work After firmware loads bytecode to memory, CPU executes Process Text (NXT code, source program)  Preprocessor (special instructions)  Translator (compiler)  Linker (library)  Object Program (Next bytecode in PC)  Object Program (Next bytecode in NXT)

19 Integrated Develop Environment
Text editor+ Preprocessor +C Compiler+ Library + Debug Microsoft VC++ Borland Turbo C++ Text editor+ Preprocessor +NXC Compiler+ Library + Debug BricxCC

20 Language & Libraries Language Libraries Provides basic operations
Extend C Standard libraries: # include <stdio.h> Programmer-defined libraries: # include <chko.h>

21 How to Run C Programs Edit: Create text, 03_c01.c
Preprocess: Special instructions Compile: machine language Link: libraries Run: executable machine language

22 First Program 1 /************************************************************* 2 Program Filename: 03_c01.c 3 Author: Chien-Ho Ko 4 Purpose: Draw triangle and trapezoid. 5 Output to: Screen 6 *************************************************************/ 7 #include <stdio.h> 8 9 int main(void) { 10 11 /* Function body: */ 12 printf(" \n"); 14 printf("| |\n"); 15 printf("| |\n"); 16 printf("| |\n"); 17 printf(" \n"); 18 printf(" /\\\n"); 20 printf(" / \\\n"); 21 printf(" / \\\n"); 22 printf(" / \\\n"); 23 printf(" \n"); 24 25 return 0; } /* end function main */

23 First Program NXC 1 /************************************************************* 2 Program Filename: 03_NXC01.nxc 3 Author: Chien-Ho Ko 4 Purpose: Basic robot control. 5 Output to: Motors 6 *************************************************************/ 7 8 task main() 9 { 10 OnFwd(OUT_A, 75); 11 OnFwd(OUT_C, 75); 12 Wait(100); 13 Off(OUT_AC); 14 } /* end function main */


Download ppt "Instructor: Chien-Ho Ko"

Similar presentations


Ads by Google