Presentation is loading. Please wait.

Presentation is loading. Please wait.

EECE.3170 Microprocessor Systems Design I

Similar presentations


Presentation on theme: "EECE.3170 Microprocessor Systems Design I"— Presentation transcript:

1 EECE.3170 Microprocessor Systems Design I
Instructor: Dr. Michael Geiger Spring 2016 Lecture 28: PICkit introduction

2 Microprocessors I: Lecture 28
Lecture outline Announcements/reminders HW 7 to be posted today; due 4/20 by 1:00 PM HW 8: Working with PICkits—groups of up to 4 (3 preferred) Cannot check out kit without a group before 4/22 Due 4/29 by 1:00 PM Will get extra points if HW submitted and PICkit returned early 10% by 11:00 AM, Friday, 4/22 5% by 1:00 PM, Monday, 4/25 Review Sample programming sequences: delay, state machine Today’s lecture: working with PICkit Assembler directives MPLAB IDE Working with existing projects Simulator In-circuit debugging Sample programs in assembly and C 4/27/2019 Microprocessors I: Lecture 28

3 Review: A Delay Subroutine
4/27/2019 Review: A Delay Subroutine ; *********************************************************************************** ; TenMs subroutine and its call inserts a delay of exactly ten milliseconds ; into the execution of code. ; It assumes a 4 MHz crystal clock. One instruction cycle = 4 * Tosc. ; TenMsH equ 13 ; Initial value of TenMs Subroutine's counter ; TenMsL equ 250 ; COUNTH and COUNTL are two variables TenMs nop ; one cycle movlw TenMsH ; Initialize COUNT movwf COUNTH movlw TenMsL movwf COUNTL Ten_1 decfsz COUNTL,F ; Inner loop goto Ten_1 decfsz COUNTH,F ; Outer loop goto Ten_1 return 4/27/2019 Microprocessors I: Lecture 28 Chapter 9

4 Review: Strategy to “Blink”
The LEDs are toggled in sequence - green, yellow, red, green, yellow, red… Let’s look at the lower three bits of PORTD 001=green, 010=yellow, 100=red The next LED to be toggled is determined by the current LED. 001->010->100->001->… 4/27/2019 Microprocessors I: Lecture 28

5 Coding “Blink” with Table Use
BlinkTable movf PORTD, W ; Copy present state of LEDs into W andlw B' ' ; and keep only LED bits addwf PCL,F ; Change PC with PCLATH and offset in W retlw B' ' ; (000 -> 001) reinitialize to green retlw B' ' ; (001 -> 010) green to yellow retlw B' ' ; (010 -> 100) yellow to red retlw B' ' ; (011 -> 001) reinitialize to green retlw B' ' ; (100 -> 001) red to green retlw B' ' ; (101 -> 001) reinitialize to green retlw B' ' ; (110 -> 001) reinitialize to green retlw B' ' ; (111 -> 001) reinitialize to green In calling program call BlinkTable ; get bits to change into W xorwf PORTD, F ; toggle them into PORTD 4/27/2019 Microprocessors I: Lecture 28

6 PIC microcontroller programming
Done through MPLAB IDE Allows for generation of projects in assembly or in C Options to generate initialization code In-circuit debugger to view device state while hardware is actually running 4/27/2019 Microprocessors I: Lecture 28

7 PIC assembler directives
banksel label Changes BSR to bank containing label Example: banksel TRISC cblock/endc Used to define a block of variables org address Indicates starting address for block of code that follows Address 0 in simple programs (initial PC value) #include file Typically used to include processor-specific definitions, macros 4/27/2019 Microprocessors I: Lecture 28

8 Example 1: Light single LED (.asm)
Start: banksel TRISC ;select bank1 bcf TRISC,0 ;make C0 an output banksel LATC ;select bank2 clrf LATC ;initialize the ; LATCH by ; turning off ; everything bsf LATC,0 ;turn on LED C0 (DS1) goto $ ;sit here forever! end 4/27/2019 Microprocessors I: Lecture 28

9 Microprocessors I: Lecture 28
Example 1 notes (.asm) TRISC: controls state of Port C pins TRISC bits = 1  corresponding pins are inputs TRISC bits = 0  corresponding pins are outputs LATC: used for writing data to Port C Equivalent to writing to PORTC register Convention: for input, read PORTC; for output, write LATC Infinite loop at end $ symbol—special label for current instruction 4/27/2019 Microprocessors I: Lecture 28

10 Example 1: Light single LED (C)
void main(void) { TRISCbits.TRISC0 = 0; // Pin 0 = // output LATC = 0; //clear all pins to 0 LATCbits.LATC0 = 1; // turn ON LED while(1) continue; } 4/27/2019 Microprocessors I: Lecture 28

11 Microprocessors I: Lecture 28
Example 1 notes (C) Can access entire registers by name To access individual bits, use form: regnamebits.regname# Example: TRISCbits.TRISC0 = 0; 4/27/2019 Microprocessors I: Lecture 28

12 Microprocessors I: Lecture 28
Running program Choose target device under File  Project Properties Either use PICkit3 or Simulator Compilation Clean and Build Make and Program Device (PICkit3 only) Separate options required for debug configuration Click arrow on right of button to build/make for debug Window  PIC Memory Views Allows you to view file registers and/or SFRs 4/27/2019 Microprocessors I: Lecture 28

13 Microprocessors I: Lecture 28
Final notes Next time: Working with delay Reminders: HW 7 to be posted today; due 4/20 HW 8: Working with PICkits—groups of up to 4 (3 preferred) Cannot check out kit without a group before 4/22 Will get extra points if HW submitted and PICkit returned early 10% by 11:00 AM, Friday, 4/22 5% by 1:00 PM, Monday, 4/25 4/27/2019 Microprocessors I: Lecture 28


Download ppt "EECE.3170 Microprocessor Systems Design I"

Similar presentations


Ads by Google