Você está na página 1de 73

Introduction to C Programming

Camp CAEN Wireless Communications

June 29, 2010

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

1 / 73

What is C Programming Language?

C is one of the most popular programming languages Developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories Replacement of the B programming language

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

2 / 73

The History of C

1969 1973 C was created by Dennis Ritchie of Bell Labs 1973 rst major use was to rewrite the UNIX kernel 1978 The C Programming Language published, Kernighan and Ritchie 1990 ISO standard approved, ISO/IEC 9899:1990 1999 ISO standard revised, ISO/IEC 9899:1999

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

3 / 73

The C Standard
http://www.open-std.org/jtc1/sc22/wg14/www/standards

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

4 / 73

The Classic K&R

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

5 / 73

C References

There are so many of them!

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

6 / 73

Some of Aspects of C

Considered by many as a high level assembly language. Typed language. Explicit use of pointers. Preprocessor. Structures. Passes arguments by value. Case sensitive. Ospring include: C++ (B. Stroustrup), C# (A. Hejlsberg and S. Wiltamuth).

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

7 / 73

C Programming Tools
For PC: Microsoft Visual Studio (Express) Microsoft Windows (Express edition is free) Xcode Mac OS X (free) GCC UNIX and Linux (Cygwin in Windows) C-Free Bloodshed Dev-C Eclipse Code::Blocks Open Watcom For TI hardware: Code Composer Studio Microsoft Windows
Camp CAEN Wireless Communications Introduction to C Programming June 29, 2010 8 / 73

C Programming Procedures
1 2 3 4

Edit the source code (a text le with .c extension lename) Compile the source code (C compiler) The compiler generates the executable program Run the executable

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

9 / 73

Compilation Process
Source codes for C programs are written as ASCII text. They must be compiled and linked to produce executable programs. The compilation of code involves several steps: Parsing of the statements for syntax Translation of the statements into machine language Setting up the addresses of all variables Optimization of the code (if desired) The linking step assembles the various routines produced by the compiler during the compilation step, and resolves missing calls to either language-specic libraries or system-wide functions.

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

10 / 73

Compilation Process

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

11 / 73

Use Microsoft Visual Studio IDE

See the handout.

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

12 / 73

Basic C Programming

Hello World! Standard I/O Data types Bit Operations Variable, Declaration and Assignment Array and Pointer Flow Control and Loop File I/O Function

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

13 / 73

Hello World!

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

14 / 73

Hello World!!

First program when learning the C language


#i n c l u d e < s t d i o . h> v o i d main ( ) { printf ( H e l l o World ! \ n ) ; }

Exercise
Create the above source code, compile it, and execute it. Whats the program output?

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

15 / 73

Standard I/O

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

16 / 73

printf()
#i n c l u d e < s t d i o . h> main ( ) { printf ( 1905+31214 i s %d , 1 9 0 5 + 3 1 2 1 4 ) ; }

Format speciers: The placeholder %d literally holds the place for the actual number that is the result of adding 1905 to 31214. %i int (same as %d) %f oat (oating-point number) %lf double %c char (character) %s string %x hexadecimal %u unsigned integer
Camp CAEN Wireless Communications Introduction to C Programming June 29, 2010 17 / 73

Newline

\n is a line break or end-of-line (EOL) character signifying the end of a line of text.

Exercise
Modify the Hello World! code to print out three lines of text strings.

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

18 / 73

Exercise
Write a program to print out the following on the screen: 1905 + 31214 ------33119
#i n c l u d e < s t d i o . h> main ( ) { printf ( 1905 \ n ) ; printf ( + 31214 \ n ) ; printf ( \n ) ; printf ( %d , 1 9 0 5 + 3 1 2 1 4 ) ; }

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

19 / 73

Input Using scanf()

scanf() get user input from keyboard


#i n c l u d e < s t d i o . h> main ( ) { int a; puts ( P l e a s e e n t e r a number : ) ; scanf ( %d , &a ) ; printf ( The number i s %d , a ) ; }

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

20 / 73

Include Files

All library functions in C are declared in header les (lename extension .h). Programmers have to include the header les in the source code in order to use the functions declared in it. stdio.h is the header in the C standard library that contains macro denitions, constants, and declarations of functions and types used for various standard input and output operations. Use triangle brackets <stdio.h> for system header les (C Standard Library), and double quotes myheader.h for user dened header les.

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

21 / 73

The Main Function

The main() function is where a program starts execution. The main function is special; normally every C program must dene it exactly once, with that name.

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

22 / 73

Print Formatted Function

printf() is the print formatted function. Output the formatted string to the standard output. Standard output is system and application dependent. It might not even be present.

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

23 / 73

Data Types

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

24 / 73

Data Types

C is a typed language. int integer number. char character. float oating point number. double BIG oating point numbers. It reserves twice the storage for the number. void allows us to create functions that either do not require any parameters or do not return a value. enum closely related to the #define preprocessor.

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

25 / 73

Data Type Examples

int x; x = 6; float y; y = 14.398; double z ; z = 1234567; char c ; c = 'g ' ;

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

26 / 73

Modiers

The modiers dene the amount of storage allocated to the variable. short long signed unsigned short int <= int <= long int float <= double <= long double

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

27 / 73

Sizes of Dierent Data Types


Dierent data types are represented by dierent number of bits. The size is system dependent. It is dened in limits.h sizeof() function can be used to nd the size of the data type in bytes (8 bits). For 32-bit processor:
Type Bytes Bits Range --------------------------------------------------------------------------short int 2 16 -16,384 -> +16,383 (16kb) unsigned short int 2 16 0 -> +32,767 (32Kb) unsigned int 4 16 0 -> +4,294,967,295 ( 4Gb) int 4 32 -2,147,483,648 -> +2,147,483,647 ( 2Gb) long int 4 32 -2,147,483,648 -> +2,147,483,647 ( 2Gb) signed char 1 8 -128 -> +127 unsigned char 1 8 0 -> +255 float 4 32 double 8 64 long double 12 96
Camp CAEN Wireless Communications Introduction to C Programming June 29, 2010 28 / 73

Exercise
Create, compile, and execute the following code.
#i n c l u d e < s t d i o . h> v o i d main ( ) { int a , b , c , d , e , f; a b c d e f = = = = = = sizeof ( int ); s i z e o f ( char ) ; sizeof ( float ); s i z e o f ( double ) ; s i z e o f ( long i n t ) ; sizeof ( short int ); of of of of of of i n t i s %d b y t e s \ n , a ) ; c h a r i s %d b y t e s \ n , b ) ; f l o a t i s %d b y t e s \ n , c ) ; d o u b l e i s %d b y t e s \ n , d ) ; l o n g i n t i s %d b y t e s \ n , e ) ; s h o r t i n t i s %d b y t e s \ n , f ) ;

printf ( s i z e printf ( s i z e printf ( s i z e printf ( s i z e printf ( s i z e printf ( s i z e }

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

29 / 73

Format Speciers

integer %d integer in Hex %x unsigned integer %u oating point number %f string %s character %c

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

30 / 73

Exercise
#i n c l u d e < s t d i o . h> main ( ) { printf ( C o l o r %s \ n , r e d ) ; printf ( number1 %d \ n , 1 2 3 4 5 6 ) ; printf ( number2 %05d \ n , 8 9 ) ; printf ( number3 %x \ n , 2 5 5 ) ; printf ( number4 %5.2 f \ n , 3 . 1 4 1 5 9 ) ; printf ( number5 %u \ n , 2 5 0 ) ; } Color red number1 123456 number2 00089 number3 ff number4 3 . 1 4 number5 250

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

31 / 73

Bit Operations

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

32 / 73

Bitwise Operations

AND (&) (&& for logical AND) OR (|) (|| for logical OR) XOR () NOT () ones complement Left shift (<<) Right shift (>>)

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

33 / 73

Bit Manipulations and Masking

Read and write a bit (or multiple bits) in a word. Read: b & 0 = 0, b & 1 = b Write: set to 1 --------b | 0 = b b | 1 = 1 set to 0 --------b & 0 = 0 b & 1 = b

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

34 / 73

Read
a = b15 b14 b13 . . . b4 b3 b2 b1 b0 What is b3 ?
b15 b14 b13 b12 b11 b10 0 0 0 0 0 0 0 0 0 0 0 0 b3 = (a & 0x0008) >> 3; i n t a , bit , bit_position , temp ; a = 23456; bit_position = 0 x0008 ; temp = a & bit_position ; bit = temp >> 3 ; b9 0 0 b8 0 0 b7 0 0 b6 0 0 b5 0 0 b4 0 0 b3 1 b3 b2 0 0 b1 0 0 b0 = a 0 = 0x0008 0 = a & 0x0008

Exercise
Whats the value of b10 b9 b8 b7?
Camp CAEN Wireless Communications Introduction to C Programming June 29, 2010 35 / 73

Write
a = b15 b14 b13 . . . b4 b3 b2 b1 b0 How to set b5 and b3 to 1?
b15 b14 b13 b12 b11 b10 0 0 0 0 0 0 b15 b14 b13 b12 b11 b10 b9 0 b9 b8 0 b8 b7 0 b7 b6 0 b6 b5 1 1 b4 0 b4 b3 1 1 b2 0 b2 b1 0 b1 b0 = a 0 = 0x0028 b0 = a | 0x0028

Exercise
How to set bit b8 to 0?
bit_position = 0x0100 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 --> 0x0100 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 a & (~bit_position)

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

36 / 73

Example BlinkLED.c
#define #define #define #define #define #define #define #define EALLOW asm(" eallow") EDIS asm(" edis") WDCR *(volatile int *)0x007029 GPAMUX2 *(volatile unsigned GPADIR *(volatile unsigned GPAPUD *(volatile unsigned GPATOGGLE *(volatile unsigned FOREVER 1

long long long long

*)0x6F88 *)0x6F8A *)0x6F8C *)0x6FC6

void main() { unsigned long counter=0L; EALLOW; WDCR = 0x0068; EDIS; // disable the watch dog

EALLOW; // configure GPIO pin 31 GPAMUX2 = GPAMUX2&0x3FFFFFFFF; GPADIR = (GPADIR & 0x7FFFFFFF)|0x80000000; GPAPUD = (GPAPUD & 0x7FFFFFFF)|0x80000000; EDIS; while(FOREVER) { while (counter++ <200000); //200 thousand counter = 0L; EALLOW; GPATOGGLE = 0x80000000; EDIS; } } Camp CAEN Wireless Communications

// GPIO31 as IO use // set direction to out // disable the pull up

Introduction to C Programming

June 29, 2010

37 / 73

The #define Directive


The #define creates a macro, which is the association of an identier or parameterized identier with a token string. After the macro is dened, the compiler preprocessor can substitute the token string for each occurrence of the identier in the source le. #define identifier definition
#d e f i n e COUNT 1000

If the statement
i n t arry [ COUNT ] ;

appears after this denition and in the same le as the denition, the preprocessor would change the statement to
i n t arry [ 1 0 0 0 ] ;

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

38 / 73

Variable, Declaration, and Assignment

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

39 / 73

Variable, Declaration, and Assignment


c h a r red ; int x; int y = 5;

Signedness
unsigned i n t x ; signed int y ; i n t z ; / Same a s s i g n e d i n t / u n s i g n e d c h a r grey ; s i g n e d c h a r white ;

Size
short int x ; long i n t y ; long long i n t z ; long i n t w ; long w ;

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

40 / 73

Exercise

#i n c l u d e < s t d i o . h> main ( ) { i n t a , b , c , sum ; a = 1; b = 2; c = 3; sum = a + b + c ; printf ( sum i s %d , sum ) ; }

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

41 / 73

Pre/Post Increment/Decrement Operators


++count; Pre Increment, means add one to count before access count++; Post Increment, means add one to count after access --count; count--;
#i n c l u d e < s t d i o . h> v o i d main ( ) { i n t count = 0 , loop ; loop = ++count ; / same a s c o u n t = c o u n t + 1 ; l o o p = c o u n t ; / printf ( l o o p = %d , c o u n t = %d \ n , loop , count ) ; loop = count ++; / same a s l o o p = c o u n t ; c o u n t = c o u n t + 1 ; / printf ( l o o p = %d , c o u n t = %d \ n , loop , count ) ; }
Camp CAEN Wireless Communications Introduction to C Programming June 29, 2010 42 / 73

Array and Pointer

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

43 / 73

Array

A set (group) of indexed variables of some data type. Similar to vectors in Matlab. Index starts at 0 and ends at size-1. (Matlab index goes from 1 to size).
int x [10]; int y [ 5 ] = {1 ,2 ,3 ,4 ,5};

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

44 / 73

Exercise
This a program which reads a line, stores it in a buer, and prints the line its length (excluding the newline at the end).
#i n c l u d e < s t d i o . h> v o i d main ( ) { int n , c , i; c h a r line [ 1 0 0 ] ; n = 0; w h i l e ( ( c=getchar ( ) ) != ' \ n ' ) { i f ( n < 100 ) line [ n ] = c ; n ++; } f o r ( i =0; i<n ; i++) { printf ( %c , line [ i ] ) ; } printf ( \ n ) ; printf ( l e n g t h = %d \ n , n ) ; }

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

45 / 73

Pointer
A pointer is a memory address. Declare a variable:
i n t foo ;

The variable foo occupies some memory location. Declare a pointer:


i n t foo_ptr = &foo ;

foo ptr is declared as a pointer to int. We have initialized it to point to foo. &foo represents the address of the memory location where the variable foo occupies.
foo = 7 ; foo_ptr = 7 ; // D e r e f e r e n c e a p o i n t e r
Camp CAEN Wireless Communications Introduction to C Programming June 29, 2010 46 / 73

Exercise

i n t foo ; i n t ptr ; ptr = &foo ; ptr = 4 7 ; (& foo ) = 5 6 ;

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

47 / 73

Pointer and Array

i n t x [ 3 ] = {13 , 57 , 6};

x is the address of the array, and can be used as a pointer points to the rst element of the array x[0]. x == &x[0], x+1 == &x[1], x+2 == &x[2] *x == x[0], *(x+1) = x[1], *(x+2) = x[2]

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

48 / 73

Exercise
#i n c l u d e < s t d i o . h> v o i d main ( ) { i n t x [ 3 ] = {13 , 57 , 6}; i n t ptr ; ptr = x ; printf ( f i r s t e l e m e n t : %d \ n , ( ptr ++)); printf ( s e c o n d e l e m e n t : %d \ n , ( ptr ++)); printf ( t h i r d e l e m e n t : %d \ n , ptr ) ; ptr = &x [ 1 ] ; printf ( %d \ n , ptr ) ; printf ( %d \ n , ( ptr 1 ) ) ; printf ( %d \ n , ( ptr + 1 ) ) ; }

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

49 / 73

Flow Control and Loop

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

50 / 73

Flow Control and Loop

if ... while do ... for

else while

break and continue switch case

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

51 / 73

The if-else Statement

i f ( / c o n d i t i o n g o e s h e r e / ) { / i f t h e c o n d i t i o n i s non z e r o ( t r u e ) , t h i s c o d e w i l l e x e c u t e } else { / i f t h e c o n d i t i o n i s 0 ( f a l s e ) , t h i s c o d e w i l l e x e c u t e / }

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

52 / 73

Relational and Equivalence Expressions

a < b: 1 if a is less than b, 0 otherwise. a > b: 1 if a is greater than b, 0 otherwise. a <= b: 1 if a is less than or equal to b, 0 otherwise. a >= b: 1 if a is greater than or equal to b, 0 otherwise. a == b: 1 if a is equal to b, 0 otherwise. a != b: 1 if a is not equal to b, 0 otherwise

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

53 / 73

Exercise
Write a program to take two user input numbers and print out the larger one.
#i n c l u d e < s t d i o . h> i n t main ( ) { int x ,y; printf ( E n t e r v a l u e f o r x : ) ; scanf ( %d ,& x ) ; printf ( E n t e r v a l u e f o r y : ) ; scanf ( %d ,& y ) ; if ( x > y ) { printf ( X i s t h e l a r g e r number : %d \ n , x ) ; } else { printf ( Y i s t h e l a r g e r number : %d \ n , y ) ; } return 0; }
Camp CAEN Wireless Communications Introduction to C Programming June 29, 2010 54 / 73

The while Loop Statement

w h i l e ( / c o n d i t i o n / ) { / t h i s c o d e w i l l e x e c u t e } i n t a =1; w h i l e ( a < 100) { printf ( a i s %d \ n , a ) ; a = a 2; }

i f the c o n d i t i o n

i s t r u e /

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

55 / 73

break and continue

A break statement will immediately exit the enclosing loop. A continue statement will skip the remainder of the block and start at the controlling conditional statement again.
i n t a =1; while (1) { printf ( a i s %d , a ) ; a = a 2; i f ( a > 100) { break ; } e l s e i f ( a ==64) { continue ; } printf ( a i s n o t 64 \ n ) ; }

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

56 / 73

The for Loop Statement


f o r ( initi alizati on ; test ; increment ) { / c o d e / } f o r ( i = 1 ; i <= 1 0 ; i++) { printf ( %d \ n , i ) ; } f o r ( i = 5 ; i > 0 ; i ) { printf ( %d , i ) ; }

Innite loop:
for ( ; ; ) { / b l o c k o f s t a t e m e n t s / }

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

57 / 73

The do-while Loop Statement

do-while loop is a post-check while loop. The statements in the loop will run at least once.
do { / do s t u f f / } w h i l e ( condition ) ;

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

58 / 73

File I/O

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

59 / 73

File I/O

There are types and functions in the library stdio.h that are used for le I/O. Make sure you always include that header when you use les. For les you want to read or write, you need a le pointer, e.g. FILE *fp; Reading from or writing to a le requires three basic steps:
1 2 3

Open the le. Do all the reading or writing. Close the le.

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

60 / 73

File I/O Modes

r open for reading w open for writing (le need not exist) a open for appending (le need not exist) r+ open for reading and writing, start at beginning w+ open for reading and writing (overwrite le) a+ open for reading and writing (append if le exists

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

61 / 73

Open a File (and Close it)


Create, compile, and execute the following code.
#i n c l u d e < s t d i o . h> #i n c l u d e < s t d l i b . h> v o i d main ( ) { FILE fp ; fp = fopen ( t e s t . t x t , r ) ; i f ( fp == NULL ) { printf ( F i l e open e r r o r ! \ n ) ; exit ( 1 ) ; } fclose ( fp ) ; }

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

62 / 73

Write to a File
fprintf()
i n t fprintf ( FILE stream , c o n s t c h a r format , #i n c l u d e < s t d i o . h> #i n c l u d e < s t d l i b . h> v o i d main ( ) { FILE fp ; fp = fopen ( t e s t . t x t , w ) ; i f ( fp == NULL ) { printf ( F i l e open e r r o r ! \ n ) ; exit ( 1 ) ; } fprintf ( fp , T e s t i n g . . . \ n ) ; fclose ( fp ) ; }
Camp CAEN Wireless Communications Introduction to C Programming June 29, 2010 63 / 73

...

);

Read from a File


fscanf()
i n t fscanf ( FILE stream , c o n s t c h a r format , #i n c l u d e < s t d i o . h> #i n c l u d e < s t d l i b . h> v o i d main ( ) { FILE fp ; int i; fp = fopen ( t e s t . t x t , r ) ; i f ( fp == NULL ) { printf ( F i l e open e r r o r ! \ n ) ; exit ( 1 ) ; } w h i l e ( fscanf ( fp , %d ,& i ) != EOF ) { printf ( %d \ n , i ) ; } fclose ( fp ) ; }
Camp CAEN Wireless Communications Introduction to C Programming June 29, 2010 64 / 73

...

);

Exercise

Write 10 numbers from user input using scanf() to a le, then read them out and show on the screen using printf().

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

65 / 73

Functions in C

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

66 / 73

Functions in C
i n t sum ( i n t a , i n t b ) { int c; c = a + b; return c ; }

Function prototype:
i n t sum ( i n t , i n t ) ;

input: int a, int b output: int c by return To use a function, the function prototype must be included in the source le. The function source code can be in the same le as the main source code, or in a separate le.
Camp CAEN Wireless Communications Introduction to C Programming June 29, 2010 67 / 73

Exercise

Write a function to compute the correlation of two arrays of the same length. Use the following prototype (rst input: array 1, second input: array 2, third input: size of the array)
i n t Correlate ( i n t , i n t ) ;

Test your function with length 31 m-sequence.

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

68 / 73

C Programming Projects

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

69 / 73

C Programming Projects

m-sequence correlator direct digital synthesis (DDS) Digital modulation BPSK, QPSK, 8-PSK, QAM

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

70 / 73

m-sequence Correlator

Project structure and setup Use length 31 m-sequence Use your correlator function Rewrite your correlator function using circular buer

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

71 / 73

Direct Digital Synthesis (DDS)

DDS and DTMF Create a sine table in C (math library) or Matlab Generate DDS using the sine table Two DDS for DTMF Write the DTMF signal to a le Plot the DTMF signal in Matlab

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

72 / 73

Digital Modulation

BPSK QPSK 8-PSK QAM

Camp CAEN Wireless Communications

Introduction to C Programming

June 29, 2010

73 / 73