Before Class Install SDCC Instructions in Installing_SiLabs-SDCC- Drivers document. Solutions to Number Systems Worksheet. Announcements.

Similar documents
By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Outline for Today. Lab Equipment & Procedures. Teaching Assistants. Announcements

Announcements Homework #3 due today. Ports. Outline for Today C8051 SFRs & Port I/O Worksheet #4 - simple I/O code. Using Ports

Review Activity 1 CALL and RET commands in assembler

Embedded Systems - FS 2018

MICROPROCESSORS A (17.383) Fall Lecture Outline

CSCI 2212: Intermediate Programming / C Chapter 15

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

Course Outline Introduction to C-Programming

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

Computers Programming Course 6. Iulian Năstac

LAB 1 Binary Numbers/ Introduction to C. Rajesh Rajamani. ME 4231 Department of Mechanical Engineering University Of Minnesota

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

Arithmetic and Bitwise Operations on Binary Data

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

Beginning C Programming for Engineers

Embedded Systems - FS 2018

COMP2611: Computer Organization. Data Representation

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

CMPE 8 Lab 3: Introduction to the Scribbler 2 and SPIN

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

ME 461 C review Session Fall 2009 S. Keres

MICROPROCESSORS A (17.383) Fall Lecture Outline

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

DEPARTMENT OF MATHS, MJ COLLEGE

Chapter 3: Operators, Expressions and Type Conversion

CS 31: Intro to Systems Binary Arithmetic. Martin Gagné Swarthmore College January 24, 2016

Programming refresher and intro to C programming

IME-100 Interdisciplinary Design and Manufacturing

CS 241 Data Organization Binary

Chapter 4. Operations on Data

Using peripherals on the MSP430 (if time)

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

ISA 563 : Fundamentals of Systems Programming

Arithmetic and Bitwise Operations on Binary Data

Why embedded systems?

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #3: Of Integers and Endians (pt. 2)

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

CS3157: Advanced Programming. Outline

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

SU 2017 May 11/16 LAB 2: Character and integer literals, number systems, character arrays manipulation, relational operator

UNIT- 3 Introduction to C++

ECE2049-E18 Lecture 6 Notes 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

CS33 Project Gear Up. Data

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

Course Outline. TERM EFFECTIVE: Spring 2016 CURRICULUM APPROVAL DATE: 10/12/2015

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #9: Exam Review w/ Solutions

Few reminders and demos

Fundamental of Programming (C)

1007 Imperative Programming Part II

Fundamentals of Programming

C Programming for Electronic Engineers

ECE2049 E17 Lecture 2: Data Representations & C Programming Basics

C Language Programming

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2

Computer Organization & Systems Exam I Example Questions

CIS 110: Introduction to Computer Programming

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

11. A Computing Machine

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

C-string format with scanf/printf

IME-100 ECE. Lab 3. Electrical and Computer Engineering Department Kettering University. G. Tewolde, IME100-ECE,

Data III & Integers I

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

Operators. Java operators are classified into three categories:

ECE2049-E17 Lecture 6 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

ECE2049 E17 Lecture 4 MSP430 Architecture & Intro to Digital I/O

Binary Representations and Arithmetic

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

Data III & Integers I

Laboratory Introduction to Embedded Control

CS2630: Computer Organization Homework 1 Bits, bytes, and memory organization Due January 25, 2017, 11:59pm

The Design of C: A Rational Reconstruction

UNIVERSITY OF LIMERICK OLLSCOIL LUIMNIGH COLLEGE OF INFORMATICS & ELECTRONICS DEPARTMENT OF ELECTRONIC & COMPUTER ENGINEERING

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

CS16 Exam #1 7/17/ Minutes 100 Points total

Magic 8 Ball. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

A flow chart is a graphical or symbolic representation of a process.

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 2

Lecture 03 Bits, Bytes and Data Types

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Programming. Elementary Concepts

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

6.096 Introduction to C++ January (IAP) 2009

EE292: Fundamentals of ECE

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

Lec 3. Compilers, Debugging, Hello World, and Variables

C Programming Language (Chapter 2 of K&R) Variables and Constants

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

C Programming Language

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

COMP2121: Microprocessors and Interfacing. Number Systems

mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut

Bits, Words, and Integers

SECTION II: LANGUAGE BASICS

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018

Transcription:

August 15, 2016 Before Class Install SDCC Instructions in Installing_SiLabs-SDCC- Drivers document Install SiLabs Instructions in Installing_SiLabs-SDCC- Drivers document Install SecureCRT On LMS, also available online by going to the computer store site. LMS: Course Resources>>Software&Drivers>>securecrt-rpi_5-5.exe (or http://www.rpi.edu/dept/arc/web/software/sw_available.html) Download the c8051_sdcc.h header file Available on the front page of the course LMS web page Solutions to Number Systems Worksheet 1) 0000 1110 2) 1011 1101 3) 0001 0000 0001 4) 0001 1101 1000 5) 0x0E 6) 0xBD 7) 0x101 8) 0x1D8 9) 55 10) 171 11) 327 12) 10977 13) 0011 0111 14) 1010 1011 15) 0000 0001 0100 0111 16) 0010 1010 1110 0001 17) 0x2D 18) 0xAA 19) 0xE3 20) 0x29B5 21) 45 22) 170 23) 227 24) 10677 Install USB-serial driver Link in Homework 1 2 3 Announcements Overview Homework 2 due next week (before 3 rd class) Considered late if turned in after class starts If you are still not registered for this class, please take care of it. TAs We are still working on this stay tuned Homework softcopy Compile, download, and run Homework #1 Edit code, compile, download, and run Discussion of variable types LOGIC Worksheet Labs 1 and 2 Overview Common digital gates Some basic circuitry 4 5

August 15, 2016 SiLabs IDE Software Communication Connections Microcontroller commands are converted to Assembly We will be writing code in the C programming language and compiling it into Assembly using the SiLabs IDE and the SDCC compiler. The SiLabs IDE will check for syntax errors, compile the code, and download it into the microcontroller flash memory The microprocessor will execute the programs stored in its memory, and does not need to be connected to any other computer to function the processor is embedded in the system Many of the programs we will write in this course, though, will have user interaction in the form of text printed on a screen and keyboard inputs Feedback can be provided by other means such as turning on/off LEDs or buzzers or making adjustments to the motors The serial port found on the C8051 board edge should be connected with a serial cable to the computer running SecureCRT or Hyperterminal This is for text communication with the microcontroller (printf, getchar, etc.) The USB adaptor strapped behind the C8051 should be connected with a USB cable to the computer running the SiLabs IDE This is for downloading the code Turn on power to C8051 TURN OFF AFTER DONE!! 6 8 Running Silicon Labs IDE Refer to instructions on LMS (also in Installing_SiLabs-SDCC-Drivers PDF) Under Course Materials -- Lab1 -- How to run codes Running the listed code listed in this handout is optional. It proves that everything is working. You are required to run the homework 1 code. Run SiLabs IDE, Click on Project New Project Device family C8051F02x Give it a name Pick a location strongly recommend creating a folder for projects Add Files to Project Suggestion right click on Header Files and remove, same for Source Files Right click in white area on left and Add files to Project Load your.c file then right click the file to Add name.c to build Things to check Options connection options USB Debug Adapter Click the Icons Connect Assemble/compile Build/Make Download Go/Stop Running HW1 Code Make sure you have installed the software completely Read instructions from course website Be sure to have saved the c8051_sdcc.h header file in C:\Program Files (x86)\sdcc\include\mcs51 Connect the USB serial port adaptor check device manager to get port numbers A COM port will be used by SecureCRT or HyperTerminal to receive feedback Open the SecureCRT software, and set the COM port Compile/Build/Download Note the error messages remember the line numbers being flagged Run the program for imax values of 18 and 270 by entering 1 or 2 at the prompt. Observe the results (what is wrong?) 9 10

August 15, 2016 Modify It, Run It Again!! Appropriate Variable Choices Change variable count from unsigned character type to integer type. Check lab manual index for printf syntax %d is for printing signed decimal values %u is for an unsigned decimal value %x is for hexadecimal values (note: no 0x is printed) %c is for printing single byte character values Compile, download and run for the same values of imax (18 and 270). Note the differences. Why do we care? Embedded controllers become more expensive as their memory requirements increase. The system also becomes more complicated. What should we do to help ourselves? Always use the smallest variable type consistent with our objective. Recommended practices: Use unsigned char for digital input and output (I/O) and the analog-to-digital conversion subsystem Can use the bit variable type for simple T/F variables Use int or unsigned int when larger variables needed Use long and float types as a last resort 11 12 Appropriate Variable Choices (Cx51 C compiler manual & in LITEC Lab Manual) There are many operators available in C to perform operations on numerical values mathematical: +, -, *, /, % (mod remainder) relational tests: <, >, <=, >= equality tests: ==,!= logical tests: (OR), && (AND) bitwise: & (AND), (OR), ^ (XOR), << (left shift), >> (right shift) unary: ++ (increment), -- (decrement), ~ (ones complement),! (logical negation) others listed in lab manual Chapter 3 13 14

August 15, 2016 True/False Logic True/False Logic When the computer performs decision making, it evaluates whether a given argument is True or False For binary operations, we are familiar with the following concept 0 False 1 True For example, the following lines of code will only print Goodbye (and return to the next line) The C code is a little more flexible than simple binary inputs for the argument. Anything that is not a 0 is interpreted as a true For example, the following lines of code will print both Hello and Goodbye if (1) printf( Hello \r\n ); if (9) printf( Goodbye \r\n ); if (0) printf( Hello \r\n ); if (1) printf( Goodbye \r\n ); 15 16 Examples of usage in programming: A = 0x09; B = 0x05; C = 0x01; if (A < B) C++; /* C++ is short form of C=C+1; */ else C=C<<2; If A were less than B, then C would be incremented by 1 (C=0x02), Since A is greater than B, C all of the bits in C are shifted to the left by 2 bits (C=0x04) C = 0000 0001 << 2 C = 0000 0100 = 0x04 Note: Values of added bits are always 0 Examples of usage in programming: A = 0x09; B = 0x05; C = 0x01; if (A == B) C+=3; /* C+=3; is short form of C=C+3; */ else C=~C; If A were equal to B, then 3 would be added to C C += 3; is same as C = C + 3; Since A is not equal to B, the ones complement is taken of C (C = 0xFE) ~C = ~(0000 0001) ~C = 1111 1110 = 0xFE Note: each bit is flipped 17 18

August 15, 2016 Examples of usage in programming: A = 0x09; B = 0x05; C = 0x00; (Using digital logic, the above variables may be considered as: A=true, B=true, C=false) D = A C; \\ Byte operation, E = A B; \\ Bit operation F = A && C; \\ Byte operation G = A & B; \\ Bit operation In this example, both D and F are single bit variables whereas E and G are byte variables D and F use LOGICAL operations: Note: 0 is false; 1 (or anything else) is true D: A is true, C is false, therefore, D is true F: A is true, C is false, therefore, F is false Truth Table: OR X Y = Q X Y Q 0 0 0 0 1 1 1 0 1 1 1 1 Truth Table: AND X & Y = Q X Y Q 0 0 0 0 1 0 1 0 0 1 1 1 Examples of usage in programming: A = 0x09; B = 0x05; C = 0x00; D = A C; \\ Byte operation E = A B; \\ Bit operation F = A && C; \\ Byte operation G = A & B; \\Bit operation E and G use BITWISE operations: 0000 1001 Conduct operation on 0000 0101 bits in each column E = 0000 1101 = 0x0D 0000 1001 & 0000 0101 G = 0000 0001 = 0x01 Truth Table: OR X Y = Q X Y Q 0 0 0 0 1 1 1 0 1 1 1 1 Truth Table: AND X & Y = Q X Y Q 0 0 0 0 1 0 1 0 0 1 1 1 19 20 Application to Microcontroller You can use these operators to read or change the state of a bit or groups of bits in an I/O port. Make pin 2 of Port 2 (P2.2) high and leave others as they were: P2 = P2 0x04; P2: XXXX XXXX (X can be 0 or 1) 0x04: 0000 0100 conduct a bitwise OR operation XXXX X1X X Alternate form of writing this: P2 = 0x04; Note: P2.2 is high, rest are unchanged Application to Microcontroller Another application testing the status on one or more input pins. Test if pin 4 of Port 3 (P3.4) is high or low: Statement if(p3) will check status of entire port If P3 = 0000 0000, statement is false; anything else is true To check one pin (P3.4), use: test = P3 & 0x10; P3: XXXX XXXX (X can be 0 or 1) 0x10: 0001 0000 conduct a bitwise AND operation test = 000X 0000 Note: just status of pin 4 is preserved test will be true if P3.4 was high, or false if it was low This is called bit-masking (the 0x10 is the mask value) 21 22

August 15, 2016 Lab 1-1 Overview Lab 1-2 Overview Lab 1 focuses on the hardware and the functions used to interface the hardware to the C8051 Lab 1-1 specifically introduces the use of digital inputs and outputs Acquire digital input from external source Use this to determine a digital output It is important to develop reusable code Use of functions in your programming GOAL: Control 2 LEDs and a buzzer with two switches Lab 1-2 presents the use of interrupts and the system timer Added components and code More switches Random number generator GOAL: Turn on a bi-color LED to red or green after a random delay. And then to measure a reaction time. Use timer overflows to control the delay length of the LEDS and to determine the reaction time. 23 24 Lab 2 Overview Preview Lab 1-1 Lab 2 focuses on the development of an interactive game using the hardware and the primitive functions developed in Lab 1. The completion of Lab 2 should give you enough experience to get started on the Smart Car and Gondola systems. Now, let s look further into the hardware aspects of the labs. Refer to the Sample code for Lab 1-1, available on LMS This code will control one LED with one switch You need to modify this code to control 2 LEDs and a buzzer with two switches (as described previously) Things to note as a review of C programming Include header files we need to include c8051_sdcc.h (website) Function prototypes note what is returned/passed Variable declarations must declare at beginning of function Use of indentation & brackets proper use is very helpful Function calls need () for functions, not variables 25 26

August 15, 2016 Pseudo-Code Homework 2 (see calendar due date) consists of 2 parts: Study provided Lab 1-1 Pseudo-Code and carefully note the structure and formatting Make syntax error corrections on a separate C file Pseudo-Code is an outline for the actual code. Read Lab 1, part 1 on LMS and compare the requirements to the Pseudo-Code to complete the lab. It is expected that this structure be followed all semester. Readability, Structure Indentation Sequence Pseudo Code, General Form compiler directives declare global variables function prototypes main function declare local variables initialization functions while (TRUE) get sensor information act on sensor information end while end main function 27 28 Pseudo Code, Subroutines function sensor_0 read and return appropriate value function sensor_1 read and return appropriate value function physical_action change system state Logic Worksheet Exercise!! Use this worksheet to test your knowledge of how bitwise and logical operators work. Work on this now Save the worksheet and put it in your lab notebook. What no lab notebook yet? Get one. One per group. Suggestion: Make choices that will keep your code simple and elegant. There is no single best answer. Refer to the provided pseudo code handout. 29 30

August 15, 2016 Finish Worksheet 2 Rest of Today Have your name checked off on HW1 list & Optionally submit HW1.c file on LMS Each individual should be able to upload the file on LMS, a hardcopy is only for your own use Before you leave Turn off power to the C8051 on car Save any changes to code Take all your possessions with you Before Next Class Finish reading all assigned chapters listed in Homework 1 Print out the Pseudocode for Lab 1-1 that has been provided to you on LMS Look it over and make sure you understand it This will be added to your Lab Notebook Use this template for the pseudocode assignments required for the rest of the labs this semester LMS: Lecture, Labs, & References>Laboratories & Worksheets>Lab 1>Pseudocode Specifications & Examples 31 32 Lecture #5 33