Les 4 - onderwerpen
description
Transcript of Les 4 - onderwerpen
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
1
Les 4 - onderwerpen
• DB038 hardware : luidsprekertje• DB038 hardware : LED displays• Aansturen van één 7-segment display
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
2
Als je voor loopt (of ‘s nachts niet kan slapen) : denk alvast na over je eind-opdracht
De laatste twee lessen (+ projectweek en thuis!) ga je werken aan een ‘vrije’ opdracht. Verzin zelf een project(je). Stem af. Schijf zelf de opdracht.
citeria:• Niet te makkelijk• Niet te moeilijk• Externe hardware gebruiken is een plus (maar zeker niet verplicht)• In principe individueel, eventueel met meer• Externe info (code!) mag, maar wees er duidelijk over
De opgave moet in overleg met de docent worden vastgesteld. Zie DB038 manual 6.3 en 6.4 voor inspiratie.
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
3
DB038‘Luid’sprekertje
extern
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
4
DB038 circuit – PIC
DB038 manual 2.1
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
5
DB038 circuit – luidspreker
DB038 manual 2.14
Externe luidspreker
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
6
piepen
• RE0..RE3 output, waarde 0x02• RA1 output• En nu maar ‘knipperen’ op RA1
DB038 manual 2.14.1
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
7
opdrachten les 4 - 1 : sirene• Schrijf een piep-subroutine met twee parameters: de tijdvertraging,
uitgedrukt in 10 µs per fase, en het aantal pulsen, uitgedrukt in 10 pulsen. (Dus: piep(3,10) is 100 periodes van 60 µs per periode.) Je kan maar 1 waarde in W meegeven, dus de andere waarde (of eventueel beiden) moet in een afgesproken geheugenplaats staan.
• Schrijf een piep macro om het aanroepen van die piep subroutine wat makkelijker te maken. De macro heeft twee argumenten (beide vaste getallen): de tijdsvertraging, en het aantal pulsen.
• Je hoofdprogramma moet dit doen:While(1) {
Piep gedurende 1 seconde op 1 kHz (=1000Hz)0.1 seconde stiltePiep gedurende 1/2 seconde op 2 kHz0.5 seconde stilte
}
• 2 kHz wat is dan de tijdvertraging?• 1/2 seconde op 2 kHz hoeveel pulsen is dat?
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
8
DB038 4 x 7-segment LED display
8 LEDs
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
9
DB038 circuit – H multiplexer
DB038 manual 2.7
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
10
DB038 circuit – LEDs and displays
DB038 manual 2.9
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
11
Maak pinnen outputs(gebeurt al in DB038-1.inc)
; 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
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
12
Selecteer en activeer LEDs(gebeurt al in DB038-1.inc)
; activate the LEDs
BSF PORTA_SHADOW, 2
CALL PORTA_FLUSH
MOVLW H'04'
MOVWF PORTE_SHADOW
CALL PORTE_FLUSH
MOVLW H'55' ^ H'FF'
MOVWF PORTD_SHADOW
CALL PORTD_FLUSH
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
13
Aansturen van één 7-segment display
• Pinnen output maken, RA2 hoog maken:
(gebeurt al in DB038-01.inc)
• Selecteer het meest rechter display:
Schrijf de juiste waarde naar poort E
• Activeer de juiste segmenten:
Schrijf de juiste waarde naar poort D
DB038 manual 2.9.4
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
14
segment letters
AB
C
D
E
F
G
DP
http://en.wikipedia.org/wiki/Seven-segment_display
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
15
segment letters
PIC pin Display Segment
RD0 A
RD1 B
RD2 C
RD3 D
RD4 E
RD5 F
RD6 G
RD7 DP
let op: active low !
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
16
BCD/binair zeven-segment
We moeten dus een getal (0..F) omzetten naar een bitpatroon dat de juiste segmenten aan zet.
byte zet_om_naar_zeven_segment( byte x ){
if( x == 0 ) return 0x15;
if( x == 1 ) return 0x21;
. . .
}
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
17
zet_om_naar_zeven_segment :cblock
temp7endcmovwf temp7; check temp7 == 1; skip if <>; return 0x21
byte zet_om_naar_zeven_segment( byte x ){
if( x == 0 ) return 0x15;
if( x == 1 ) return 0x21;
. . .
return 0x11;
}
2PROJ5 – PIC assembler
Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
18
opdrachten les 4 - 2 : hexadecimaal tellen op 1 zeven-segment display
tel op de 1 cijfer van het 7-segment display van 0 tot F (en dan weer opnieuw, bv 1 tikken per seconde)
Gebruik een conversie subroutine om te vertalen van een getal (0..F) naar het bitpatroon van de segmenten.