les 3 - onderwerpen

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

Upload: sonel

Post on 19-Mar-2016

33 views

Category:

Documents


0 download

DESCRIPTION

Les 3 - onderwerpen. Hints voor ‘delay’ Register file banks Gebruik van het DB037 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

Page 1: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

12PROJ5 – PIC assembler

Les 3 - onderwerpen

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

Page 2: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

22PROJ5 – PIC assembler

Een W * 1 ms delay

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

Page 3: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

32PROJ5 – PIC assembler

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

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

42PROJ5 – PIC assembler

Een Delay_1ms

cblock teller

endc

movlw D’250’movwf teller

loop:decfsz teller, f

goto loop

Page 5: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

52PROJ5 – PIC assembler

Een paar instructies vertraging (1)

loop: nop ; 17 NOPs...nop

decfsz teller, f goto loop

Page 6: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

62PROJ5 – PIC assembler

Een paar instructies vertraging (2)nop4: macro

nopnopnopnopenmd

loop: nopnop4nop4nop4nop4 decfsz teller, f

goto loop

Page 7: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

72PROJ5 – PIC assembler

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

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

82PROJ5 – PIC assembler

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

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

92PROJ5 – PIC assembler

PIC16F887 memory map

Page 10: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

102PROJ5 – PIC assembler

PIC –register bank selection

Page 11: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

112PROJ5 – PIC assembler

DB037

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

Page 12: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

122PROJ5 – PIC assembler

DB037Programming connector

Power source (zet de jumper rechts)

8 LEDs

reset

Programming activity LED

Power LED

Page 13: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

132PROJ5 – PIC assembler

Using DB037

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

Page 14: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

142PROJ5 – PIC assembler

an (empty) DB037 program;================================================================

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

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

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

; put your code here

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

SLEEPEND

Page 15: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

152PROJ5 – PIC assembler

DB037-01.INC1. Includes the Microchip16F877 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 subroutine6. Initialises TRIS (direction) registers7. Beeps8. Activates LEDS, pattern 0x55

Page 16: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

162PROJ5 – PIC assembler

DB037-01.INC (1);================================================================; ; include file for DB037 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 17: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

172PROJ5 – PIC assembler

DB037-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 18: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

182PROJ5 – PIC assembler

DB037-01.INC (3)

; start code at 0ORG 0

; start variables at 0x20CBLOCK H'20'ENDC

; skip subroutinesGOTO WContinue

Page 19: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

192PROJ5 – PIC assembler

DB037-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 20: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

202PROJ5 – PIC assembler

DB037-01.INC (5);

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

WWAITCBLOCK

WWaitCounterENDCMOVLW 0x00MOVWF WWaitCounter

WWaitLoopCALL WWaitReturnDECFSZ WWaitCounter, f

GOTO WWaitLoopWWaitReturn

RETURN

Page 21: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

212PROJ5 – PIC assembler

DB037-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 22: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

222PROJ5 – PIC assembler

DB037-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 23: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

232PROJ5 – PIC assembler

DB037-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 24: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

242PROJ5 – PIC assembler

PICkit 2 V1.20

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

Page 25: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

252PROJ5 – PIC assembler

PICkit 2 V1.20

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

Page 26: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

262PROJ5 – PIC assembler

PICkit 2 V1.20

• Zet target 5.0V aan

Page 27: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

272PROJ5 – PIC assembler

PICkit 2 V1.20

• Zet programmeren van de Data EEPROM (voorlopig) uit

Page 28: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

282PROJ5 – PIC assembler

DB037 bordje – tel op 8 LEDsMain loop:

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

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

Hoe snel zal de meest linker LED ongeveer gaan knipperen?

Page 29: Les 3 - onderwerpen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

292PROJ5 – PIC assembler

DB037 bordje – Kitt Display

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!