DOC PREVIEW
SJSU ME 106 - OOPic Programming Fundamentals

This preview shows page 1-2-3-4-5 out of 16 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

OOPic Programming FundamentalsObject Oriented PicTypes (classes) of ObjectsCreating ObjectsCreating Objects, cont.Object PropertiesObject MethodsObject Method ExampleLinking Objects TogetherLinking Objects Together, cont.Slide 11Object Linking ExampleVC Graphical LayoutProceduresFunctionsEventsOOPic Programming Fundamentals•Compiled vs. Interpreted programs–Compiled program converts high level code into native machine language•e.g., y=x+5;•Machine language runs on the target•Done in levels•Cross-compiler  code program on one machine (PC) generate machine code for another machine (microcontroller)•Features–Fast–Interpreted program executes high level code on the machine that the interpreter is running on•Each line of code is interpreted and run each time each time the program is run•Fetch token from EEPROM  wait for fetch complete  decode token (objects that represent an action) locate native code associated with token  execute native code  advance EEPROM address•Features–Easier to write an interpreter than a compiler–SlowObject Oriented Pic•Object  conceptual approach allowing the programmer to interact with what appears to be a physical object–Grouping of code and data treated as a single unit•Like pre-written code libraries–Examples:•oFreq•oButton•oLCD•Why objects?–More intutive, faster to learn to use–Functionality built into the objects, so coding becomes mostly just manipulating objects (rather than reading and writing to memory locations)–Like having prewritten code libraries•Ex: PWM –“multitasking code” objects operate “continuously” rather than line-by-line–Can link objects togetherTypes (classes) of Objects•Hardware–Represents or encapsulates a physically implemented piece of hardware:•oDio1•oA2D10•Processing –Retrieves values from other objects, performs calculations, stores resulting value in another object•oMath•Variable –Stores a value and provides evaluation properties about that value •oByte•System–controls one of several system functions •oOOPicCreating Objects•Need to create an instance of the particular class of object–oA2D10 light_level = new oA2D10;•Identifier Names must begin with a letter•Identifier Names cannot contain a period.•Identifier Names must not exceed 32 characters.•Identifier Names must be unique within the application. (Identifier names are case insensitive)•The name of the Identifier is not stored in RAM and therefore can be any length (up to 32 characters) with out affecting the amount of RAM that gets allocated for the Identifier's instance–Not sensitive to case: Light_level = = liGHt_LeVEl–Creates an instance of an oA2D10 object (10 bit A/D)–Must be done at the beginning of the program–Allocates memory out of the free RAM to hold the instance of the Object, and is added to the Object list in the order defined•If object operation is time critical, place next to each other–86 bytes of object memory available (96 total, but OOPic object takes 10 bytes)•Don’t add object that you don’t need!•They will take up memory and operating time•Operating system steps through the object list and executes the defined properties of the objectCreating Objects, cont.•Can create arrays of objects by specifying a index value when the object is declared–Example of array of 3 A2D10 objects•oA2D10 light_level(3)= new oA2D10;–Access using index value:Z=light_level(1).value;•Some class of some objects have variable size–Example oGate (provides logic gate functions) with two inputs•oGate 2-input_OR = new oGate(2); //declare 2-input OR gate•oGate objects can have up to 8 inputsObject Properties•Properties are things that allow you to customize the characteristics of an object and determine the value an object holds. Some of the common ones:–Result•A value (number) the result of processing done by the object–Value•A value (number) specifying the state, content or magnitude of an Object–Flag•A value (number) that signals the beginning or end of an object process–String•Allow the value to be represented as a string–Operate•Turns the object on (enables it to respond to input changes)–It will hold the state of its last change until operate property set to 1 •Syntax to set:–object_name.Property=expression;–Ex. oA2D10 light_level = new oA2D10;light_level.IOLine = 1; // Map A2D10 object to A/D line 1light_level.Operate = cvTrue; // Enable A2D10 object•Syntax to determine the state of an object:–Variable=object_name.Property;Object Methods•Methods are actions that objects can performClear A command that instructs the Object to clear its Value property by setting all of its bits to 0. oBit, oBuffer, oByte, oDIO1, oDIO16, oDIO4, oDIO8,oNibble, oPWM, oRAM, oWord Data A command that instructs the oEEProm Object to store data in the EEProm. oEEProm Dec A command that instructs the Object's Value property to decrement by 1. oBuffer, oByte, oDIO16, oDIO4,oDIO8, oNibble, oPWM, oRAM, oWord Inc A command that instructs the Object's Value property to increment by 1. oBuffer, oByte, oDIO16, oDIO4,oDIO8, oNibble, oPWM, oRAM, oWord Invert A command that instructs the Object to invert the binary value of its bits. oBit, oBuffer, oByte, oDIO1,oDIO16, oDIO4, oDIO8,oNibble, oRAM, oWord LShift A command that instructs the Object to shift the bits in its Value property left. oBuffer, oByte, oDIO16, oDIO4,oDIO8, oNibble, oPWM, oRAM, oWord RShift A command that instructs the Object to shift the bits in its Value property right. oBuffer, oByte, oDIO16, oDIO4,oDIO8, oNibble, oPWM, oRAM, oWord Set A command that instructs the Object to 'set' its Value property by setting all of its bits to 1. oBit, oBuffer, oByte, oDIO1,oDIO16, oDIO4, oDIO8,oNibble, oPWM, oRAM, oWordObject Method ExampleoDio4 Nib1 = new oDio4;oDio4 Nib2 = new oDio4;Const num1 = 1; // Defines the constant “num1” equal to 1Sub void Main (void)Nib1.IOGroup = 1; //IO lines 8-15Nib1.Nibble = 0; //IO lines 8-11 (the lower 4 bits)Nib1.Direction = cvInput; // Digital inputs (cvInput = = 1)Nib2.IOGroup = 1; //IO lines 8-15Nib2.Nibble = 1; //IO lines 12-15 (the upper 4 bits)Nib2.Direction = 0; // Digital outputs (cvOutput = = 0)Nib2.Value = Nib1.Invert; //Nib1 bits are inverted and sent out Nib2Nib2 = Nib1.LShift; //Nib1 bits are shifted left and sent out Nib2Linking Objects Together•Virtual Circuit is a way to link objects together so that


View Full Document

SJSU ME 106 - OOPic Programming Fundamentals

Download OOPic Programming Fundamentals
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view OOPic Programming Fundamentals and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view OOPic Programming Fundamentals 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?