Home

Digital Computers ECE-222 Lab manual

image

Contents

1. Submission Statement We I are am submitting this report for grading in 222 We I certify that this report including any code descriptions flowcharts etc that are part of the submission were written by us me and have received no prior academic credit at this university or any other institution The penalty for copying or plagiarism will be a grade of zero 0 Member 1 Member 2 Name Name UW ID NOT student UW ID NOT student Signature Signature Note Reports submitted without a signed submission statement will receive a grade of zero 0 Weight Grade Comment Part l Pre lab 10 Part ll Lab completion 30 Lab demo Questions 30 Part lll Code quality 20 Lab report Code comments 10 Total 100 22 Lab 3 Input Output Interfacing Objective The objective of this lab is to learn how to use peripherals connected to a microprocessor The ARM CPU is connected to the outside world using Ports and in this lab you will setup and use Input and Output ports What you do In this lab you will measure how fast a user responds to an event accurate to a 10 of a millisecond Initially all LEDs are off and after a random amount of time between 2 to 10 seconds one LED turns on and then the user presses the push button Between Turning the LED on and Pressing the push button a 32 bit counter is incremented every 10
2. 54 N c D ENET MDIO PLI7 R67 OR MCBI760 only P1 16 ENET MDC R70 MCB1760 only PL4 PLS P1 14 7 2 P19 PLI0 TOR C75 100n 100n 100n GND GND GND DP83848CVV OSCI GNDal 1 26 LED ACT 27 28 LED UNK IND 24 RT 4k87 1 L23 C70 10u m C71 100n P C7 1 R7 2k2 gt ORE aa T 1 22V LM386M 1 50MHz T3 33V R59 2k2 LED LINK LED ACT 300 0065 3 3V R60 612862 2k2 TORTIOR a MCB1700 gt Revision 1 2 Ethernet Spk SchDoc Size Ad Sheet 6 of 6 An ARM Company Date 29 7 2009 Web www keil com MCB1700 i 3 4 References 1 LPC17xx User manual Literature number UM10360 Rev 2 August 19 2010 Published by NXP Can be accessed online http www nxp com documents user manual UM10360 pdf Accessed on June 18 2012 2 Getting Started Creating Applications with uVision 4 Published by Keil Can be accessed online http www keil com product brochures uv4 pdf Accessed on June 18 2012 3 ECE 455 Lab manual Bernie Roehl E amp CE Department University of Waterloo Can be accessed online https ece uwaterloo ca ece455 lab manual pdf Accessed on June 18 2012 4 Schematic Diagram for the MCB1700 board Published by Keil Can be accessed online http www keil com mcb1700 mcb1700 schematics pdf
3. 45 10 pin has neither pull up nor pull down 11 Pin has a pull down resistor enabled For more information refer to Appendix A or tables 87 93 of the LPC17xx User manual 1 Table D 5 Register Description Table Note All registers are R W access and have a reset value of 0 Name Description PORTn Register Name and Address FIODIR Port Direction Control Reg FIOODIR 0x2009 C000 FIO1DIR 0x2009 C020 FIO2DIR 0x2009 C040 FIO3DIR 0x2009 C060 FI04DIR 0x2009 C080 FIOMASK Mask register for R W set and clears not used in ECE 222 A one masks or blocks access to a pin FIOOMASK 0x2009 C010 FIO1MASK 0x2009 C030 FIO2MASK 0x2009 C050 FIO3MASK 0x2009 C070 FI04MASK 0x2009 C090 FIOPIN Read IO Pin value and mask AND it with the inverted FIOMASK value FIOOPIN 0x2009 C014 FIO1PIN 0x2009 C034 FIO2PIN 0x2009 C054 FIO3PIN 0x2009 C074 FI04PIN 0x2009 C094 FIOSET Set a pin by writing a 1 to register Writing O has no effect on the IO pin The FIOMASK can prevent setting outputs FIOOSET 0x2009 C018 FIO1SET 0x2009 C038 FIO2SET 0x2009 C058 FIO3SET 0x2009 C078 FIOASET 0x2009 C098 FIOCLR Clear a pin by writing a 1 to register FIOOCLR 0x2009 CO1C FIO1CLR 0x2009 C03C FIO2CLR 0x2009 5 FIO3CLR 0x2009 7 FIOACLR 0x2009 CO9C Schematic diagram A ful
4. MOV R4 HOxXDEF Loading DEF into R4 MOV R5 0x0 Loading R5 with zeros Swapping the values in RO and R1 R5 is used as temporary buffer MOV R5 RO R5 content of RO is stored in R5 MOV RO R1 RO lt R1 content of R1 is stored in RO MOV R1 R5 R1 lt R5 content of R5 is stored R1 Adding five values together R5 lt RO R1 R2 R3 R4 ADD R5 RO R1 R5 lt RO R1 ADD R5 R2 85 lt R5 R2 ADD R5 R3 R5 lt R5 R3 ADD R5 RA Rb lt 5 RA LOOP B LOOP Infinite loop END 12 Lab 1 Flashing LED Objective The objective of this lab is to complete assemble and download a simple assembly language program Here is a short list of what you will do in this session Write some THUMB assembly language instructions Use different memory addressing modes Test and debug the code on the Keil board You will flash an LED Light Emitting Diode at an approximate 1 Hz frequency Background The LPC1768 belongs to the Cortex M3 family of microprocessors which uses the THUMB instruction set Thumb is a subset of the ARM instruction set In order to flash an LED one needs to know how the LPC1768 microprocessor is connected to the LEDs the pin configuration and interfacing A lot of the hardware interfacing details are in Lab 3 The details to accomplish this lab are Writing 0xB0000000 into memory address 0x2009C020 turns off the three LEDs on port 1 pins P1 28 P1 29
5. and P1 31 Writing 0x0000007C into memory address 0x2009C040 turns off the five LEDs on port 2 pins P2 2 to P2 6 Toggling bit 28 of the address 0x2009C020 will cause the corresponding LED P1 28 to alternate between on and off The memory address is 32 bits wide bit 31 down to bit 0 You should switch between 0 0000000 and 0xA0000000 to flash the LED Pre lab Before the lab session look at the THUMB instruction set in Appendix B The LPC1768 is a Cortex M3 ARM CPU using the THUMB instructions set In order to see a flashing LED implement a delay between the LED on and off states Think about implementing a delay in assembly language Hint Increment or decrement a register in a loop until it reaches a certain value There is no deliverable as pre lab for this lab 13 In lab procedure Complete the given code that is mostly written Create new folder like N ECE222 Lab1 and project as was done in Lab 0 Start by turning off all eight LEDs Then implement the flashing LED code using an infinite loop which toggles bit 28 of the address 0x2009C020 Figure 1 1 shows the two different approaches The shorter flowchart leads to smaller code size and the longer flowchart will cost you marks as the code is inefficient Don t forget to insert a 500mS delay in the loop otherwise it is too fast to see Assemble the code download it to the board and debug it if necessary Initialize LEDs Turn
6. BLX Branch indirect with Link B BL BX and BLX m BX Branch indirect Rm CBNZ Compare and Branch if Non Zero Rn label CBZ Compare and Branch if Zero Rn label CLREX Clear Exclusive CLZ Count Leading Zeros Rd Rm CMN N Z C V Compare Negative eval Rn 0p2 Rn Op2 CMP N Z C V Compare evaluates Rn Op2 Rn Op2 Change Processor State Disable CPSID CPS i Interrupts Change Processor State Enable CPSIE CPS i Interrupts EOR S N ZC Exclusive OR AND ORR EOR BIC and ORN Rd Rn Op2 LDM Rn reglist Load Multiple registers increment after LDMDB Load Multiple registers decrement LDMEA Rn reglist before LDM and STM LDMFD LDMIA Rn reglist LDR Load Register with 32 bit word Rt Rn offset LDRB LDRBT Rt Rn offset LDRD Load Register with two bytes LDR and STR immediate offset Rt Rt2 Rn offset LDREX Load Register Exclusive Rt Rn offset LDREXB Rt Rn Load Register Exclusive with Byte LDREX and STREX Rn LDREXH Load Register Exclusive with Halfword Rt Rn Load Register with Halfword Memory access instructions LDRH Rt Rn offset 4 34 Load Multiple registers increment after Memory access instructions Load Register with byte Mnemonic Operands Flags Brief description See LDRHT LDRSB Load Register with Signed Byte LDRSBT Rt Rn offset LDRSH Load Register with Signed H
7. MOVT moves into the upper word Show several ways to create an address using a fixed offset and register as offset and several examples used below NOTE MOV can move ANY 16 bit and only SOME gt 16 bit constants into a register MOV R2 OxC000 move 0 000 into R2 MOV R3 0 80000000 move initial Port 1 value into R3 MOV R4 0 0 init R4 register to O to build address MOVT R4 0x2009 assign 0x20090000 into R4 ADD R4 R4 R2 add OxC000 to R4 to get 0x2009C000 STR r4 80x20 Turn off three LEDs on Port 1 using an offset MOV R3 0x0000007C move initial value for port P2 STR R3 R4 40x40 Turn off five LEDs on port 2 MOV R2 HOx20 put Port 1 offset into R2 MOV RO OxFFFF Initialize RO lower word for countdown loop SUBS RO 1 Decrement rO and set N Z V C status bits Approximately five lines of code 3 are reguired to complete the program STR R3 R4 R2 Toggle the bit 28 or port 1 B loop This branch needs to be fixed END 15 Lab 1 Submission form Class 001 201 202 203 Demo date 002 204 205 206 Submission Statement We I are am submitting this report for grading in 222 We I certify that this report including any code descriptions flowcharts etc that are part of the submission were written by us me and have received no prior academic credit at this univer
8. Rm ROR n Test Equivalence same as EORS N Z C TST and TE Rn Op2 but it preserves Rn TST Rmus N ZC same as ANDS but it preserves Rn TST and n Op UBFX Unsigned Bit Field Extract SBFX and UBFX Rd Rn 156 width UDIV Unsigned Divide SDIV and UDIV Rd Rn Rm Unsigned Multiply with Accumulate 32 RdLo RdHi Rn Rm x 32 64 64 bit result UMULL UMLAL SMULL and SMLAL Unsigned Multiply 32 x 32 64 bit UMULL RdLo RdHi Rn Rm result USAT Rd Rm shift Unsigned Saturate SSAT and USAT Hs UXTB Zero extend a Byte 5 and UXT Rd Rm ROR n UXTH Zero extend a Halfword SXT and UXT Rd Rm ROR n WFE Wait For Event WFE WFI Wait For Interrupt WFI Table B 1 Cortex M3 Math and Bitwise Instructions 7 Mnemonic Operands Flags Brief description See ADC S N Z C V Add with C B Rn 2 ADD S N Z C V Add Rd Rn Op2 ADD SUB SBC and RSB N Z C V Add ADDW Rd Rn imm12 AND S N ZC Logical AND AND ORR EOR BIC and ORN Rd Rn Op2 37 Mnemonic Operands Flags Brief description See ASR S N ZC Arithmetic Shift Right ASR LSL LSR ROR and RRX Rd Rm Rs gt BFC Bit Field Clear and Rd 156 width BFI Bit Field Insert and Rd Rn 156 width BIC S N Z C Clear AND ORR EOR BIC and ORN Rd Rn Op2 CLZ Count Leading Zeros Rd Rm EO
9. S N Z C V Subtract ADD ADC SUB SBC and RSB Rd Rn Op2 SUB SUBW N Z C V Subtract ADD ADC SUB SBC and RSB Rd Rn imm12 SXTB Sign extend a byte SXT and UXT Rd Rm ROR n SXTH Sign extend a halfword SXT and UXT Rd Rm ROR n Test Equivalence same as EORS TEQ N Z C TST and TEQ Rn 2 but it preserves Rn Test same as ANDS but it preserves TST N Z C TST and TEQ Rn Op2 Rn UBFX k Unsigned Bit Field Extract SBFX and UBFX Rd Rn 156 width UDIV Unsigned Divide SDIV and UDIV Rd Rn Rm Unsigned Multiply with Accumulate RdLo RdHi Rn Rm 32 x 32 64 64 bit result UMLAL UMULL UMLAL SMULL and SMLAL Unsigned Multiply 32 x 32 64 bit RdLo RdHi Rn Rm result USAT Unsigned Saturate SSAT and USAT Rd n Rm shift 5 UXTB Zero extend a Byte SXT and UXT Rd Rm ROR n UXTH Zero extend a Halfword SXT and UXT Rd Rm ROR n UMULL 39 Appendix C Memory map Table C 1 shows a rough memory map Detailed information can be extracted from chapter 2 of the document LPC17xx User manual Table C 1 Memory usage for Coretx M3 and LPC1768 Microprocessor Address range General use Address range for Description MCB1700 0x0000 0000 On chip non 0x0000 0000 Flash memory Ox1FFF FFFF volatile memory 0x0007 FFFF On chip SRAM 0x1000 0000 32 kB user program memory 0x1000 7FFF Boot ROM Ox1FFF 000
10. SBFX and rUBFX Rd Rn 156 width SDIV Signed Divide SDIV and UDIV Rd Rn Rm SEV Send Event SEV Signed Multiply with Accumulate 32 x SMLAL RdLo RdHi Rn 6 32 64 64 bit result UMULL UMLAL SMULL and SMLAL SMULL Signed Multiply 32 x 32 64 bit result RdLo RdHi Rn Rm SSAT Rd Rm shift Q Signed Saturate SSAT and USAT Hs STM Store Multiple registers increment Rn reglist after STMDB Store Multiple registers decrement LDM and STM STMEA Rn reglist before STMFD Store Multiple registers increment STMIA Rn reglist after STR Store Register word Rt Rn offset Memory access instructions STRB Store Register byte STRBT Rt Rn offset STRD Store Register two words LDR and STR immediate offset Rt Rt2 Rn offset STREX Store Register Exclusive Rd Rt Rn offset STREXB Store Register Exclusive Byte LDREX and STREX Rd Rt Rn STREXH Store Register Exclusive Halfword Rd Rt Rn STRH Store Register Halfword STRHT Rt Rn offset Memory access instructions STRT Store Register word Rt Rn offset 36 Mnemonic Operands Flags Brief description See SUB S N Z C V Subtract ADD ADC SUB SBC and RSB Rd Rn Op2 N Z C V Subtract ADD ADC SUB SBC and RSB SUBW Rd Rn imm12 SXTB Sign extend a byte SXT and UXT Rd Rm ROR n SXTH Sign extend a halfword SXT and UXT Rd
11. of a millisecond in a loop The final value of this 32 bit number should be sent to the 8 LEDs in separate bytes with a 2 second delay between them Background You will need to review the information presented in the schematic diagram Appendix F as well as the LPC17xx User manual 1 literature number UM10360 Information about the LEDs and INTO push button is in the Appendix D Pre lab In Lab 1 and 2 the method used to turn the LEDs on and off was very strange as the IO pins were changed from input to output in order to turn an LED off or on The FIODIR address was used instead of writing O s and 1 s to the outputs FIOPIN Before the lab determine what to write into which memory address to turn any of the 8 LEDs on or off Refer to Appendix D or the LPC17xx User manual 1 The INTO push button is also used It should be set to an input GPIO type port with a pull up resistor Note that this is done by default Submit assembly language code for the following tasks to the drop box for Prelab 3 Subroutine which implements a 100uS delay 23 Pseudo or asm code that initializes the INTO button as GPIO port with a pull up resistor PINSEL3 and PINSEL4 addresses are defined in the sample code The default value is OxO so one just has to set the appropriate bits INTO is pin P2 10 Pseudo or asm code that displays the lowest 8 bits of RO on the 8 LEDs Calculate the number of 100uS delay routine loops that are necessary to generate
12. penalty for copying or plagiarism will be a grade of zero 0 Member 1 Member 2 Name Name UW ID NOT student UW ID NOT student Signature Signature Note Reports submitted without a signed submission statement will receive a grade of zero 0 Weight Grade Comment Part l Pre lab 10 Part ll Lab completion 30 Lab demo Questions 30 Part lll Code quality 20 Lab report Code comments 10 Total 100 26 Lab 4 Interrupt Handling Objective The objective of this lab is to learn about interrupts You will enable an interrupt source in the LPC1768 microprocessor and you will write an interrupt service routine ISR that is triggered when pressing the INTO button The ISR will return to the main program after handling the interrupt What to do The objectives for Lab 4 are achieved by implementing a program similar to the program for Lab 3 except using interrupt drive I O instead of programmed I O Pre lab Identify all relevant I O register memory addresses see the UM10360 manual Write an initial program that configures the pin control block i e setting the function of pins to GPIO setting the direction to either input or input and that enables GPIO interrupts sensitive to the falling edge of P2 10 the INTO button Take a look at the EINT3 IROHandler code in the start up file and set a breakpoint in it Test your initial prog
13. 0 8 kB boot ROM with flash Ox1FFF 1FFF services 0x2000 0000 On chip SRAM 0x2007 C000 16 kB AHB SRAM Bank 0 Ox3FFF FFFF typically used for 0x2007 FFFF peripheral data 0x2008 0000 16 kB AHB SRAM Bank 1 0x2008 3FFF GPIO 0x2009 C000 16 kB 0x2009 FFFF 0 4000 0000 APB Peripherals 0x4000 0000 APBO Peripherals Ox5FFF FFFF 0x4007 FFFF 0x4008 0000 APB1 Peripherals Ox400F FFFF AHB Peripherals 0 5000 0000 Ethernet USB 0x501F FFFF 0 000 0000 Cortex M3 Private 0 000 0000 Cortex M3 functions including OxEOOF FFFF Peripheral Bus OxEOOF FFFF NVIC and System Tick Timer Figure C 1 shows a detailed memory map for the LPC1768 MCU 40 0x4010 0000 APB1 peripherals oxtoor cooo 31 system control 0x400C 0000 30 16 reserved 0x4008 C000 0x400B 8000 motor control PWM 0x4008 4000 om m 0x400B 0000 12 repetitive interrupt Ox400A cooo 14 reserved 0 sooo 1 8 Ox400A 4000 reserved oxtooa ooo 8 202 oloogcuo ugr3 6 oxtoos 4000 5 Tmer3 04009 0000 4 2 3 DAC 0 4008 8000 2 sso 1 0resened 0x0000 0400 0x0000 0000 active interrupt vectors I code D code memory space 1 256 words 0 5 ER LPC1768 memory space E mm FFFF reserved x ToxE010 0000 ARS 0502
14. 0 0000 127 4 reserved 0 000 0000 Ta iial 0x5000 C000 private peripheral bus reserved m 0000 2 reserved 0450008000 appn jen 000 1 GPDMAconteler 60004000 reserved 0 Ethemetcontroler 645000 0000 peripheral bit band alias addressing 4200 0000 reserved Fox4010 0000 APB1 peripherals APBOperipherals 508 0000 31 24 reserved APBO peripherals 1 amp 4000 QUOD X 3 0x4006 0000 reserved 23 I2C1 0x4005 C000 22 19 reserved 0x4004 C000 18 CAN2 0x4004 8000 0000 SRAM bit band alias addressing gt 0000 reserved 17 0 4004 4000 16 _ 0 4004 0000 15 CAN AF registers 0x4003 C000 reserved x2008 4000 14 CAN AF RAM 0x4003 8000 AHB SRAM 2 blocks of 16 kB 1 1 i 1 1 1 1 1 i 2 200 0000 ___ ___ ee V C000 1 1 1 1 1 1 0x2007 cooo 13 ADC 054003 4000 fu r 8 FFF 2000 SSP __ M 0 1000 8000 101 GPIO interrupts 0x4002 8000 lg backup registers 0 4002 4000 la SPI 0x4002 0000 pco 4001 000 0x4001 8000 reserved 0x4001 4000 32 kB local static RAM 0x1000 0000 2 reserved 2 068 0x0008 0000 4 512 on chip flash 62800070000 x UARTI 0x4001 0000 UARTO 0x4000 C000 a TIMER1 0x4000 8000 1 TIMERO 0x40
15. 00 4000 0 WDT 0x4000 0000 Figure C 1 Detailed memory map for LPC1768 microprocessor 41 Appendix D Input Output ports Detailed information on this topic can be found in chapters 7 8 and 9 of the document LPC17xx User manual 1 The LPC1768 microprocessor on the MCB1700 board has 100 pins as shown in figure D 1 Figure D 2 shows the functionality of selected pins which we are interested in Figure D 1 The LPC1768 microprocessor in LOFP100 pin configuration 1 As you can see in figure 2 many pins can have more than one function For example pin number 73 named as P2 2 can take four different roles as indicated by P2 2 PWM1 3 CTS1 TRACEDATA3 Actually many pins of LPC1768 can have up to four different functionalities For each pin there is a two bit field in a register named PINSELx that determines the functionality of the pin Table D 1 shows how two the bits choose pin functionality For more information refer to Appendix A or tables 79 to 86 of the LPC17xx User manual We define the pins we are going to work with as GPIO general purpose input output the default functionality 42 P4 28 P4 29 P0 0 RD1 TXD3 SDA1 1 0 TXDO P0 1 TD1 RXD3 SCL1 P1 1 ENET TXD1 P0 2 TXD0 AD0 7 P1 4 ENET TX EN P0 3 RXD0 AD0 6 P1 8 ENET_CRS P0 4 12SRX CLK RD2 CAP2 0 P1 9 ENET RXDO P0 5 DSRX WS TD2 CAP2 1 P1 10 ENET RXDI P0 6 DSRX SDA SSEL1 MAT2 0 P1 14 ENET RX ER 0 7125 CLK SCK1 MAT2 1 1
16. 001 0111 23 17 B E E E 0000 0001 1101 0101 469 1D5 C 0000 0111 0101 1101 1885 75D D NEN 0000 0000 0111 0101 117 75 0000 0000 0000 0001 1 1 0000 0001 0101 1101 349 15D G 0000 0001 1101 1101 477 1DD H E E EH 0000 0000 0101 0101 85 55 0000 0000 0000 0101 5 5 J 00010211101110111 6007 1777 K EH 0000 0001 1101 0111 471 1D7 L NH fH 0000 0001 0111 0101 373 175 M 0000 0000 0111 0111 119 77 0000 0000 0001 1101 29 1D ERES DEB 0000 0111 0111 0111 1911 777 NEN 0000 0101 1101 1101 1501 5DD Q 00011101 11010111 7639 1DD7 R NEN E 0000 0000 0101 1101 93 5D S E E E 0000 0000 0001 0101 21 15 T 0000 0000 0000 0111 7 7 0 0000 0000 0101 0111 87 57 V 0000 0001 0101 0111 343 157 Ww NEN 0000 0001 0111 0111 375 177 X NH 0000 0111 0101 0111 1879 757 Y EN 0001110101110111 7543 1D77 Z NEN 0000 0111 0111 0101 1909 775 Z o D A dash is equal to three dots The space between parts of the same letter is equal to one dot The space between two letters is equal to three dots The space between two words is equal to seven dots 21 Lab 2 Submission form 201 202 203 Demo date 204 205 206
17. 15 REF CLK P1 16 ENET MDC 0 8125 WS MISO1 MAT2 2 P1 17 ENET MDIO P0 9 DSTX SDA MOSII MAT2 3 P0 10 TXD2 SDA2 MAT3 0 P1 18 USB UP LED PWM1 1 CAP1 0 P0 11 RXD2 SCL2 MAT3 1 P1 19 MCOA nUSB PPWR CAPI 1 P0 15 TXD1 SCK0 SCK P1 20 MCFB0 PWM1 2 SCKO P1 21 MCABORT PWM1 3 SSELO P0 16 RXDl SSELO SSEL P1 22 MCOB USB PWRD MATI 0 P0 17 CTS1 MISO0 MISO P1 23 MCFB1 PWM1 4 MISOO P0 18 DCD1 MOSIO MOSI P1 24 MCFB2 PWMI 5 MOSIO P0 19 DSR1 SDA1 P1 25 MC1A MAT1 1 P0 20 DTRI SCLI1 P1 26 MCIB PWMI 6 CAP0 0 P0 21 RI1 RD1 P1 27 CLKOUT nUSB OVRCR CAPO 1 P0 22 RTS1 TD1 P1 28 MC2A1 0 MAT0 0 P023 ADO 0 DSRX CLK CAP3 0 P1 29 MC2B PCAP1 1 MAT0 1 P1 30 VBUS AD0 4 P024 ADO 1I DSRX WS CAP3 1 P1 31 SCK1 AD0 5 P0 25 ADO 2 DSRX SDA TXD3 P0 26 AD0 3 AOUT RXD3 P0 27 SDA0 USB_SDA P2 0 PWM1 1 TXD1 P0 28 SCLO USB SCL P2 1 PWM1 2 RXD1 P0 29 USB_D P2 2 PWM1 3 CTS1 TRACEDATA3 P0 30 USB D P2 3 PWM1 4 DCD1 TRACEDATA2 P2 4 PWM1 5 DSR1 TRACEDATA1 P2 5 PWM1 6 DTR1 TRACEDATAO P3 25 MAT0 0 PWM1 2 P2 6 PCAP1 0 RI1 TRACECLK P3 26 STCLK MAT0 1 PWM1 3 P2 7 RD2 RTS1 P2 8 TD2 TXD2 P4 28 RX_MCLK MAT2 0 TXD3 P2 9 USB_CONNECT RXD2 P4 29 TX_MCLK MAT2 1 RXD3 P2 10 nEINTO NMI P2 1I nEINTI DSTX P2 12 nEINT2 DSTX WS P2 13 nEINT3 DSTX SDA LPC1768 Figure D 2 LED connections to NXP LPC1768 4 P1 0 P14 P18 BES P1 10 P1 14 P1 15 P1 16 PLI P118 P119 4 P130 lt Joystick P121 centre P122 P2 0 LED tm P2 9 P210
18. 448 100n INTO R28 D6 33k COMI SubD9F GND COMO T4 BC850B PMLL4448 GND DP Dg P0239 MCB1760 only Dt EU UMODE GND P118 1121117833 DS 4 7 7220k BAT VBAT amm CR1220 133VA VDDIO VDDIO 33V VDDREG VDDREG 33V N R25 R26 1008 DEVICE BAT60A BAT60A VIN 49 SL 10u GND 3 USB B C50 29 417 IM GND 18 R3 GND 53 3 3V He usc vaL R34 GND 10k lt 15 BC857B R36 R37 638 680R 680R 2k2 R39 1k MCB1700 gt KEIL Revision 1 2 USB COM LED SchDoc Size A4 Sheet 3 of 6 An ARM Company Date 29 7 2009 Web www keil com MCB1700 J 3 4 52 RATERARERAOERSI 1008 3 3 3 3 10 LM3526M L _USB micro AB MCB1700 KEIL 53 Revision 1 2 USB OTG SchDoc Size A4 Sheet 4 of 6 An ARM Company Date 29 7 2009 3 Web wwwkeil com MCB1700 4 LCD TFT Display PJS 008 2000 1 6 E L8 BB 10 L1 5 12 9 15 16 17 18 1 19 20 21 GND 3l 2 2 GND SubD 9M MCB1700 SD CAN DEBUG SchDoc Revision 1 2 gt Sheet 5 of 6 Size A4 KEIL An ARM Company Date 29 7 2009 3 Web wwwkeil com MCB1700 4
19. ADD R13 R13 8 pop the 8 bytes of data RO R3 put onto the stack MOV more code 18 mySubroutine STMFD R13 RO RA R14 push RO 84 and R14 taking 3 x 4 12 bytes To read from the stack offset 12 bytes for pushed registers and then 4 bytes per data LDR RO R13 412 read the value of R3 that was pushed onto the stack LDR R4 R13 16 read the value of RO that was pushed onto the stack ADD R3 R3 R2 rest of the subroutine till return with LDMED LDMFD R13 RO RA R15 restore RO R4 and the return address Lookup Tables Creating a lookup table is very easy However one must be careful as to how one reads it and indexes into it Data can be 8 bit byte 16 bit half word or 32 bit word The ARM documentation may confuse you if you are used to calling 16 bit a word and 32 bit a long word Here is some simple code to loop thru data in a lookup table ADD some code ResetLUT LDR R5 LUT assign the address for the lab LUT to R5 LDRD R6 R5 read the first 32 bit word from the LUT 6 0 test it to see if we hit the null at the end BEO ResetLUT If we hit the end start at the beginning of the LUT ADD 5 4 add 4 bytes to point to the next 32 bit data in LUT R6 now holds the data read from the LUT DDD more code to do something with the data from the LUT ALIGN make sure that the data is aligned properly in memory LUT DCD 469 0x020 3 5 Ox3F2 0 LookUp Table with a nu
20. Accessed on June 18 2012 5 Snap shots taken from the Keil uVision4 software 6 Morse Code From Wikipedia the free encyclopedia Can be accessed online http en wikipedia org wiki Morse code Accessed on August 21 2012 7 Cortex M3 Devices Generic User Guide Published by ARM Can be accessed online http infocenter arm com help topic com arm doc dui0552a DUI0552A cortex m3 dgug pdf Accessed on August 21 2012 56
21. INTO P2 11 P2 12 P2 13 There are ten PINSEL pin select registers Two of them PINSEL3 and PINSEL4 are used for pins connected to LEDs The PINSEL3 address 0x4002 COOC controls P1 31 16 pins and the PINSELA 0x4002 C010 controls P2 15 0 pins Table D 2 shows pin function select for PINSEL3 partial and table D 3 shows pin function select for PINSEL4 partial Pins connected to LEDs have bold purple font You should also find the pins connected to INTO and Joystick centre push buttons 43 Table D 1 Pin function select register bits PINSELO 9 values Function Value after reset 00 Primary default function typically GPIO port 01 First alternate function 00 10 Second alternate function 11 Third alternate function Table D 2 Pin function select register 3 2 LED Pin k Function Function Function Reset PINSEL3 Function when 00 name when 01 when 10 when 11 value 19 18 P1 25 GPIO Port 1 25 MCOA1 Reserved MAT1 1 21 20 P1 26 GPIO Port 1 26 MCOB1 PWM1 6 CAP0 0 23 22 P1 27 GPIO Port 1 27 CLKOUT USB OVRCR CAP0 1 25 24 P1 28 GPIO Port 1 28 MCOA2 PCAP1 0 MAT0 0 LED 7 27 26 P1 29 GPIO Port 1 29 MCOB2 PCAP1 1 MATO 1 00 LED 6 29 28 P1 30 GPIO Port 1 30 Reserved Veus ADO 4 31 30 P1 31 GPIO Port 1 31 Reserved SCK1 ADO 5 LED 5 Table D 3 Pin function select register 4 z 5 LED Pin k Function Function Functi
22. R S N ZC Exclusive OR AND ORR EOR BIC and ORN Rd Rn Op2 LSL S N Z C Logical Shift Left Rd Rm lt Rs n gt ASR LSL LSR ROR and RRX LSR S N ZC Logical Shift Right Rd Rm Rs gt KILA Multiply with Accumulate 32 bit Rd Rn Rm Ra result MUL MLA and MLS MLS Multiply and Subtract 32 bit result Rd Rn Rm Ra MUL S N Z Multiply 32 bit result MUL MLA and MLS Rd Rn Rm 5 Rd Rn Op2 N ZC Logical OR NOT AND ORR EOR BIC and ORN ORR S N ZC Logical OR Rd Rn Op2 RBIT Reverse Bits Rd Rn REV Reverse byte order in a word Rd Rn Reverse byte order in each REV REV16 REVSH and RBIT Rd Rn halfword Reverse byte order in bottom REVSH Rd Rn halfword and sign extend ROR S N ZC Rotate Right Rd Rm Rs gt RRX S a N ZC Rotate Right with Extend Rm ASR LSL LSR ROR and RRX RSB S N Z C V Reverse Subtract Rd Rn Op2 SBC S N Z C V Subtract with Carry Rd Rn Op2 SBFX Signed Bit Field Extract SBFX and rUBFX Rd Rn 156 width z 38 Mnemonic Operands Flags Brief description See SDIV Signed Divide SDIV and UDIV Rd Rn Rm Signed Multiply with Accumulate 32 x 32 64 64 bit result SMLAL RdLo RdHi Rn Rm UMULL UMLAL SMULL and SMLAL Signed Multiply 32 x 32 64 bit RdLo RdHi Rn Rm result SMULL SSAT Signed Saturate SSAT and USAT Rd Rm shift 5 SUB
23. University of Waterloo Electrical and Computer Engineering Department Digital Computers ECE 222 Lab manual Version 1 70 Released on November 20 2012 Developed by Rasoul Keshavarzi Hiren D Patel Assisted by Roger Sanderson Eric Praetzel Gordon B Agnew This manual is for the exclusive use of students registered in the course Reproduction or use for any other purpose is prohibited Contents General eegerit erem rm 3 eA SCM SUG Cai 3 DSN OU DS ete ES 4 LAD VAC I ETE c 4 Due dates and On time delivery 4 4 Lab 0 Introduction to the ARM platforms in the 1ab pp 5 Lab 1 Flashing LED co eite Ee e o t a tuni ves eem triv a 13 Lab 2 Subroutines and parameter 115 17 Lab 3 Input Out put InterfAa i NE ee doe voe v i 23 27 Appendix A The LPC1768 55 30 Appendix B Instruction set summary ss 33 Appendix Memory e ai 40 Appendix D Input Output ports ee 42 Appendix E Exception and inanes esee 48 Appendix F Schematic diagrami 4 ono ot ae ete ee a i eR Te none eas ed A e Ted RR 50 56 General Information All lab content and resources are posted o
24. ad do this add this AFTER your code is working you may want to look at the CLZ instruction Note one can determine if all of the Morse pattern has been shifted out without a counter several ways 5 Turn the LED on and off according to the Morse code with delays between consecutive bits for that letter down to bit O 6 Inserta long delay 3 dots before fetching next character 7 Insert a long delay 7 dots and show the same four letters over again Note Use both registers and the stack for parameter passing between the main program and the subroutines Add pass by stack only AFTER everything is working as it s harder to do Example Suppose the lab partner s initials compose the word BIRD Then the program should extract the letters B R D and create a Morse code like this N OU D Please note that all four letters are considered as one word Lab report Submit a report to the electronic drop box prepared for lab 2 Examine the Lab 2 Submission form to understand what you will need to deliver Expect to have nearly as many lines of documentation as code 20 The Morse code Table 2 1 shows corresponding Morse codes for English language alphabets Table 2 1 The Morse code Letter Morse code Binary value Decimal value Hex value A HE 0000 0000 0
25. alfword LDRSHT Rt Rn offset LDRT Load Register with word Rt Rn offset LSL S N Z C Logical Shift Left Rd Rm lt Rs n gt ASR LSL LSR ROR and RRX LSR S N ZC Logical Shift Right 5 Rd Rm Rs gt 3 2 MLA Multiply with Accumulate 32 bit result Rd Rn Rm Ra MUL MLA and MLS MLS Multiply and Subtract 32 bit result Rd Rn Rm Ra MOV S N Z C Move MOV and MVN Rd Op2 MOVT Move Top MOVT Rd imm16 MOVW Move 16 bit constant top word set to N Z C MOV and MVN MOV Rd imm16 zero MUL S N Z Multiply 32 bit result MUL MLA and MLS Rd Rn Rm MVN S N Z C Move NOT MOV and MVN Rd Op2 NOP No Operation NOP ORN S Rd Rn Op2 N ZC Logical OR NOT AND ORR EOR BIC and ORN ORR S N ZC Logical OR Rd Rn Op2 POP Pop registers from stack reglist PUSH and POP PUSH Push registers onto stack reglist RBIT Reverse Bits Rd Rn REV Reverse byte order in a word Rd Rn REV REV16 REVSH and RBIT REV16 m Reverse byte order in each halfword Rn Reverse byte order in bottom halfword REVSH Rd Rn and sign extend 35 Mnemonic Operands Flags Brief description See ROR S N ZC Right uM Rd Rm Rs gt RRX S N ZC Right with Extend Rd Rm ASR LSL LSR ROR and RRX RSB S N Z C V Reverse Subtract Rd Rn Op2 SBC S N Z C V Subtract with Carry Rd Rn Op2 SBFX k Signed Bit Field Extract
26. ameter register RO and waits for RO 500ms before returning Submit the subroutines as a single text file to the electronic drop box as Prelab 2 Hints The Course Notes have excellent code examples for subroutine and pass by stack Optimization can be done to greatly reduce the size of the assembly code This should not be attempted until everything is working and only if the student has time Lab 2 can be done in 150 lines of code with the main loop taking around 40 lines Expect to add a good fraction of your code size in comments before submission for marking Simulate to check the basic operation before downloading to hardware To simulate the code use breakpoints or comment out the branch instruction in the timing loop so that it passes thru Data can be passed to a subroutine via the registers stack or memory Passing by memory requires the programmer to organize how the memory is used Passing by register is the easiest 17 but there are a limited number of registers to use Passing by stack is the most flexible however it is the most complex and error prone method for assembly language programmers When starting with subroutines use only register passing When your code is working switch one subroutine to using pass by stack Here is an example of a subroutine using pass by register In this example the STMFD instruction stores registers onto the stack R14 is the Link Register and holds the address to return to R14 is pus
27. c com arm doc dui0204j Cihedhif html Note for the tables e angle brackets lt gt enclose alternative forms of the operand e braces enclose optional operands e the Operands column is not exhaustive e Op2 is a flexible second operand that can be either a register or a constant e most instructions can use an optional condition code suffix e Most instructions support the suffix S which will result in flags being set e Status Flags set include Negative Zero Carry oVerflow For more information on the instructions and operands see the instruction descriptions Table B 1 Cortex M3 Instructions 7 Mnemonic Operands Flags Brief description See ADC S N Z C V Add with Carry Rd Rn Op2 ADD S N Z C V Add Rd Rn Op2 ADD SUB SBC and RSB ADD N Z C V Add ADDW Rd Rn imm12 ADR Load PC relative Address ADR Rd label AND S N ZC Logical AND AND ORR EOR BIC and ORN Rd Rn Op2 ASR S Arithmetic Shift Right ASR LSL LSR ROR Bk l RRX Rd Rm Rs gt B h E 10 BNE Not B Not B BL BX and BLX label BCC carry clear BCS carry set etc BFC Bit Field CI and Rd 15 width en BFI k Bit Field Insert BFC and BFI Rd Rn 156 width BIC S N Z C Bit Clear AND ORR EOR BIC and ORN Rd Rn Op2 BKPT Breakpoint BKPT fimm 33 Mnemonic Operands Flags Brief description See BL Branch with Link label
28. cking on Start All Programs Keil 4 Click on the Project tab and choose New uVision Project Select or create a subdirectory on N drive like N ECE 222 Lab 0 then assign a name to your project like LabO can be different from folder name then click on Save DO NOT MAKE A DIRECTORY FILE OR PROJECT NAME WITH A SPACE IN IT A space will prevent simulation from working properly To select a CPU double click on NXP founded by Philips and select LPC1768 Click OK Click NO when prompted to copy startup LPC17xx s to Project Folder which is for C programmers rather than assembly programmers Open a web browser and from the lab webpage http ece uwaterloo ca ece222 download startup LPC17xx s Assembly startup file and LabO program s Sample Lab 0 code Save them to the Lab 0 folder created in Step When using a web browser right clock on the link to the file and choose Save target as to select a destination folder Switch back to the uVision4 screen which should now resemble Figure 1 2 Right click on the Source Group 1 under Target 1 Select Add Files to Group Source Group 1 Select All Files from Files of type drop down menu which will list all files in the folder Select startup LPC17xx s click Add then select the file LabO program s click Add then click Close Next click on Target 1 so that it is highlighted if it is not already and then click again on it waiting a couple of seconds
29. d with them If you miss a lab session please inform the lab instructor to avoid being recorded as Absent They will try to assign you to another session for that particular lab Electronic lab report submission is done through ECE CourseBook https ecewo32 uwaterloo ca cgi bin WebObjects CourseBook or possibly UW Learn learn uwaterloo ca Lab reports are due 48 hours after your scheduled lab session A penalty per day will be applied to late reports Lab 0 Introduction to the ARM platforms in the lab Objective We will familiarize ourselves with the basics of the ARM boards used in the ECE 222 lab Here is a short list of what we will do in this session Introduction to ARM board Introduction to uVision4 software o Howto create or open a project o Howto build or assemble a target o Howto download object code into memory on the target board o Howto debug code o Howto use the simulator What you do In this lab you will load assemble download and run some short programs Each program performs a specific task For example one program loads some values into some registers and them adds them up You will confirm the result by checking the contents of the registers in debug mode Pre lab N A Introduction to hardware and software In order to get students familiarized with the tools used in the ECE 222 lab let us take a closer look at the hardware and software used in the lab More details can be found in Append
30. ent LPC17xx User manual 1 LCD Display Dual RS232 SDCard Elhemet Figure A 1 Block diagram of LPC1768 1 Figure A 2 shows a simplified block diagram of the LPC1768 microprocessor As you can see there is no memory block in the above figure This is because all volatile RAM and non volatile Flash memories are on chip Figure A 3 shows some details of the CPU and buses 30 8 gt e lt c 77 Xtalin Xtalout RST APB slave group 0 APB slave group 1 CAN 1 amp 2 Watchdog Timer Pin Connect Block GPIO Interrupt Ctl Real Time Clock 20 bytes of backup registers RTC Power Domain Figure A 2 Simplified block diagram of LPC1768 1 31 JTAG Ethemet PHY USB interface Debug Port interface interface X32Kin k 5 ost controls ARM Cortex M3 22 internal power Multilayer AHB Matrix APB slave group 0 APB slave group 1 SSS l 2 LWem Kk gt Sara aT Pa EC System control Pin connect block Motor control PWM Quadrature encoder 32 kHz oscilator Real Time Clock ultra low powe regulator Figure A 3 LPC1768 block diagram CPU and buses 1 32 Appendix B Instruction Set Summary The processor implements a version of the Thumb instruction set Table B 1 lists the supported instructions 7 Details on the instructions can be found at http infocenter arm com help topi
31. ep 8 WHENEVER the INTO button is pushed reset the time delay counter and go to step 2 With everything working add your code to set the INTO button as a GPIO input port with pull up Qo cO C Lab report Submit a report to the electronic drop box prepared for Lab 3 Take a look at the Lab 3 Submission form to understand what you will need to deliver Answer these questions and put them as comments at the end of your program 24 If a 32 bit register is counting the number of 10 s of milliseconds what is the maximum amount of time which can be encoded in 8 bits 16 bits 24 bits and 32 bits Considering the question above could the program be improved by displaying 16 bits or 24 bits or by reducing the timing loop to 10us delay time or increasing it to 1ms Consider What is a typical reaction time How consistent is a person Extra Information Random numbers with linear feedback shift registers at WikiPedia http en wikipedia org wiki Linear feedback shift register 25 Lab 3 Submission form 201 202 203 Demo date 204 205 206 Submission Statement We I are am submitting this report for grading in 222 We I certify that this report including any code descriptions flowcharts etc that are part of the submission were written by us me and have received no prior academic credit at this university or any other institution The
32. for the vectors is address OxO The push button INTO is connected to pin P2 10 of the LPC1768 microprocessor This pin can be a source of external interrupts to the MCU Table E 1 shows different functionalities that can be assigned to P2 10 pin For our purpose there is no big difference between the three types of interrupt sources For simplicity you may choose to go ahead with the default state which is GPIO Table E 1 Pin functions for P2 10 Bits 21 20 of PINSEL4 Function Value after reset 00 GPIO P2 10 pin default 01 EINTO 00 10 NMI 11 Reserved 48 If you choose to consider the P2 10 as GPIO then you should also enable this source of interrupt as described in section 9 5 6 of the document LPC17xx User manual 1 You can set the P2 10 pin to be sensitive to either the rising edge or the falling edge More information on clearing the interrupt pending pin can be found in table 123 in section 9 5 6 11 page 139 of 1 49 4 iagram Schematic d Header 4x 1 LPC1768 MCB1700 KEIL Revision 1 2 B Sheet 1 6 ARM Company Date 29 7 2009 Web www keil com MCB1700 3 4 Appendix F 50 LPC1758 MCB1700 KEIL 51 Revision 1 2 LPC1750 SchDoc Size 4 Sheet 2 of 6 An ARM Company Date 29 7 2009 3 Web wwwkeil com MCB1700 4 1 6 ST3232C PMLLA
33. he most significant bits of the 8 bit number HINT The DISPLAY NUM subroutine will be called after STORE NUM DISPLAY NUM uses R3 to write to FIO2SET register which will turn on the appropriate LEDs for P2 2 thru P2 6 and it uses R4 to write to the FIOTSET register which will turn on the appropriate LEDs for P1 28 P1 29 and P1 31 Thus when parsing out the 8 bits pay close attention to which bits in R3 and R4 should be turned on in order to display the correct LEDs Keep in mind both the order and locations of the bits 2 DISPLAY NUM a This subroutine uses R3 and R4 to turn on the appropriate LEDs STORE NUM should be called prior to calling this subroutine See above hint 3 RandomNum a Sameas Lab 3 4 DELAY a This should cause a delay of RO x 0 5 seconds Note that registers R10 and R11 both have a specific purpose R10 will always store the current number being displayed by the LEDs R11 will contain the most recently generated random number Additionally you will write an interrupt service routine called EINT3 IROHandler which is actually located in the startup LPC17xx s file An updated version of the start up file is provided for this lab Open this file and scroll down until you find the EINT3 IROHandler label You need to implement it as follows e Clear the interrupt register IO2IntClr for P2 10 remember that pin 10 corresponds with the 11 bit of the register Call RandomNum which stores a new random number
34. hed on the stack and then all registers are restored just before exit with the LDMFD instruction A twist is that the return address is restored to R15 the Program Counter so that the next instruction executed is the one after BL mySubroutine Some programs may be expecting a RTS or Return To Sender instruction to mark the end of the subroutine but it is not used with ARM ADD Some code MOV R2 0x20 put some data into R2 for the subroutine BL mySubroutine branch and link to mySubroutine MOV more code mySubroutine STMFD R13 RO R2 R4 R14 save RO R2 R4 and R14 on the stack R14 is the address to return to MOV R3 40x0000007C ADD R3 R3 R2 do something LDMFD R13 RO R2 R4 R15 restore RO R2 to R4 and put the return address that was in R14 into R15 the program counter To pass data into a subroutine using the stack before the subroutine call the data must be put onto the stack The programmer must calculate how much is pushed onto the stack at the start of the subroutine and use that as an offset An example is below A different example is in the course text and course notes and it offers advantages and also demonstrates passing data back ADD Some code STR RO R13 4 4 push RO value onto the stack taking 4 bytes STR R3 R13 4 4 push R3 value onto the stack ABC code which destroys what was in RO and R3 BL mySubroutine branch and link to mySubroutine
35. in R11 Store this number in R10 e Call STORE NUM which parses out the last 8 bits of R10 and stores these bits appropriately in R3 and R4 Doing this in the ISR ensures that the next number flashed using the LEDs will be the new number Lab report Submit a report to the Lab 4 drop box Look at the Lab 4 Submission form for the deliverables 28 Lab 4 Submission form 201 202 203 Demo date 204 205 206 Submission Statement We I are am submitting this report for grading in 222 We I certify that this report including any code descriptions flowcharts etc that are part of the submission were written by us me and have received no prior academic credit at this university or any other institution The penalty for copying or plagiarism will be a grade of zero 0 Member 1 Member 2 Name Name UW ID NOT student UW ID NOT student Signature Signature Note Reports submitted without a signed submission statement will receive a grade of zero 0 Weight Grade Comment Part l Pre lab 10 Part ll Lab completion 30 Lab demo Questions 30 Part lll Code quality 20 Lab report Code comments 10 Total 100 29 Appendix A The LPC1768 microprocessor Figure A 1 shows block diagram of the LPC1768 Detailed information can be found in chapter 1 of the docum
36. ix A Hardware Figure 1 1 shows the MCB1700 board The board employs a LPC1768 a micro controller unit MCU made by NXP affiliated with Philips There are several input output peripheral devices available on the board USB USB Device USB Cortex Ethernet Host Power OTG Debug JTAG CAN P2 P 2 A 22 2 2 CAN1 9112 OM1 LE LCD Display un MicroSD ae Card gm cbe 6 Ge Potentiometer LPC1768 Port Cortex INTO amp Joystick LEDs Debug Reset ETM Buttons Figure 1 1 The MCB1700 board 2 The heart of the board is the LPC1768 MCU microcontroller unit which contains a CPU on chip flash memory RAM Random Access Memory and some peripheral blocks Software The software used to access the resources on the MCB1700 board is uVision developed by the Keil the manufacturer of the board The MCB1700 has been designed mainly to work with high level programming languages such as C The manufacturer clearly states that it is not meant to work as a platform for pure assembly language Regardless the board can be used to develop assembly language programs In lab procedure First we will build and run code on the MCU Then we will review how to debug the code 6 Running assembly language code on the MCU Follow the following steps in order to get yourself familiarized with the uVision4 interface 1 2 3 10 11 Run the software by cli
37. l schematic diagram of the MCB1700 is given in Appendix F 46 Figure D 4 shows the connections for the LEDs It is clear that in order to be able to turn the LEDs on and off the IC9 74LVC244T must be enabled Jumper LED on the board permanently activates this buffer IC The eight inputs of A1 A8 to IC9 are coming directly from the LPC1768 Three inputs are from port number 1 and five inputs are from port number 2 C52 SE vcc 22 Eo OE2 Al YI A2 5 mr i gt 4 Y4 AS Y6 7 A8 Y8 a 10 R40 680R GND 74LVC244T GND P26 GND Figure D 4 Hardware connection for on board green LEDs 4 In order to turn one LED on like P1 28 a 1 must be written to the pin P1 28 Similarly writing a O to P1 28 pin will turn the LED off The IC 74LVC244T is just a buffer to provide high current Figure 5 shows the schematic diagram for INTO push buttons 47 P2 10 100n 43 3V L GND GND Figure D 5 Schematic diagram for the INTO push button 4 Appendix E Exception and Interrupts The LPC1768 microprocessor can have many sources of interrupts Selected GPIO pins can also be set to generate interrupts The Nested Vectored Interrupt Controller NVIC is an integral part of the ARM Cortex M3 In the LPC17xx microprocessors the NVIC supports 35 vectored interrupts The default location
38. ll or O to mark the end In order to work with 16 bit data the LUT has to be type DCW you have to increment by 2 bytes to move thru the data and to read the table you need to use LDRH For Bytes use DCB and LDRB In lab procedure Implement the following changes to the provided or your Lab 1 code Put the initials of the two lab partners into a lookup tabled called InputLUT Turn all LEDs off Add the subroutines LED_OFF and LED_ON to turn off and on LED P 1 28 Call the subroutine DELAY between calls to LED_OFF and LED_ON to test all three Then write a subroutine called CHAR2MORSE that converts an ASCII character in RO into a Morse code pattern in R1 c M E 19 The following steps should be done for each of the four characters 1 Extract one ASCII character from the first to last from the lookup table InputLUT 2 Convert the ASCII character to an index value le A or 0x41 is O B or Ox42 is 1 C or 0x43 is 2 Z or Ox5A is 25 3 With the index value read from the Morse look up table called MorseLUT the corresponding 16 bit Morse pattern BE VERY CAREFUL DOING THIS Carefully match your index value an offset in bytes with the size of the data 8 16 or 32 bits wide in the MorseLUT 4 Usearegister starting at OxFO to keep track which bit of the Morse pattern is being processed To remove leading 0 s in the Morse pattern decrement the register and shift left the Morse pattern until a 1 is re
39. n Waterloo LEARN It is here learn uwaterloo ca For the Fall 2012 term we are shifted from the ColdFire to ARM boards for the ECE 222 lab You may come across some typos or errors in this manual Please report such cases to the Lab Instructor We appreciate your feedback and cooperation Lab schedule The exact dates for labs can be found here http www adm uwaterloo ca infocour CIR SA under html Lab groups All labs are to be done in groups of two students Groups of more students are prohibited It is expected that both members will put equal effort into the lab Unequal participation or other conflicts in a group should be brought to the lab instructor s attention at the earliest possible time Lab marking There are three marked components related to each lab session The lab manual for each experiment will tell you what you will need to submit for that component Prelab It is designed to get you started with the task Once completed you will be ready to start coding in assembly language Lab session Demo You will present your work to a lab staff to be marked for that section Lab report You will submit a report containing your assembly language code to be marked by a TA Different labs carry different marks allocated to them Warning Failure to attend and complete ALL labs may result in an Incomplete mark Due dates and on time delivery Lab reports and lab demonstration sessions will have marks associate
40. ndler Reset Handler PROC EXPORT Reset Handler WEAK IMPORT __main LDR RO main BX RO ENDP Dummy Exception Handlers infinite loops which can be modified NMI_Handler PROC EXPORT NMI Handler VEAK B HardFault Handlers PROC EXPORT HardFault Handler VEAK Project Running with Code Size Limit 32K Load N ARM Programs Lab_O Lab_O project AXF Restricted Version with 32768 Byte Code Size Limit Currently used 768 Bytes 23 Figure 1 5 Debug session in Vision software 5 11 The assembly language code Name Lab 0 program s Purpose Teaching students how to work with the uVision software Author Rasoul Keshavarzi ok THUMB Thumb instruction set AREA My code CODE READONLY EXPORT MAIN ENTRY MAIN This name should not be changed It matches with the startup LPC17xx s file Storing 0x1234 5678 into memory address 0x1000 0000 in order to see how little endian approach writes data into memory MOV 0x5678 Loading least significant part of RO MOVT 0x1234 Loading most significant part of RO MOV R1 0 0 Loading least significant part of R1 by zeros MOVT R1 0 1000 0x1000 0000 stored in R1 STR RO R1 Look at the memory address 0x1000 0000 Importing values to registers MOV 0x123 Loading 123 into RO MOV R1 40x456 Loading 456 into R1 MOV R2 0x789 Loading 789 into R2 MOV R3 HOxABC Loading ABC into
41. on Reset PINSEL4 Function when 00 name when 01 when 10 when 11 value 1 0 P2 0 GPIO Port 2 0 PWM1 1 TXD1 Reserved 3 2 P2 1 GPIO Port 2 1 PWM1 2 RXD1 Reserved 44 5 4 P2 2 GPIO Port 2 2 PWM1 3 CTS1 Reserved LED 4 7 6 P2 3 GPIO Port 2 3 PWM1 4 DCD1 Reserved LED 3 9 8 P2 4 GPIO Port 2 4 PWM1 5 DSR1 Reserved 00 LED 2 11 10 P2 5 GPIO Port 2 5 PWM1 6 DTR1 Reserved LED 1 13 12 P2 6 GPIO Port 2 6 PCAP1 6 RI1 Reserved LED O 15 14 P2 7 GPIO Port 2 7 RD2 RTS1 Reserved 17 16 P2 8 GPIO Port 2 8 TD2 TXD2 ENET MDC Each GPIO pin can be either input or output It can also have a pull up resistor pull down resistor or no resistor at all Figure D 3 shows general structure for a GPIO pin 33V Figure D 3 General structure of a GPIO pin For output configuration the pull up resistor can generate a high or 1 state and the open collector transistor can generate a low or state when the transistor is turned on For input configuration the open collector transistor is off There is a two bit field in the register named PINMODEx that determines the GPIO pin configuration Table D 4 shows how it is done Table D 4 Pin mode configuration pull up pull down resistor configuration PINMODO to PINMODE values Function Value after reset 00 pin has a pull up resistor enabled 00 01 pin has repeater mode enabled
42. on the Step button or F11 The yellow arrow moves down by one line This means that the first line was run and you are now about to run the next line Note If you experienced difficulty in seeing the yellow arrow in your editor window an alternative way to get to the first line of your code is to put a break point in the first instruction of your code the first line after the ENTRY and run the program in the Debug mode The program stops in that line 7 Clickon the Step button or push F11 button on keyboard several times until you reach the last line of code loop B loop before the END In each step look at the register values to make sure that the program is working properly Lab report Although there is no mark assigned to this lab attendance is mandatory and will be checked You must complete Lab 0 before starting Lab 1 10 Z N ARM Programs Lab_0 Lab_0_project uvproj pVision4 125 126 ENDP 1000000000 0500000000 000000000 2 129 Dummy Exception Handlers infinite loops which can be modified 130 piece 131 NMI Handler PROC 0 00000000 132 NMI Handler WEAK 0x00000000 00 BX 3 r He 1000000000 135 HardFault Handler 0500000000 136 PRO 1 5 0 10000200 91408 OKFFFFFFFF i c RIS PC Ox000000CC CRP Key DCD xFFFFFFFF E xPSR 001000000 ENDIF Banked System AREA text CODE READONLY El Internal Reset Ha
43. ou click you are no longer using the actual board But if GER on the right pane you will need the MCB1700 board connected to the computer you are working on V Options for Target LPC1768 Flash Device Target Output Listing User C C Asm Use Simulator Limit Speed to Real Time Settings Linker Debug utilities Use ULINK2 ME Cortex Debugger Settings Load Application at Startup Run to main Initialization File Load Application at Startup Run to main Initialization File e r Restore Debug Session Settings Restore Debug Session Settings Breakpoints v Toolbox Breakpoints Toolbox Watch Windows amp Performance Analyzer Watch Windows Memory Display Memory Display CPU DLL Parameter Driver DLL Parameter SARMCM3 DLL MPU Dialog DLL Parameter 1 DLL 768 SARMCM3 DLL MPu Dialog DLL Parameter 1 DLL 758 Figure 1 4 Simulator versus MCB1700 board 5 Debugging assembly language code As you may have noticed there is no visual difference on the board when the code is running So how can we make sure that the code is generati code step by step and checking the content of r ng the correct results This is done by running the egisters This is called Debug mode It is a very powerful and useful mode when you want to find a bug in
44. ram by ensuring that program execution jumps to the interrupt handler when pressing the INTO button Be sure to clear the interrupt In lab procedure NOTE In the past we ve polled on a global flag which indicates that the interrupt was received This new method avoids the global flag nicely The following is a high level description of the program you will implement You will implement a random countdown timer Your main program will run an infinite loop in which the LED displays the current number in R10 The main program can be interrupted by the user pressing the INTO button When this occurs an interrupt service routine will generate a new random number which is then displayed using the LEDs Each number flashes on for a half second then off for a half second The number is decremented by 1 every second The program begins with the LEDs turned off The random 8 bit number will be displayed in binary using the LEDs If a light is ON then it represents a 1 if a light is OFF then it represents a 0 The most significant bit will correspond with the leftmost LED You are provided with a template that gives you an idea of how to organize your code Carefully read the comments in the source files There are four subroutines that you will be using 27 1 STORE NUM a This subroutine will parse out the last eight bits stored in R10 and will store these bits appropriately in R3 and R4 b R3savesthe least significant bits and R4 saves t
45. sity or any other institution The penalty for copying or plagiarism will be a grade of zero 0 Member 1 Member 2 Name Name UW ID NOT student UW ID NOT student Signature Signature Note Reports submitted without a signed submission statement will receive a grade of zero 0 Weight Grade Comment Part l Pre lab 0 Part ll Lab completion 30 Lab demo Questions 30 Part lll Code quality 20 Lab report Code comments 20 Total 100 16 Lab 2 Subroutines and parameter passing Objective In structured programming big tasks are broken into small routines A short program is written for each routine The main program brings the subroutines together by calling them In most cases when a subroutine is called some information parameters must be communicated between the main program and the subroutine This is called parameter passing In this lab you will practice subroutine calling and parameter passing by implementing a Morse code system What you do In this lab you will turn one LED into a Morse code transmitter You will cause one LED to blink in Morse code for a four character word Pre lab Think about implementing Lab 1 code using subroutines Write a subroutine called LED OFF that turns LED P 1 28 off and another subroutine called LED ON that turns the LED on Write a third subroutine called DELAY that takes one input par
46. the time delays required 0 1 0 25 2 5 seconds In lab procedure Here are the steps to implement this program 1 5 Verify your timing loop which generates a 100uS delay by looping it to get a 10 second delay Create a simple counter to generate numbers from O to 255 Oxff and write these to the 8 LEDs to verify this functionality using a 0 25 second delay between numbers Add the random number routine and display the 8 bit output to the LEDs to verify the operation of the random number generator To implement the project 1 Implement a loop with 0 1 second delay between generating a random number and displaying it on the LEDs until INTO is pressed at the start of the program 2 Call the given random number function to generate a number and add an offset to get a number to generate a delay between 2 to 10 seconds and then delay that long You may use as many of the 16 bits of the pseudo random number as you wish BUT using only the least signif 3 bits will not give a good result Use 8 bits or more and scale the result to get what you need Turn one LED on and start counting 107 of millisecond time periods 100uS each With polling monitor the status of the INTO push button Once the button is pushed stop incrementing exit from the loop Send the first 8 bits least significant part of the register to the LEDs Wait for two seconds pressing INTO should cause an exit Send the next 8 bits wait 5 seconds and go back to st
47. them off Initialize LEDs Turn them off Set initial value to a counter Set initial value to a counter Increment Decrement the counter Increment Decrement the counter Delay about 0 5 Sec Counter reached final value Counter reached final value Yes Switch the LED toggle the bit Delay about 0 5 Sec Increment Decrement the counter Counter reached final value Yes Turn the LED off Y gt Figure 1 1 Flowcharts for flashing LED Coding Goals All code should be well commented All code added to an existing program for a lab should be identified Ideally ALL documentation is within the program 14 Lab report Submit a report in CourseBook To understand the deliverables look at the Lab 1 Submission form The assembly language code Name Lab 1 program s Purpose This code flashes one LED at approximately 1 Hz frequency Author Rasoul Keshavarzi t xr ufi gir tc are umi tu rar pr yr I tu ger eur RUE M La you THUMB Declare THUMB instruction set AREA My code CODE READONLY EXPORT MAIN Label MAIN is used externally q ENTRY MAIN The following operations can be done in simpler methods They are done in this Way to practice different memory addressing methods MOV moves into the lower word 16 bits and clears the upper word
48. to edit the text Type in LPC1768 FLASH to rename the target The name is appropriate because our program will be written to the Flash memory of the device as opposed to the RAM Next double click on Target 1 or click once on the symbol to show the files under the target Your screen should now match Figure 1 3 Now you are ready to assemble your code This is called Build target in the p Vision software Click on Project tab and then on Build Target The target or binary code written to the LPC1768 should assemble with no errors or warnings Lab0 pVision4 File Edit View Project Flash Debug Peripherals Tools SVCS Window Help ABA AB mmnmmiiiii B 3 Target 1 M X dh Project vax EA Target 1 Source Group 1 E Project 3 Books Func Temp Build Output Figure 1 2 The uVision4 environment 5 pVision4 File Edit View Project Flash Debug Peripherals Tools SVCS Window Help LL d di s 225 7 c a LPC1768 FLASH _ 5 LPC1768 FLASH lt q Source Group 1 startup LPC17xx 5 Lab 0 program s Build target LPC1768 FLASH assembling startup LPC17xx s assembling Lab 0 program s linking Program Size Code 564 RO data 204 RW data 0 ZI data 512 LabO0 axf 0 Error Warningi s Figure 1 3 Building the target 5 12 The next step is to download the program in
49. to the LPC1768 Click on the Flash drop down menu and select Download In order to get the code running press the Reset button on the board a If when downloading the program to the device you receive a SWD Communication Failure message please ensure that you have connected the device to your workstation via it s USB cables b Toeliminate the need to press the Reset button after every download right click on your target LPC1768 FLASH and select Options for Target LPC1768 FLASH and then click the Utilities tab Next click on Settings select the Use Target Driver for Flash Programing click on Flash Download tab and then ensure the checkbox for Reset and Run under the Download Function section is selected 13 You should get an Application running on the message window Your code is now running Using the simulator The uVision software comes with a powerful Simulator and is used to run code when you do not have access to an ARM board Here is how you can switch between debugging on a physical board and the simulator 1 Make sure that you are not in the Debug mode If in Debug mode simply exit from it by clicking on the Debug button 2 Right click on the LPC1768 FLASH and choose the Options for Target LPC1768 FLASH and then click on the Debug tab You should see Figure 1 4 3 You have the option to choose between on Use Simulator on the left pane then you choose ULINK2 ME CORTEX DEBUG the Simulator or the MCB1700 board If y
50. your code Your code must generate no errors when assembled before you activate the Debug mode The Debug mode can be used both with the Simulator or the board itself When debugging using the board every instruction will be executed on the MCB1700 and the results are communicated over the ULINK2 ME Cortex Debugger Be sure that your workstation is physically connected to the board via the USB cables otherwise communication will not be possible If Simulator is chosen then the board is not used at all during the debug mode Follow these instructions in order to step through debug your code 1 Make sure you are using the board and not the simulator for the following steps see section Using the Simulator 2 Choose Start Stop Debug Session from the Debug drop down menu 3 Click OK when presented with the message about being in Evaluation Mode Your screen should now resemble Figure 1 5 4 Make note of the following important buttons in the graphical user interface GUI gt Halala From left to right Reset Run Stop Step Step Over Step Out Run to Cursor Line Show Next Statement Command Window Disassembly Window Symbol Window Registers Window Call Stack Window Watch Windows Memory Windows Serial Windows Analysis Windows Trace Windows System Viewer Windows Toolbox Debug Restore Views 5 Click on the Reset button The arrow should point to the line LDR RO MAIN 6 Click

Download Pdf Manuals

image

Related Search

Related Contents

go live 5 user manual  Et aussi... Franqueville Saint-Pierre à Graines de Jardin 2012 « le    Descargar documentación  GE WES1130 Microwave Oven User Manual  TABLA DE CONTENIDO - Superintendencia de Industria y Comercio  3ウェイタイプ 取扱説明書  取扱説明書 - ELECOM  TAINET Scorpio 1400 A/D/G G.SHDSL Termination Unit User`s Manual  Eco-LogicProgrammateur intérieur à 4 et 6 stations  

Copyright © All rights reserved.
Failed to retrieve file