Les 3 - onderwerpen

30
2PROJ5 – PIC assembler Hogeschool Utrecht / Institute for Computer, Communication and Media Technology 1 Les 3 - onderwerpen Hints voor ‘delay’ Register file banks Gebruik van het DB038 bord Aftekenen vorige opgaves Twee nieuwe opgaves

description

Les 3 - onderwerpen. Hints voor ‘delay’ Register file banks Gebruik van het DB038 bord Aftekenen vorige opgaves Twee nieuwe opgaves. Een W * 1 ms delay. int i = W; while( i > 0 ){ i--; Delay_1ms(); }. Een Delay_1ms. 5 MIPS, dus 1 ms is 5000 instructies* - PowerPoint PPT Presentation

Transcript of Les 3 - onderwerpen

Page 1: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

1

Les 3 - onderwerpen

• Hints voor ‘delay’• Register file banks• Gebruik van het DB038 bord• Aftekenen vorige opgaves• Twee nieuwe opgaves

Page 2: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

2

Een W * 1 ms delay

int i = W;while( i > 0 ){ i--; Delay_1ms();}

Page 3: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

3

Een Delay_1ms

• 5 MIPS, dus 1 ms is 5000 instructies*• In 8 bit kan je tot 256 tellen, neem 250• 1 keer door de lus moet dan 5000 / 250 =

20 instructies zijn

Page 4: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

4

Delay_1ms : eerste poging

cblock teller

endc

movlw D’250’movwf teller

loop:decfsz teller, f

goto loop

Hoeveel vertraging moeten we nog toevoegen, en waar precies?

Page 5: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

5

Een paar instructies vertraging (1)

loop: nop ; 17 NOPs...nop

decfsz teller, f goto loop

Page 6: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

6

Een paar instructies vertraging (2)nop4: macro

nopnopnopnopenmd

loop: nopnop4nop4nop4nop4

decfsz teller, f goto loop

Page 7: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

7

Een paar instructies vertraging (3)

delay_4: return

cblock teller

endcmovlw D’250’movwf teller

loop:nopcall delay_4call delay_4call delay_4call delay_4decfsz teller, f

goto loop

Page 8: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

8

Een paar instructies vertraging (4)

delay_16: call delay_4delay_12: call delay_4delay_8: call delay_4delay_4: return

cblock teller

endcmovlw D’250’movwf teller

loop:nopcall delay_16decfsz teller, f

goto loop

Page 9: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

9

Een paar instructies vertraging (5)delay_2: macro

goto $+1endm

delay_4: macrodelay_2delay_2endm

delay_8: macrodelay_4delay_4endm

delay_16: macrodelay_8delay_8endm

Page 10: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

10

PIC16F887 memory map

Page 11: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

11

PIC –register bank selection

Page 12: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

12

DB038

Contains:• Target chip: PIC16F887• Programmer: pickit2 clone• Power: from USB (2x), Wall-Wart / NiCad• Peripherals: LSP, LEDs (and much more)

Page 13: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

13

DB038Programming connector

Power source (zet de jumper rechts)

8 LEDs

reset

Programming activity LED

Power LED

Page 14: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

14

Using DB038

• Get count.zip (from my website)• Unzip to new directory (let op path!)• Double-click count.mcp• Edit count.asm• Assemble• Correct errors and repeat ....

Page 15: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

15

an (empty) DB038 program;================================================================

; ; count.asm;;================================================================

; initialisation etc for DB038; also beeps and activated the LEDs#include <DB038-01.INC>

;================================================================; main ;================================================================

; put your code here

;================================================================; end of assembler source;================================================================

SLEEPEND

Page 16: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

16

DB038-01.INC

1. Includes the Microchip16F887 include file (register definitions)

2. Sets the configuration word(s) (oa. 20 MHz crystal, external reset)

3. ORG 0, CBLOCK H’20’4. PORTx_SHADOW, PORTx_FLUSH (x = A,B,C,D)5. WWAIT subroutine – die mogen jullie niet gebruiken6. Initialises TRIS (direction) registers7. Beeps8. Activates LEDS, pattern 0x55

Page 17: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

17

DB038-01.INC (1);================================================================; ; include file for DB038 for a first program;; beeps and activates the LEDs with a 0x55 pattern;;================================================================

; select target chip and hex file formatLIST p=16f887, f=inhx32

; include target chip stuff#include <P16F887.INC>

Page 18: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

18

DB038-01.INC (2)

; configuration settings__config _CONFIG1, 0x20E2 ; -debug, -LVP, -fcmen, -ieso, -boren,

; -cpd, -cp, mclre, pwtre, -wdte, HSosc__config _CONFIG2, 0x3FFF ; nothing special

Page 19: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

19

DB038-01.INC (3)

; start code at 0ORG 0

; start variables at 0x20CBLOCK H'20'ENDC

; skip subroutinesGOTO WContinue

Page 20: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

20

DB038-01.INC (4) ; ===========================================================

; shadow registers and flush subroutines

FLUSH_MACRO MACRO Shadow, PortCBLOCKShadowENDCMOVFW ShadowMOVWF PortRETURNENDM

PORTA_FLUSH FLUSH_MACRO PORTA_SHADOW, PORTAPORTB_FLUSH FLUSH_MACRO PORTB_SHADOW, PORTBPORTC_FLUSH FLUSH_MACRO PORTC_SHADOW, PORTCPORTD_FLUSH FLUSH_MACRO PORTD_SHADOW, PORTDPORTE_FLUSH FLUSH_MACRO PORTE_SHADOW, PORTE

Page 21: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

21

DB038-01.INC (5);

===========================================================; WWAIT

WWAITCBLOCK

WWaitCounterENDCMOVLW 0x00MOVWF WWaitCounter

WWaitLoopCALL WWaitReturnDECFSZ WWaitCounter, f

GOTO WWaitLoopWWaitReturn

RETURN

Page 22: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

22

DB038-01.INC (6)WContinue ; ===========================================================

; A0..A2 and D and E0..E2 are outputs

BSF STATUS, RP0

MOVLW 0xD8MOVWF ( 0x80 ^ TRISA )

MOVLW 0x00MOVWF ( 0x80 ^ TRISD )

MOVLW 0xF8MOVWF ( 0x80 ^ TRISE )

BCF STATUS, RP0

Page 23: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

23

DB038-01.INC (7) ; ===========================================================

; beep

CBLOCKWBeepCounter

ENDCCLRF WBeepCounterMOVLW H'02'MOVWF PORTE_SHADOWCALL PORTE_FLUSH

WBeepLoopBSF PORTA_SHADOW, 1CALL PORTA_FLUSHCALL WWAITBCF PORTA_SHADOW, 1CALL PORTA_FLUSHCALL WWAITDECFSZ WBeepCounter, f

GOTO WBeepLoop

Page 24: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

24

DB038-01.INC (8) ; ===========================================================

; activate the LEDs

MOVLW H'04'MOVWF PORTE_SHADOWCALL PORTE_FLUSH

MOVLW H'55' ^ H'FF'MOVWF PORTD_SHADOWCALL PORTD_FLUSH

; the students' application follows; (in the file that includes this file)

Page 25: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

25

PICkit 2 V1.20

• Gebruik V1.20 !!!• Device Family > Midrange (14 bit core)

Page 26: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

26

PICkit 2 V1.20

• Selecteer de .hex file die je in MPLAB hebt aangemaakt: <project name>.HEX

Page 27: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

27

PICkit 2 V1.20

• Zet target 5.0V aan

Page 28: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

28

PICkit 2 V1.20

• Zet programmeren van de Data EEPROM (voorlopig) uit

Page 29: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

29

opgave 1 – tel op 8 LEDs (DB038 bord) Main loop:

– Tel in een variabele– Copieer die naar PORTD– Wacht 4 ms (gebruik je wacht subroutine)

Allokeer je variabelen nu en voortaan altijd op de nette manier (cblock).

Hoe snel zal de meest linker LED ongeveer gaan knipperen?

Page 30: Les 3 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

30

Opgave 2 – Kitt Display (DB038 bord)

Maakt een ‘Kitt’ display op de 8 LEDs. (Kitt patroon is: steeds 1 LED aan, de LED die aan is ‘beweegt’ heen-en-weer). NB: 4 ms voor een stap is nu een beetje te snel!