How to use the CCS compiler with the serial port.

Slides:



Advertisements
Similar presentations
EMS1EP Lecture 7 Program Structure and Serial I/O Dr. Robert Ross.
Advertisements

EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
An Introduction to C Adam Gleitman – IAP 2014.
Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
Dale Roberts Basic I/O – scanf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Computer Science 1620 C++ - Basics. #include using namespace std; int main() { return 0; } A very basic C++ Program. When writing your first programs,
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
Eejit’s guide to using a LCD alphanumeric display with the CCS C compiler 1.Hardware connection 2.The LCD.C include file 3.An example.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
CS 161 Introduction to Programming and Problem Solving Chapter 13 Console IO Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
Files Programs and data are stored on disk in structures called files Examples Turbo C++ - binary file Word binary file lab1.c - text file lab1.data.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
1 - buttons Click “Step Forward” to execute one line of the program. Click “Reset” to start over. “Play,” “Stop,” and “Step Back” are disabled in this.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
C Tokens Identifiers Keywords Constants Operators Special symbols.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Adv. UNIX:io/91 Advanced UNIX v Objectives of these slides: –look in some detail at standard input and output in C Special Topics in Comp.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
Code The Arduino Environment.
ITEC 320 Lecture 11 Application Part Deux Look Ahead.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
1 CSC241: Object Oriented Programming Lecture No 02.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
ARDUINO 1. Basics  Comments  /* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
CSCI 130 Basic Input and Output Chapter 9. The printf ( ) function Printf(“\nThe value of x is %d”, x); Displayed to screen (assume x = 12): –The value.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
C is a high level language (HLL)
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
Serial Communication RS-232. In order to make two devices communicate, whether they are desktop computers, microcontrollers, or any other form of integrated.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
C Formatted Input/Output
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Arduino Programming Part II
Programming Fundamentals
TMF1414 Introduction to Programming
Introduction to C CSE 2031 Fall /3/ :33 AM.
CSE1320 Files in C Dr. Sajib Datta
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Chapter 08- printf and scanf
1 Code
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Programming Assignment #1 12-Month Calendar—
Differences between Java and C
Conversion Check your class notes and given examples at class.
Chapter 4 Managing Input and Output Operations
Module 12 Input and Output
Professor Jodi Neely-Ritz University of Florida
Presentation transcript:

How to use the CCS compiler with the serial port

Setting up and initialization 1. Tell the compiler what pins are to be used for the transmit and receive serial streams. For example, if you want a 4,800-baud serial connection using pins RC6 and RC7 to trasmit and receive then put the following line at the head of your program: #use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7) Hint: Do not leave spaces around the = sign! Hint: If you choose these pins the compiler will automatically use the integral USART. Other pins can be used, in which case the compiler will generate/process signals using software only. There are many other options for the serial port. For example, you can have more than one serial port by giving each stream its own #use rs232 incantation; each with unique pins and with a name. For instance, stream=GPS. Functions such as fputc() can then name the serial port as required.

2. To transmit a single character from the serial port then use the putchar() (or putc() ) function. For example, to send out the character Z: putchar(‘Z’); 3. To transmit a single byte from the serial port then specify the byte as the function argument. For example, to send out the byte hex 0D (which happens to be the code for Carriage Return: putchar(0x0d); 4. To transmit a complete character string then use the puts() function. For example, to transmit the message “ Hello world ”: puts(“Hello world”); Hint: A new-line (Carriage-feed, Line-Feed or 0x0D, 0x0A) sequence is sent out automatically after the message. Outputting a single character or string

Outputting strings and data values Say you want to print out the value of some variables, as well as an optional message e.g.: int i = 0; /* Loop counter*/ while(TRUE) /* DO forever*/ { printf(“Hello world for the %uth time\n\r”,i); } Tags are put in the string which then pick up the list of comma separated variables at the end. These tags should match the type of variable. Some of these are (see manual): %u Unsigned int %lu Long Unsigned int %d signed Decimal %ld Long signed int %x/X Unsigned int in hex/Hex %lx/lX Long Unsigned int in hex/Hex Hint: A number can appear after the % ; e.g. %4lu means print only the first four digits or %04lu means pad out with leading zeros. Tag for unsigned int New line/Return

To receive a single character from the serial port then use the getchar() (or getc()) function. For example: char answer; /* Sometime later*/ printf(“Continue? Input Y or N.”); while(TRUE) { value = getchar();/* Get a character */ if((value == ‘Y’)| (value == ‘y’)) {do this;} if ((value == ‘N’) | (value == ‘n’)) {do that;} } This askes the operator to input a Y (for Yes) or N (for No) and waits (forever!) for a response. Provided it is a Y (or y) or N (or n) then something happens. If it is anything else, then it waits for the next character. Reading in from the serial port