Unformatted text preview:

Example buttons boxOBJECTIVEprogramsProgram Buttons_bxFlowchart and codeexecutionWhat you have learnedEMCH 367 Fundamentals of Microcontrollers Example BUTTONS BOX EXAMPLE BUTTONS BOXOBJECTIVEThis example has the following objectives:- Review the use of parallel ports- Illustrate the use of Port C for input and output- Introduce the concept of shifting register and memory content- Practice the use of the THRSim11 IO box for input and outputPROGRAMS This example demonstrates the use of Port B for output and of Port C for both input and output. Port Cis configured to have the even pins PC0, PC2, PC4, PC6 for output. This is achieved using the DataDirection Register for port C (DDRC). Since the default setting for Port C is input, the pins that have tobe set to output have their image set to 1 in DDRC. In our case, the bits 0, 2, 4, and 6 of DDRC are setto 1. Thus, the Port C pins PC0, PC2, PC4, PC6 become output, while pins PC1, PC3, PC5, PC7remain input.The program loops continuously, reading data from some Port C pins, and sending data back to theother Port C pins. Simultaneously, the data is also sent to Port B.PROGRAM BUTTONS_BXInstructions(i) Load REGBAS in reg. X(ii) Clear port B by storing zeroin itSelect odd Port C pins for output(iii) Load %01010101 in accA(iv) Store accA to DDRCMain loop(v) Load Port C to accA(vi) Shift accA to the right(vii) Store accA to Port C andPort B(viii) Branch back to (v)(ix) SWIFlowchartPlease fill in yourselfCodeSTART LDX #REGBAS* Begin typing your code* Clear Port BLDAA #%00000000STAA PORTB,X* Select PC0, PC2, PC4, PC6 foroutputLDAA #%01010101STAA DDRC,X* Main loopBEGIN LDAA PORTC,XLSRA* STAA PORTC,XSTAA PORTB,XBRA BEGINSWIFLOWCHART AND CODEThe program flowchart is not provided, since is simpler than in previous examples. The students areencouraged to use the space provided for filling in their own flowcharts of the program. The essentialDr. Victor Giurgiutiu Page 11/14/2019EMCH 367 Fundamentals of Microcontrollers Example BUTTONS BOX code for this program is shown to the right of the flowchart. The file Buttons_bx.asm is the result ofincorporating this code in the standard template.EXECUTIONOpen THRSim11. Close the Commands window. Open port registers, and THRSim11 IO box. Openand assemble Buttons_bx.asm. Set breakpoint, and reset registers. Set standard labels (Label/SetStandard Labels). Set display of accA to binary. Set display of PORTB and PORTC to binary. Tilewindows. Arrange windows for maximum benefit. Your screen should look like this:a) Before you run the program, verify the Port C pins functionality. In the THRSim11 IO box, toggleup the switch PC3. You will see that the corresponding bit in Port C register, bit 3, becomes 1immediately. Your screen looks like this:Dr. Victor Giurgiutiu Page 21/14/2019EMCH 367 Fundamentals of Microcontrollers Example BUTTONS BOX b) Toggle down the switch PC3 in the IO box.c) Run the program. The program will loop continuously between label BEGIN and opcode BRA.d) With the program running, toggle up the switch PC3 in the IO box. Immediately, bit 3 in PORTCwill switch to one. Simultaneously, pin 2 in PORTB will become 1, and the light PB2 in the IObox will lit. Press the stop button and capture the screen. Your screen should look like this:Dr. Victor Giurgiutiu Page 31/14/2019EMCH 367 Fundamentals of Microcontrollers Example BUTTONS BOX e) Try to toggle other PC switches in the IO box. You will notice that now only the odd switches(PC1, PC3, PC5, PC7) are producing the setting of the corresponding bits in PORTC register.The other switches (PC0, PC2, PC4, PC6) can be toggled, but with no effect on the PORTCregister. This illustrates how DDRC controls PORTC register.f) Restart the program by pressing the Run button. With the program running, try to toggle theother switches. You will notice that the toggling of the odd switches (PC1, PC3, PC5, PC7) hasthe effect of switching on the even Port B lights (PB0, PB2, PB4, PB6). This is the result of thedata from the odd Port C pins is loaded in accA, right shifted, and sent back to Port B. WHAT YOU HAVE LEARNEDIn this example, you have learned:- The use of PORTC for input and output- The concept of shifting a register- The use of the THRSim11 IO box for both input and output- New words and expressions: toggle switch; shift a register, shift data.Dr. Victor Giurgiutiu Page 41/14/2019EMCH 367 Fundamentals of Microcontrollers Example BUTTONS BOX-Dr. Victor Giurgiutiu Page 1


View Full Document

SC EMCH 367 - EMCH 367 Example Buttons Box

Download EMCH 367 Example Buttons Box
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 EMCH 367 Example Buttons Box 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 EMCH 367 Example Buttons Box 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?