Les 3 - onderwerpen
description
Transcript of 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
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();}
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
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?
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
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
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
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
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
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
10
PIC16F887 memory map
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
11
PIC –register bank selection
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)
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
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 ....
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
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
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>
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
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
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
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
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
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
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)
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)
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
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
27
PICkit 2 V1.20
• Zet target 5.0V aan
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
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?
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!