Sie sind auf Seite 1von 4

Introduction

 Scope of the course


Prerequisite for EE150 (see syllabus for more details)
EE140: Introduction to

 Basic skills in programming and software development


Programming Concepts for Engineers  C will be used as the programming language to illustrate the
concepts. C is the language of choice for programming embedded
and mechatronic systems with hardware interfaces.
 Basic UNIX commands
 Textbook Recommendations:
Lecture 1: Introduction  C How to Program, 8th Ed., Prentice-Hall, by Deitels
 The Indispensable Guide to C, Addison-Wesley, by Davies
 The C programming Lanuage, Prentice-Hall, by Kernighan & Ritchie
 Problem solving and Program Design in C, Addison-Wesley, by Hanly
and Koffman

1 2

What is UNIX? Your UNIX Account


 UNIX is an operating system, like windows. It is very popular in  Everyone will be assigned a UNIX account with a
universities and colleges. username and a default password.
 It was designed and developed in the late 60's and 70's in Bell
Labs to help scientists write papers, store/share/manipulate  How to login in/out your UNIX account?
data, exchange ideas, and work with others.  Use putty to access your UNIX account
 UNIX system can run multiple applications at the same time  Putty.exe can be downloaded at
(multitasking); it allows multiple users to use the same system at http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
the same time (multiuser); it has programming shells to enable  Host name: tpaclinux.montgomerycollege.edu
the communication between user and UNIX kernel. The  To exit from a login session, type logout or exit
portability to a wide range of computers makes it possible to  To change your password, use passwd (highly recommended)
move applications from one system to another.

3 4

1
UNIX File System and Directories Useful UNIX Commands
 ls list files and directories
 Unix file system consists of files and directories.
 ls -a list all files and directories (including hidden
 When you first login, your current working directory is your home
files)
directory, and it is where your personal files and subdirectories are
saved.  ls –l list all files and detailed information
drwxr-xr-x 2 lxiang users 4096 Nov 28 14:13 test
 / Top root directory for all the users
~ Your home directory (Unix file types, permissions, number of hard links, owner, group, size,
date, and filename)
. Current directory
.. Parent directory  mkdir directory make/create a directory
 A directory may contain several files and subdirectories. Examples:  cd directory go to named directory
/home/faculty/lxiang  cd ~ go to home directory (root for individual user)
/home/faculty/lxiang/test/display.c  cd .. go to parent directory (go one level up)
~/test/display.c  cd / go to top root directory for all users

5 6
6

More useful UNIX Commands More useful UNIX Commands


 rm filename remove a file  more/cat file view a file content (cannot edit)
 rm -r directory remove a directory (This will delete all the files and  chmod mode file/dir change the access mode of a file or a directory
directories under that directory. No way to recover!)
chmod +x runme   set "runme" executable
 rmdir directory remove an empty directory
chmod 733 sample  set "sample" rwx by user, -wx by group, -w-
 mv file1 file2 move (or rename) file1 to file2
If file2 exist, it will be overwritten by file1. by all other users
mv test.c new.c  move test.c to new.c under current directory Binary coded mode: 7 – 111, 3 – 011, 2 - 010
mv test.c ../new.c move test.c to parent directory renamed as new.c  echo print out what you type in
 mv file1 directory move file1 to specified directory  pwd display the path of the current directory
mv test.c ~/new  move test.c to directory ~/new (if new exists)
 man command display UNIX reference manual
 cp file1 file2 copy file1 to file2
cp test.c new.c  copy test.c to new.c under current directory  logout (exit) logout the current session
 cp file1 directory copy file1 to specified directory if exists
 cp –r dir1 dir2 copy directory1 to directory2 (including subdirectoies)

7 8

2
Useful Information UNIX Text Editor: vi/vim
 UNIX tutorial for beginners:  vi/vim is a powerful UNIX-oriented text editor; vi is the
http://www.ee.surrey.ac.uk/Teaching/Unix/index.html original editor and vim stands for "vi improved". We will
 You can use the up- and down- arrow keys to scroll use vi/vim to create all the text files including C codes.
through previous commands that you have executed  vi operates in two different "modes":
 Automatic filename completion is a useful utility. To use  Command mode
 vi starts up in this mode
it, just type a few letters of the desired file name, and
then press tab key, shell will fill in the rest of the name  Whatever you type is interpreted as a command

for you (provided the completion is unique).  Insert mode


 This is the mode you use to type (insert) text.
 Keep your account organized by creating a file system
 You can press 'i' to enter the insert mode.
hierarchy.
 Must press the ESC (escape) key to exit this mode and return
 You can select text with the mouse to copy and right- to command mode.
click your mouse to paste
9 10

Basic vi/vim Commands Simple Programming Concepts


 All the commands are used in the Command mode  Step 1: Design and Create
(Press Esc to go back to command mode once you  Develop algorithm (the way or method to solve the problem)
finished typing your text files)  Plan for the implementation of the algorithm
 Type in the source code of the program using a text editor
:wq – save and quit 
such as vi/vim
:q – quit (if you haven't made any changes)
:w – save the file  Step 2: Compile
:w filename – save as filename   Convert the source code (high level) into machine code (low
:q! ‐ quit without saving the changes level) that the computer understands; Link all the components
together into one executable file
:n  ‐ jump to line n
 Go back to Step 1 if there are programming or syntax errors
u – undo changes
dd – delete the current line  Step 3: Execute, test, and debug your program on sample
/text – search forward for text data
?text – search backward for text  Go back to Step 1 if necessary

11 12

3
Example: Hello.c Compiling and Executing Program
 Let us create a simple C source code using vim (Step 1)  You can compile your program with gcc (Step 2)
cd test (go to your test directory)
vim hello.c (open program vim and edit a file called hello.c) gcc hello.c –o hello.exe

(press 'i' to enter insert mode to type in the code; once done,  This will compile hello.c program.
press Esc to go back to command mode and then type :wq to save
 use –o option to specify the name of the executable file.
and quit vim to go back the UNIX prompt.)
 If compilation is successful, it will generate an executable
/* Your first C program: hello.c */ called hello.exe
 If there are any errors, go back to Step 1 (vim hello.c) to
#include <stdio.h>
edit your source code
int main()  gcc comes with many options. For a listing of options, you can
{ type gcc – help
printf( "Hello!\n");
 To execute the program, type ./hello.exe (Step 3)
return 0;
}
13 14

How to Submit Your Assignment


 Do not submit any irrelevant work. Create a specific directory of the
work you need to submit.
 Make a tar gunzip file of your working directory. Make sure that you
first go one level above to its parent directory to make a tar file. Do
not zip it when you are still in the current working directory. Use ls to
check!
cd ..
tar –czvf YourName_HW1.tar.gz  HW1

This creates a zip file named YourName_HW1.tar.gz of your HW1


directory. Replace HW1 by the directory name you want to zip.

 Then copy your zip file to my dropbox under specified directory.


Remember it is case sensitive!
cp YourName_HW1.tar.gz  /home/faculty/lxiang/dropbox/ee140/HW
15

Das könnte Ihnen auch gefallen