lecture03F - Announcements Hand in Homework#2 – Hard copy...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: January 22, 2008 Announcements Hand in Homework #2 – Hard copy on table, one per pair. Outline for Today SignSign-out Procedures of Tools and Hardware Hardware for switches and LEDS Submit a soft copy using RPILMS, everybody (not one per pair.) Log onto the course LMS site • Online Assignments • Homework 2 • Upload your file • Submit – Important to remember to do this. Everybody must submit, but pairs of students should submit exact copies. Add the hard copy to your notebook after it is graded by TA Switches are inputs, LEDs are used for Output Quiz 1 – next week (Thu Sept 16, sections 1,2; Tue Sept 14 (Thu 16, sections 3,4) 40 minutes; Open book, open notes No web pages, no past quizzes, no sharing, calculators allowed Coverage: Coverage: number conversion, logic, pseudocode, and wiring Homework #3 on website: C code for Lab 1, part 1. Due by beginning of next class Worksheet #3 is on RPILMS REMINDER: No food or drink in the lab! January 22, 2008 Lecture #3 2 Worksheet #3 C8051 Ports & Special Function Registers Ports Special Function Registers Lab 1, part 1 January 22, 2008 Lecture #3 3 Teaching Assistants Grading Grading TAs: Lab Equipment & Procedures You will need to check out one toolbox per team each day of lab. Side A (podium left) • Side B (podium right) • Toolboxes are located in cabinets on both sides of the lab. lab. A TA will not need to check the box before and after you use it but you must be responsible for all items. We will need to hold your student ID or some other form of ID until you return the box if there are abuses. Helping TAs: • • Students must be Students must be accountable accountable when accessing this cabinet! January 22, 2008 Lecture #3 4 January 22, 2008 Lecture #3 5 1 January 22, 2008 Lab Equipment & Procedures Wire for your project can be found in the spare wire box and on the spools Lab Equipment & Procedures Each group will be assigned a protoboard Please put your name on the bottom of it th Pl Please use the spare wire in the box before using th new wire from the spools Less cutting, less waste, less cost Remember: red wires for 5V pwr, black wires for 0V gnd pwr, At end of lab, return it to the corresponding numbered location in At end of lab, return it to the corresponding numbered location in cabinets cabinets – REMEMBER THIS NUMBER Write the number of your protoboard on the inside cover of your lab notebook Cabinets located on each side of the lab Unless told otherwise, keep the circuit on the protoboard when you store your equipment at the end of class January 22, 2008 Lecture #3 6 January 22, 2008 Lecture #3 7 Lab Equipment & Procedures Each group will be assigned a bag of chips and components components. These can be left with the protoboard or taken home (don’t damage or forget to bring it to class). Lab Equipment & Procedures Not all components are in your bag LED LEDs, resistors, and some other components can be found in the trays on the center table January 22, 2008 Lecture #3 8 January 22, 2008 Lecture #3 9 2 January 22, 2008 Lab Equipment & Procedures Clean up your station before leaving lab! Preparing for Hardware Take a few minutes and perform the following tasks: Don’t just wipe wires on floor! on floor! Turn off power on car. Remember: no food or drink allowed in lab! One student – sign out a toolbox Partner – get a protoboard and bag of parts Understand the protoboard nodes Mount the protoboard on the car the protoboard on the car Connect the ribbon cable to the protoboard January 22, 2008 Lecture #3 10 January 22, 2008 Lecture #3 11 SiLabs Compiler Setting Lab Equipment & Procedures Both partners should have a copy of your code code Open SiLabs Under the “Projects” tab, click on ‘Tool Chain th “P ‘T Ch Integration’ Open the “Compiler” tab Under the text box for ‘Command Line Flags’, add the following --nogcse --nogcse Make sure you don’t erase the existing flags Make sure you both have a copy at end of each day • One partner may be late/sick/gone next class Homework needs to be submitted on WebCT If equipment is broken inform TA so it If equipment is broken, inform a TA so it can can get fixed, replaced, or repaired This setting corrects an SDCC compiler error that exists when creating while loops January 22, 2008 Lecture #3 12 Please be careful, only limited supplies and some equipment is custom built Lecture #3 13 January 22, 2008 3 January 22, 2008 Wiring Rules Power/Ground and color convention Help Procedures TAs there to help you Be aware there are only aware there are only four or five TAs in the room with up to 70 students All connections to power (+5V) use red wire All connections to power (+5V) use red wire All connections to ground use black wire Do not use red or black wires for any other connections Wire around them Easier to debug No wires over chips We are limited Use tight wiring Trim leads of resistors & LEDs January 22, 2008 Lecture #3 14 Try to use the resources available & troubletroubleshoot on your own first, then ask a TA if you cannot solve the problem If TAs and professor are busy, please wait patiently January 22, 2008 Lecture #3 15 Help Procedures There are also Open Shop hours posted in the lab and on-line on Lab 1-1 Overview 1Lab 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 1inputs and outputs The schedule is posted on the pillar in the center of The schedule is posted on the pillar in the center of the the room TAs will be in the lab at those times to help if necessary Acquire digital input from external source Use this to determine a digital output Use of functions in your programming of functions in your programming It is important to develop reusable code GOAL: Control 2 LEDs and a buzzer with two switches January 22, 2008 Lecture #3 16 January 22, 2008 Lecture #3 17 4 January 22, 2008 Common Digital Gates Inverter X Q Common Digital Gates AND X Y Q 7404 X 0 1 Q 1 0 X 0 0 1 1 Y 0 1 0 1 Y 0 1 0 1 Q 0 0 0 1 Q 1 1 1 0 7408 Buffer Buffer X Q X 0 1 Q 0 1 7407 7465 NAND NAND Q 0 1 1 1 18 18 X Y Q OR X Y 7432 Q X 0 0 1 1 Y 0 1 0 1 7400 X 0 0 1 1 There are many, many other digital circuits, but these are the common ones we will use. January 22, 2008 Lecture #3 January 22, 2008 Lecture #3 19 19 Hardware Hardware Components Refer to the components when discussing the following slides following slides Buffer chips LEDs Pushbuttons Slide switches Note: voltage inputs/outputs corresponding to ‘On/Off’ are not necessarily ‘0/5 [V]’ Chip Numbering On the physical chip, the pin numbers are arranged pin numbers are arranged from from the top-left around topthe chip in a countercounterclockwise (CCW) direction. The top-left is found by toplocating the small dot or notch on the chip. 20 January 22, 2008 Lecture #3 SN74LS05N 1 VCC 14 13 1 2 6 3 12 2 4 11 5 5 10 3 6 9 4 7 GND 8 Circuit examples Lecture #3 8/26/2010 21 5 January 22, 2008 Resistors & Potentiometers Example of a resistor component: LightLight-Emitting Diodes LEDs are common components that provide visible indication of digital provide a visible indication of a digital output. output. Diodes only allow current to flow through in one direction. Physical appearance Electrical symbol Resistance value is indicated by the colored bars. Resistor color codes can be found in Appendix C of the lab manual and on the poster on center column in the lab. January 22, 2008 Lecture #3 22 From the cathode to the anode Must be a potential drop across it to emit light it li Current (i) January 22, 2008 Lecture #3 23 Application in Circuit Connect an LED and resistor in series Switches Different types of switches can provide di digital input to the microprocessor. th Choose resistor to limit Choose resistor to limit current in LED to rated value in LED to rated • i<=10 mA Can use an output pin on microcontroller to turn on/off Power +5V Current (i) Power +5V Ground 0V Logic High – no current flow Logic Low – current flow Use buffer gate to protect microcontroller (acts as a current sink) January 22, 2008 Lecture #3 24 Pushbuttons provide different status only when pressed. Slide switches can be placed in either status. common January 22, 2008 Lecture #3 25 6 January 22, 2008 Application in Circuit Connect a switch and resistor in series Hardware Wiring and Testing Additional items in open supply in the Parts Drawers on the table in the middle of the room. Resistor limits current and provides a voltage drop limits current and provides voltage drop When open circuit, no current flow, no voltage drop across resistor, therefore reading +5V at point A When closed circuit, current flows, voltage drops across resistor, therefore reading 0V at point A Microcontroller can read the status at this point A - Voltage at this point w.r.t. ground is: High when not pressed (no current) when not pressed (no current Low when pressed Power +5V Current (i) only when pressed Ground 0V Lecture #3 26 Wire, Resistors Some special items like LEDs Read the schematic. Plan the circuit layout on the protoboard. Connect wires and check. Remember to connect power and ground to the chip. Turn on power. Verify correct function. Debug if necessary with logic probe. Enter procedure and results in Lab Notebook procedure and results in Lab Notebook Show TA the result. Save your work for Lab 1, part 1. Lecture restarts in 30 minutes January 22, 2008 January 22, 2008 Lecture #3 27 Lab 1, part 1 Objectives Your program for Lab 1, part 1 should: Lab 1, part 1 Representation Switches (pushbutton, slide switch) When the Slide switch is off (input is HIGH voltage) LED0 is When the Slide switch is ‘off’ (input is a HIGH voltage), LED0 is on, on, all other output devices are off When the Slide switch is ‘on’ and both Pushbuttons are pushed, the Buzzer is turned on When the Slide switch is ‘on’ and only Pushbutton 1 is pushed, the BiLED is green When the Slide switch is ‘on’ and only Pushbutton 2 is pushed, the BiLED red the BiLED is redprint LED and buzzer status to the screen LED and buzzer status to the screen Print button and switch states to the SecureCRT window Input Port 2 & 3 C code C8051 Controller Port 3 Output buzzer LED0 BicolorLED See Tutorials website for helpful info. January 22, 2008 Lecture #3 28 January 22, 2008 Lecture #3 29 7 January 22, 2008 Lab 1, part 1 Schematic Inputs Why do we need inputs? We want to send some type of information to the system. Digital (True/False, 1/0, High/Low, +5V/0V) High for the C8051 microcontroller is ~3V, while logic gates need ~5V What type of signals can we send? Analog (variable voltage) January 22, 2008 Lecture #3 30 January 22, 2008 Lecture #3 31 31 Creating Digital Inputs The Goal: Communicate information to the microcontroller microcontroller. The Approach: Force an input line to a TRUE or FALSE condition. Recommended practice: Make the input line either high or low at all times — do not let input lines float lines float. Creating Digital Inputs The usual implementation: Vcc To input pin R Floating lines create the possibility of ambiguous information at best, and undesirable information at worst. Lecture #3 32 January 22, 2008 Lecture #3 33 January 22, 2008 8 January 22, 2008 Ports Ports are sets of connections on the microcontroller C8051F020 Block Diagram (pg 18) (pg They are used to communicate with the external circuitry (input/output) We will only use Ports P0, P1, P2, and P3 will only use Ports P0, P1, P2, and P3 Ports 0 – 7 January 22, 2008 Lecture #3 35 The C8051 has 7 ports, P0, P1, … P7 The C8051 manual lists Ports and the use of their pins January 22, 2008 Lecture #3 34 Using Ports These input and output pins can be connected to wires where signals are produced Special Function Registers A Special Function Register (SFR) is a SFR) microprocessor feature capable of receiving microprocessor feature capable of receiving information, information, holding it, and transferring it. SFRs are used in the C8051 for: Either a sensor will detect something and send a signal to the microcontroller or the microcontroller will send out a signal to control a hardware feature We will show you where you can make these connections using a prototyping board (commonly called a protoboard or bread board) We need way to read the signals on these We need a way to read the signals on these pins, pins, send signals out these pins, and configure the system to know which way the system is wired (input or output) January 22, 2008 Lecture #3 36 Input/Output Control (Configuring pins, A/D, …) Counting Timing Arithmetic operations, addressing, … January 22, 2008 Lecture #3 37 9 January 22, 2008 Special Function Registers C8051 SFRs are listed in the header file: c8051F020.h 8051F020 SFRs have a size of 1 byte (8 bits) The SFRs look like memory locations to the software Bit Identification (One Byte) 7 6 5 4 3 2 1 0 Special Function Registers, Ports & Communication Each I/O port has a SFR associated with it Example: P2 is the SFR associated with Port 2 P2 th SFR 8-bit register where each bit is associated with a specific pin of Port 2 (C8051 manual pg 175) (C8051 January 22, 2008 Lecture #3 38 January 22, 2008 Lecture #3 39 Special Function Registers, Ports & Communication Using Port 2 as an example: More Examples of SFRs Input/Output Port SFR Th The software communicates with the pins of th Port Port 2 by using SFR P2 • Input example: the current value (status of all 8 bits) can be used to give a variable, input, a value: input, input = P2; /* read PORT 2 */ • Output example: the 8 pins of Port 2 can be assigned a value: P2 = 0x30; /* write to PORT 2*/ P0 P1MDOUT – output mode for P1 ADC1CN con ADC1CN – control of analog to digital di converter converter Configuration Control The hardware communicates by connecting wires to the pins of Port 2 Lecture #3 40 January 22, 2008 Lecture #3 41 January 22, 2008 10 January 22, 2008 Application of SFRs Example: In the case of I/O ports, we need to input settings into some SFRs to SFR determine how we will use the port. Configuration of Port 3 Output Mode The eight lines of Port 3 can be individually configured as push-pull (output) or open-drain (input). ushenWe set the configuration for each line through the special function register P3MDOUT Writing a 0 to a bit sets the corresponding pin of Port 3 to open drain; writing a 1 to a bit sets the corresponding pin of Port 3 to push-pull. push Example: P3MDOUT = 0x0F; P3MDOUT /* Pins 0-3 push-pull, 0- pushpins 4-7 open-drain */ 4- open- I/O Ports can be set to operate in different modes by switching transistors on and off January 22, 2008 Lecture #3 42 January 22, 2008 Lecture #3 (C8051 manual pg 176) 43 43 Configuring I/O Pins When using P0-P3 for digitial output, set the bits in the P0output, corresponding output mode SFR for push-pull. ush- ull. Configuring I/O Ports Here is an example using pins 2-7 of Port 2 and pins 0-2 20of Port 3 for digital input and pins 0-1 of P2 and 3-7 of P3 03for digital output. Data can then be sent to the pins with the Port SFR When using P0-P3 for digital input, set the bits in the P0input, corresponding output mode SFR for open-drain. open-drain. Put these commands in a function that you will call at the beginning of the program Additionally, you need to send a high value to those pins using the port SFR. Note: Port 1 can also be used for analog input, so additional settings need to be made in the P1MDIN SFR to set it for digital or analog input (C8051 manual pg 174). Since hardware configuration does not change in a typical application, these settings only need to be done once at the beginning of the code. January 22, 2008 Lecture #3 44 44 void Port_Init(void) Port_Init(void) { P2MDOUT = 0x03; 0x03; P2 |= 0xFC; P3MDOUT = 0xF8; P3 |= 0x07; } January 22, 2008 /* Pins 0-1 push-pull, pins 2-7 open-drain */ Pins push pins open /* Set pins 2-7 of P2*/ 2/* Pins 3-7 push-pull, pins 0-2 open-drain */ 3- push0- open/* Set pins 0-2 of P3 */ 0- Lecture #3 45 11 January 22, 2008 C Program for Lab 1, part 1 See Lab Manual Appendix E for some sample code that can be applied to this th thi project. As we look over this example now, think of these questions: Sample Code Lets refer to the Sample code given at the end of Lab 1, part 1 in your lab manual. How can this be applied in this project? can this be applied in this project? What modifications and additions need to be made to meet our goals? Lecture #3 46 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) (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 Lecture #3 47 January 22, 2008 January 22, 2008 Sample Code Remember, we can use logic operations to change state of a pin, if P2.2 is connected to LED0 state of pin if P2 is connected to LED0 Reading & Writing to Bits & Ports When should you use sbit? sbit? To turn on LED0, force P2.2 to go low P2 &= ~0x04; The C8051 also has the ability to change the state of individual bits on certain ports sbit at 0xB4 LED0 ;/* LED0 associated with P2.2 */ LED0 = 0; /* Light LED0 */ Same can be done with input ports to read state of individual pins Lecture #3 48 If you want to read or change the state of one or two individual bits of a port, using the sbit command can be very efficient. If you want to read or change the state of multiple pins, it is recommended that you use th the port register. • Example: To make bits 3-7 of Port 2 low: 3P2 = P2 & 0x07; or P2 &= 0x07; or P2 January 22, 2008 January 22, 2008 Lecture #3 49 12 January 22, 2008 PinPin-out Form Before implementing code and setting up th the hardware, determine the initialization th and EVB pin connections. The pin-out form is available on LMS pin Lab Check-Off CheckWhen you complete a lab assignment, you will need to demonstrate your lab to TA need to demonstrate your lab to a TA CheckCheck-off procedure Complete the pin-out form using the following pininformation • P2.6 is a pushbutton input with an sbit label PB1 • P2.7 is a slide switch input with an sbit label SS • P3.2 is an LED output with an sbit label LED0 TAs/Prof from any section may check you off Both partners need to present Lab Notebook needs to be completed to that point You will be asked questions from the Demonstration Demonstration and Verification section at end of lab as well as some additional questions Both partners need to know lab well • Questions will be directed towards both partners Lecture #3 51 January 22, 2008 Lecture #3 50 January 22, 2008 Lab Notebooks Don’t forget to keep your lab notebooks up- oup-to-date! Good Communication Inform TAs of any partner changes over next week. After that, you will remain Aft th partners for rest of semester You will receive email updates from your grading TA Details in Lab Manual Appendix B Part of lab check-off procedure check- Be sure to check your email sure to check your email Thank you for your help in making this course run smoothly January 22, 2008 Lecture #3 52 January 22, 2008 Lecture #3 53 13 January 22, 2008 Connections to the Microcontroller Each protoboard has an EVB Port Connector see back cover of lab manual Connector, see back cover of lab manual and and pin sheet For example, hardware connects to Port 3 by using pins 31-38. 31Review the numbering scheme on the protoboard connector block to EVB. bl EVB Additional Hardware Notes Note: LEDs will only turn on for forward current flow. Reverse connections if they fl if th do not light. See lab manual. Slide protoboards into the slots on top of the car above EVB. This will ensure proper connection of the ribbon cable. connection of the ribbon cable. Note the location of pins 1 and 2 to see how they are sequenced. Lecture #3 54 Brown edge of cable should be at “low number” end of pin connector. January 22, 2008 January 22, 2008 Lecture #3 55 Quiz 1 RPILMS – bring your laptop Coverage Worksheet #3 To prepare for Lab 1, we will begin with a short activity to setup and test the hardware activity to setup and test the hardware. This activity uses hardware similar to Lab 1, part 1, but without the microprocessor control. One switch activates an LED and one activates a buzzer. This circuit can be used as the basis the circuitry This for Lab 1 (note the similarities). Logic – review worksheet 2 Pseudo Code • Indent for loops • Must logically work logically work Number conversion – review worksheet 1 Wiring – example next class Lecture #3 56 Use proper wiring conventions (neatness, wire color) Don’t disassemble it when finished! Lecture #3 57 57 January 22, 2008 January 22, 2008 14 January 22, 2008 Next Class Homework #3 due Lab 1, part 1 check-off Before you leave Return your protoboard to cabinet slot that matches number on protoboard. Parts bags may be left with protoboard. Have TA check in your toolbox. January 22, 2008 Lecture #3 58 15 ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online