1 / 30

Les 3 - onderwerpen

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*

stella
Download Presentation

Les 3 - onderwerpen

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Een W * 1 ms delay int i = W; while( i > 0 ){ i--; Delay_1ms(); } 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 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? 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 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  6. Een paar instructies vertraging (2) nop4: macro nop nop nop nop enmd loop: nop nop4 nop4 nop4 nop4 decfsz teller, f goto loop Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  7. Een paar instructies vertraging (3) cblock teller endc movlw D’250’ movwf teller loop: nop call delay_4 call delay_4 call delay_4 call delay_4 decfsz teller, f goto loop delay_4: return Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  8. Een paar instructies vertraging (4) cblock teller endc movlw D’250’ movwf teller loop: nop call delay_16 decfsz teller, f goto loop delay_16: call delay_4 delay_12: call delay_4 delay_8: call delay_4 delay_4: return Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  9. Een paar instructies vertraging (5) delay_2: macro goto $+1 endm delay_4: macro delay_2 delay_2 endm delay_8: macro delay_4 delay_4 endm delay_16: macro delay_8 delay_8 endm 9 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  10. PIC16F887 memory map Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  11. PIC –register bank selection 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) Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  13. DB038 8 LEDs Programming connector Programming activity LED Power LED reset Power source (zet de jumper rechts) 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 .... 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 ;================================================================ SLEEP END Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  16. DB038-01.INC • Includes the Microchip16F887 include file (register definitions) • Sets the configuration word(s) (oa. 20 MHz crystal, external reset) • ORG 0, CBLOCK H’20’ • PORTx_SHADOW, PORTx_FLUSH (x = A,B,C,D) • WWAIT subroutine – die mogen jullie niet gebruiken • Initialises TRIS (direction) registers • Beeps • Activates LEDS, pattern 0x55 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 format LIST p=16f887, f=inhx32 ; include target chip stuff #include <P16F887.INC> 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 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  19. DB038-01.INC (3) ; start code at 0 ORG 0 ; start variables at 0x20 CBLOCK H'20' ENDC ; skip subroutines GOTO WContinue Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  20. DB038-01.INC (4) ; =========================================================== ; shadow registers and flush subroutines FLUSH_MACRO MACRO Shadow, Port CBLOCK Shadow ENDC MOVFW Shadow MOVWF Port RETURN ENDM PORTA_FLUSH FLUSH_MACRO PORTA_SHADOW, PORTA PORTB_FLUSH FLUSH_MACRO PORTB_SHADOW, PORTB PORTC_FLUSH FLUSH_MACRO PORTC_SHADOW, PORTC PORTD_FLUSH FLUSH_MACRO PORTD_SHADOW, PORTD PORTE_FLUSH FLUSH_MACRO PORTE_SHADOW, PORTE Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  21. DB038-01.INC (5) ; =========================================================== ; WWAIT WWAIT CBLOCK WWaitCounter ENDC MOVLW 0x00 MOVWF WWaitCounter WWaitLoop CALL WWaitReturn DECFSZ WWaitCounter, f GOTO WWaitLoop WWaitReturn RETURN 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 0xD8 MOVWF ( 0x80 ^ TRISA ) MOVLW 0x00 MOVWF ( 0x80 ^ TRISD ) MOVLW 0xF8 MOVWF ( 0x80 ^ TRISE ) BCF STATUS, RP0 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  23. DB038-01.INC (7) ; =========================================================== ; beep CBLOCK WBeepCounter ENDC CLRF WBeepCounter MOVLW H'02' MOVWF PORTE_SHADOW CALL PORTE_FLUSH WBeepLoop BSF PORTA_SHADOW, 1 CALL PORTA_FLUSH CALL WWAIT BCF PORTA_SHADOW, 1 CALL PORTA_FLUSH CALL WWAIT DECFSZ WBeepCounter, f GOTO WBeepLoop Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  24. DB038-01.INC (8) ; =========================================================== ; activate the LEDs MOVLW H'04' MOVWF PORTE_SHADOW CALL PORTE_FLUSH MOVLW H'55' ^ H'FF' MOVWF PORTD_SHADOW CALL PORTD_FLUSH ; the students' application follows ; (in the file that includes this file) Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  25. PICkit 2 V1.20 • Gebruik V1.20 !!! • Device Family > Midrange (14 bit core) 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 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  27. PICkit 2 V1.20 • Zet target 5.0V aan Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  28. PICkit 2 V1.20 • Zet programmeren van de Data EEPROM (voorlopig) uit 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? 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! Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

More Related