Upload
maite-york
View
33
Download
5
Embed Size (px)
DESCRIPTION
Wouter van Ooijen Mail: [email protected] Sheets en verdere info: www.voti.nl/hvu/V1TH04 (deze link staat ook op sharepoint) Onderwerp: PIC assembler programmeren Materiaal: - PIC USB target board ( € 70 ) - handouts etc (worden uitgedeeld) - PowerPoint PPT Presentation
Citation preview
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 1
Wouter van Ooijen
Mail: [email protected]
Sheets en verdere info:
www.voti.nl/hvu/V1TH04
(deze link staat ook op sharepoint)
Onderwerp: PIC assembler programmeren
Materiaal: - PIC USB target board (€ 70 )
- handouts etc (worden uitgedeeld)
- (thuis) PC met XP of Vista (met USB)
- Memory stick
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 2
Wat er van u verwacht wordt
• U bent (op tijd!) aanwezig
• Theorie in C03.14 (vanaf 10;50), praktijk in D01.12• De eerste weken iedere week een of meer opgave(n)
• De opgaven moeten voor de volgende les klaar zijn
• U maak de opgave(n) zelf
• De opgaven worden beoordeeld op werking, code en begrip
• De laatste weken een individueel projectje
• Het resultaat van het projectje is uw cijfer, mits alle voorgaande opgaven voldoende, en op tijd (anders minpunten!)
• Er is dus geen tentamen, geen projectverslag, etc.
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 3
Wat er van u verwacht wordt
• De opgaven zijn individueel• Code schrijft u zelf• Overleg mag, maar zorg dat je het uiteindelijk zelf
ook begrijpt• Copy-and-paste is dus niet toegestaan
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 4
Onderwerpen voor vandaag
• wat is een microcontroller
• wat is assembler
• hoe werk je met een microcontroller
• eerste stappen in PIC assembler
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 5
Wat is een microcontroller?
meestal: ‘computer-achtig’ ding (computertje) combinatie van processor, ROM, RAM, I/O, ... compact goedkoop zuinig geschikt voor real-time geschikt voor embedded gebruik
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 6
Wat is assembler?
• De meeste directe manier om een CPU te programmeren
• Veel werk voor de programmeur
• Een stuk beter dan binair, hex of met schakelaars programmeren ...
• Regel-georienteerd
• (meestal) 1 regel 1 CPU instructie
• maar ook: het programma dat een in assembler geschreven programma vertaalt (de ‘compiler’)
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 7
; delay
movlw H'00'
delay_loop:
addlw H'01'
skpz
goto delay_loop
een assembler fragment
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 8
PIC16F887• 40-pins chip, max. 35 beschikbaar als I/O
• met kristal maximaal 20 MHz (interne osc 8 MHz)
• 8k code (14-bit instructies)
• 368 general purpose registers (RAM)
• 256 bytes EEPROM
• Diverse peripherals (bv A/D, timers, UART, PWM)
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 9
PIC programming model
• W (accumulator) – het enige echte ‘register’
• Geheugen, adressen 0 .. 0x1FF (512), waarin oa:
– File registers (memory, RAM)
– Flags – die zitten dus in het ‘geheugen’!
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 10
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 11
File Registers (SFR, GPR)
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 12
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 13
a represents an address, [ a ] the (byte) content of that address
Literal to W, W to file, file to W
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 14
MOVF H’20’, W
MOVWF H’21’
MOVLW H’30’
MOVWF H’31’
Wat doet dit code fragment?
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 15
W
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 16
a represents an address, [ a ] the (byte) content of that address, n a (byte) literal
Arithmetic instructions - diadic
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 17
Arithmeticinstructions
- diadic
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 18
MOVF H’20’, w
ADDWF H’21’, w
MOVWF H’21’
Wat doet dit code fragment?
Hoe kan dit korter?
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 19
a represents an address, [ a ] the (byte) content of that address
Arithmetic instructions - monadic
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 20
Arithmeticinstructions- monadic
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 21
RLF H’30’, w
MOVFW H’31’
RRF H’32’, f
Wat doet dit code fragment?
Het maakt niet uit of je hoofdletters of kleine letters gebruikt, maar CaMelCaSe werkt niet.
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 22
a represents an address, [ a ] the (byte) content of that address, n a (byte) literal,
b a 3-bit literal (a bit number, 0..7), X : b represents bit b of X
Bit set and clear
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 23
Bit set and clear
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 24
BSF H’03’, 0
RRF H’32’, f
Wat doet dit code fragment?
Zoek in de INSTRUCTION SET SUMMARY op hoe de RRF instructie precies werkt.
Wat gebeurt er als je de BSF instructie weg laat?
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 25
gotocall
return
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 26
Start:CALL MainHALT
Spagetti:MOVLW 1CALL spinazieGOTO spinazieMOVLW 2
Spinazie:MOVLW 3RETURNMOVLW 4
Main:MOVLW 5CALL spagettiMOVLW 6
In welke volgorde worden de MOVLW instructies uitgevoerd?
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 27
a represents an address, [ a ] the (byte) content of that address
Conditional skips
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 28
Conditionalskips
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 29
diversen
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 30
Assembler build-in macro’s
SKPZ = btfss 3, 2
SKPNZ
SKPC
SKPNC
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 31
movlw 5movwf h’30’btfsc h’30’, 0
movlw 12btfss h’30’, 1
movlw 13addlw 252skpz
movlw 14skpnc
movlw 15
In welke MOVLW instructies worden uitgevoerd?
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 32
wat doet dit stukje assembler code?
; delay
movlw H'00'
delay_loop
addlw H'01'
skpz
goto delay_loop
nb: skpz == btfss 3, 2
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 33
oefening 1
Op geheugenplaatsen H’20’ en H’21’ staan 2 getallen. Schrijf een programma dat deze getallen optelt en het resultaat in H’22’ plaatst
(3 instructies)
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 34
oefening 2
Op geheugenplaatsen H’20’ en H’21’ staan 2 getallen. Zet het grootste van deze twee getallen in geheugenplaats H’22’.
(diverse oplossingen mogelijk, bv 8 instructies)
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 35
Oefening 3
Op geheugenplaatsen H’20’ en H’21’ staan 2 getallen. Vermenigvuldig deze getallen en plaats het resultaat in H’22’. Na afloop mogen de getallen in H’20’ en H’21’ veranderd zijn.
(diverse oplossingen mogelijk, bv 10 instructies. Tip: vermenigvuldigen is herhaald optellen, evt eerst uitschrijven in C of Java)
V1TH04 – PIC assembler
Hogeschool Utrecht / Institute for Information & Communication Technology
1 - 36
Doen
neem de slides nog eens door noteer wat je niet duidelijk is ! neem € 70 mee voor het bordje (gepast!) schrijf de programma’s voor de oefeningen(mag op papier, of in notepad, etc )dit moet voor volgende week af zijn!!
let goed op het verschil tussen MOVLW en MOVWF/MOVF/MOVFW.