lecture04F - Lecture#4 September 5 2008 Announcements...

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: Lecture #4 September 5, 2008 Announcements Homework #3 Before Class Begins... Hand in Homework #3 Hard copy (one per team) turned in on center table Everybody submits an LMS soft copy (two per team) Ever You should have a lab notebook by now Get your Protoboard and a Toolbox Quiz 1 – next class Remember to submit a soft copy on WebCT Homework #4 on website – due next class Get your Protoboard and a Toolbox Thursday, September 16, Sections 1,2 16, Tuesday, September 14, Sections 3,4 14, Lab Manual available August 26, 2010 Lecture #4 1 August 26, 2010 Lecture #4 2 Quiz 1 Comments 40 Minutes; On RPILMS Open book, open notes, but NO old quiz copies, book open notes but NO old quiz copies NO other web pages except LMS Calculators OK Covera Coverage: number conversion, logic, pseudocode, and wiring Special Function Registers Review from last class 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: Input/Output Control (Configuring pins, A/D, …) Counting Timing Arithmetic operations, addressing, … August 26, 2010 Lecture #4 3 August 26, 2010 Lecture #4 5 1 Lecture #4 September 5, 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 August 26, 2010 Lecture #4 6 August 26, 2010 Lecture #4 7 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. Bitwise operations, example { P2 = 0x19; P2 |= 0xC1; P2 &= ~0x33; } // assignment operation // bitwise OR // bitwise AND 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. 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). P2 = 0x19 0xC1 = P2 |= 0xC1 0x33 = ~0x33 = P2 &= ~0x33 8 August 26, 2010 0 0 0 1 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 0 0 0 1 1 Since hardware configuration does not change in a typical application, these settings only need to be done once at the beginning of the code. August 26, 2010 Lecture #4 0 1 1 0 1 1 1 0 0 1 0 0 0 1 1 0 1 0 1 0 0 1 0 0 Lecture #4 9 2 Lecture #4 September 5, 2008 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. Sample Code, sbit Remember, we can use logic operations to change state of pin state of a pin Put these commands in a function that you will call at the beginning of the program void Port_Init(void) Port_Init(void) { P2MDOUT = 0x03; 0x03; /* Pins 0-1 push-pull, pins 2-7 open-drain */ Pins push pins open P2 |= 0xFC; /* Set pins 2-7 of P2*/ 2P3MDOUT = 0xF8; /* Pins 3-7 push-pull, pins 0-2 open-drain */ 3- push0- openP3 |= 0x07; /* Set pins 0-2 of P3 */ 0} August 26, 2010 Lecture #4 10 To turn on LED0 which is connected to P2.2 P2 &= ~0x04; // force P2.2 to go low The C8051 also has the ability to change the state of individual bits on certain ports sbit at 0xB4 LED0 ;/* LED0 associated with P3.4 */ LED0 = 0; /* Light LED0 */ Same can be done with input ports to read state of individual pins Lecture #4 11 August 26, 2010 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 PinPin-out Form – available on LMS Before implementing code and setting up th the hardware, determine the initialization th and EVB pin connections. Example: complete the pin-out form using the pinfollowing information P2.6 is a pushbutton input with an sbit label PB1 P2 is slide switch input with an sbit P2.7 is a slide switch input with an sbit label SS SS P3.2 is an LED output with an sbit label LED0 Note the location of pins 1 and 2 to see how they are sequenced. August 26, 2010 Lecture #4 12 August 26, 2010 Lecture #4 13 3 Lecture #4 September 5, 2008 Lab Check-Off CheckWhen you complete a lab assignment, you will need to demonstrate your lab to a TA IMPORTANT: Compiler Issues Remember NOTE: We NO LONGER require it to be a TA from your section! Both partners need to present Neatness of the wiring matters Lab Notebook needs to be completed to that point You will be asked questions from the Demonstration and Demonstration Verification section at end of lab as well as some additional questions questions quest Both partners need to know lab well CheckCheck-off procedure Do not use special characters in the file name ‘-’ and ‘_’ are OK, but NOT ‘#’ OK, Only use a single “.” in the name Save your program as a “.c” file • Questions will be directed towards both partners You will need to correct the problem And then request a new check-off checkLecture #4 14 August 26, 2010 Lecture #4 15 Failure of any of the above: • • August 26, 2010 Lab 1, part 1 Pseudo Code compiler directives declare global variables global variables function prototypes main function declare local variables initialization functions while (TRUE) read sensors set outputs for LED, buzzer and BILED end while end main function August 26, 2010 Lecture #4 16 Pseudo Code continued function initialize ports set ports 2 and 3 for input/output ports and for input/output function sensor0 read push button 1 and return appropriate value function sensor1 read push button 2 and return appropriate value function sensor3 read slide switch and return appropriate value function set outputs determine LED, buzzer and BILED states based on the four conditions August 26, 2010 Lecture #4 17 4 Lecture #4 September 5, 2008 Pseudo Code in general In general, there is no single best code implementation The pseudoThe pseudo-code should reflect your approach to solving the specified problem Finish Lab 1, part 1 Complete Pin-out form for Lab 1, part 1 Pin Include it in your notebook it Need to get checked off See Demonstration and Verification at end of Lab 1, part 1 description. IF YOU DON’T FINISH BY END OF CLASS Go to open shop to complete iit. t Get checked off in open shop Both partners must be present for check-off. checkAugust 26, 2010 Lecture #4 18 August 26, 2010 Lecture #4 19 5 ...
View Full Document

This note was uploaded on 04/08/2011 for the course ENGR 2350 taught by Professor Fukanari during the Spring '08 term at Rensselaer Polytechnic Institute.

Ask a homework question - tutors are online