Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560.

Similar presentations


Presentation on theme: "ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560."— Presentation transcript:

1 ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

2 Digital I/O on the 430 Digital input and output Modify the routine to vary the time on/off of each led in oscillation Allow toggle on input from push button ECE 3561 - Lecture 1 2

3 There is a MSP 430 wiki page There is a Launch Pad wiki page http://processors.wiki.ti.com/index.php/MSP 430_LaunchPad_(MSP-EXP430G2) ECE 3561 - Lecture 1 3

4 Modifying the blink rate We can create two memory locations that modify the blink rate of the LEDs. This will be done in real time in class. ECE 3561 - Lecture 1 4

5 Digital input The launch pad has one input available to the user. It is at P1.3 It is a momentary push button switch. The code can be modified to turn the light on when this switch is pressed. Note: There is another momentary push button switch – it is a hard reset. ECE 3561 - Lecture 1 5

6 Configure the port The port configuration must be modified to set that pin as an input. It is pin 3 of Port 1 Need to set the value in the P1DIR to xxxx 0xxx To read the value on this switch. When combined with output configuration for the LEDs it give a value of 1xxx 0x1x to be written to P1DIR ECE 3561 - Lecture 1 6

7 The code for setting it up Setting the port to read the input switch. Set unused pins to output mov.b #0xF7&P1DIR ;dir register mov.b #0x00,&P1IE;disable int mov.b #0x00,&P1SEL ;all pins I/O mov.b #0x00,&P1OUT ;LEDs off mov.b P1IN,R6 ;read input mov.b P1IN,R6 ECE 3561 - Lecture 1 7

8 Consider code in CCS For some reason the switch does not seemed not to work. But it should. Then it was realized The DIRection register should be 1111 0111 or $F7 not $FB This is a note slide to show how easy it is to make minor errors that result in errors. Time to revisit and just work with the bit instruction. ECE 3561 - Lecture 1 8

9 General scheme to configure To configure – Two alternatives Configure all bits in the control register Configure only the bit you desire to set ECE 3561 - Lecture 1 9

10 The flow of control The diagram show the relationships ECE 3561 - Lecture 1 10

11 Using diagram The steps to configure pull up First set bit in SEL register to 0 – Digital I/O The set DIR register to 0 – Input From here you configure if you want interrupts (later) – 0 disable for now Also, PxREN – internal pull- up 0 – disabled 1 – enable PxOUT 0 for a pull down 1 for a pull up ECE 3561 - Lecture 1 11

12 What is a pull up Port pin can have an internal pull up Possible switch circuits SPDT –Single Pole Double Throw – issue here is that during transition the input is floating. Often see these as DPDT and used in automotive window up/down switch. ECE 3561 - Lecture 1 12

13 Switch on input Use a SPST – Single pole single throw Have a connection to Vdd through a limiting resistor. When switch is open Input is at Vdd When switch is closed Input is drawn to ground. Limiting resistor limits current to a low value when closed as there is a path Vdd to GND ECE 3561 - Lecture 1 13

14 Typical values for pull up Typical values 5V system so Vdd = 5V Often a pullup resistor of 290Ω or 330Ω is used. So current is 0.017 Amp or 17 mA (15mA) In 3.3V system – 11 mA (10 mA) When switch is closed this is the current that flows through the resistor. ECE 3561 - Lecture 1 14

15 The code to just set that pin Use bit set and bit clear instruction Will do this for Port 1 pin 3 which is the pushbutton switch – a SPST momentary bic.b#0x08,&P1SEL ;I/O bic.b#0x08,&P1DIR;Output bis.b#0x08,,&P1REN;Resistor bis.b#0x08,&P1OUT;Pullup bic.b#0x08,&P1IE;Disable mov.b&P1IN,R6;get value ECE 3561 - Lecture 1 15

16 Could be done using bytes This also could have been set using the mov.b instruction. The first attempt with the byte mov instruction failed due to the bit being set wrong in P1OUT so the resistor was a pull down. ECE 3561 - Lecture 1 16

17 Good code for bytes mov.b #0x00,&P1SEL;set I/O mov.b #0xF7,&P1DIR;in/out set mov.b #0x08,&P1REN ;res enable mov.b #0x08,&P1OUT ;pullup mov.b #0x00,&P1IE;disable int mov #P1IN,R6 ;read port to R6 mov.b @R6,R7;get val mov.b @R6,R7 Can see this work in demo ECE 3561 - Lecture 1 17

18 Now change light blink code Set up code in iodemo2 for One loop has fast blinking lights-stitch pressed – value is 1 Other has slower blinking lights – switch released – value is 0 How to tell? Use bit – bit test instruction bit #0x08,&P1IN Does a logical and of src,dst so if = 0, switch not pressed, if =1 switch pressed Use JEQ instruction – if Z=0 no jump and code for slower ECE 3561 - Lecture 1 18

19 And to watch a code demo Note the code running on the 430 The code for iodemo and iodemo2 is on the webpage. Play with iodemo2 to add code such the blink rate is one rate when the switch is pressed and another when released. ECE 3561 - Lecture 1 19

20 Now we can modify We can now modify our led program to change the blinking frequency when we press the switch. File iodemo.asm has core of the code. And a modification is in iodemo2.asm ECE 3561 - Lecture 1 20

21 ECE 3561 - Lecture 1 21 Summary - Assignment Try out the code Add an inner loop to lengthen the time for each individual light. No new assignment.


Download ppt "ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560."

Similar presentations


Ads by Google