Les 5 - onderwerpen

21
2PROJ5 – PIC assembler Hogeschool Utrecht / Institute for Computer, Communication and Media Technology 1 Les 5 - onderwerpen DB038 hardware : 7-segment display multiplexen 16F887 / DB038 hardware : A/D conversie 16F887 : memory banks Opdracht1 : decimaal tellen op 4 displays Opdracht2 : A/D conversie Lees van de DB038 manual hoofdstuk 3 door (PIC 14-bit architecture and instruction set summary)

description

Les 5 - onderwerpen. DB038 hardware : 7-segment display multiplexen 16F887 / DB038 hardware : A/D conversie 16F887 : memory banks Opdracht1 : decimaal tellen op 4 displays Opdracht2 : A/D conversie - PowerPoint PPT Presentation

Transcript of Les 5 - onderwerpen

Page 1: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

1

Les 5 - onderwerpen

• DB038 hardware : 7-segment display multiplexen• 16F887 / DB038 hardware : A/D conversie• 16F887 : memory banks• Opdracht1 : decimaal tellen op 4 displays• Opdracht2 : A/D conversie

Lees van de DB038 manual hoofdstuk 3 door (PIC 14-bit architecture and instruction set summary)

Page 2: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

2

multiplexen

Laat Digit 1 zien (wacht)

Doe eventueel ander werk

Laat Digit 2 zien (wacht)

Laat Digit 3 zien (wacht)

Laat Digit 4 zien (wacht)

Page 3: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

3

Ghosting bij multiplexen

Laat een digit zien:• (RA2 is hoog)• Zet het nieuwe adres op RE0..RE2• Zet het nieuwe segment-patroon op RD0..RD7• Wacht 1 ms

- Wat gaat hier (heel even) fout?- Hoe is dit op te lossen?

Page 4: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

4

DB038 – multiplexers

DB038 manual 2.8

Page 5: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

5

PIC – A/D

A/D converter vertaald een analoge spanning naar een waarde 0..255 (8 bits) of 0..1023 (10 bits)

RA0

16F887 datasheet p 99-108

Page 6: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

6

PIC – A/D – configure pin as analog

16F887 datasheet p 99-108

Page 7: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

7

PIC – A/D – aan zetten

16F887 datasheet p 99-108

Page 8: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

8

PIC – A/D – channel

16F887 datasheet p 99-108

Page 9: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

9

PIC – A/D – clock

16F887 datasheet p 99-108

Page 10: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

10

PIC – A/D – start, wait

16F887 datasheet p 99-108

Page 11: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

11

PIC – A/D – start, wait

16F887 datasheet p 99-108

Page 12: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

12

PIC – A/D – result format

16F887 datasheet p 99-108

Page 13: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

13

PIC – A/D – enable, go / done

16F887 datasheet p 99-108

Page 14: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

14

Read an analog input• Zet de juiste code op poort RE• Configureer de pin (RA0) als input (TRISA)• Configureer de pin (RA0 = AN0) in ANSEL als analoog• Activeer de A/D, selecteer het betreffende kanaal, selecteer

de conversie clock (ADCON0)• Selecteer VSS en VDD als referenties, en de alignment

(ADCON1)• wacht 100 us• start de conversie (ADCON0)• wacht tot de conversie voltooid is (ADCON0)• lees het resultaat (ADRESH, eventueel ADRESL)

Page 15: Les 5 - onderwerpen

2PROJ5 – PIC assembler

• Maak pin RA1 een ingang (bit 1 in TRISA)• Maak poort A een digitale poort:

ANSEL = 0CMCON0 = 0x07

• Zet een waarde 0x01, 0x02, 0x04 of 0x08 op PORTD• Zet een waarde 4 .. 7 op PORTE• Wacht ten minste 10 µs• Lees pin RA1 (hoog == toets is ingedrukt)• Doe dit voor alle 16 toetsen

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

15

PIC16F887 memory map

Page 16: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

16

PIC –register bank selection

Page 17: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

17

banksel

0063 1683 1303 00099 banksel TRISA0065 1485 00100 bsf ( TRISA & 0x7F ), 1 00101 0066 1683 1703 00102 banksel ANSEL0068 0188 00103 clrf ( ANSEL & 0x7F ) 00104 0069 1283 1303 00105 banksel 0

banksel TRISAbsf ( TRISA & 0x7F ), 1

banksel ANSELclrf ( ANSEL & 0x7F )

banksel 0

Gebruik dus altijd banksel, en schakel terug naar bank 0!DB038 manual 3.9

Page 18: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Code paging

11 bits == maar 2k instructies...

Page 19: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Code paging

Als je minder dan 2k code gebruikt geen probleem

Anders: GOTO LGOTOCALL LCALL

Maar: LGOTO en LCALL worden vertaald naar meerdere instructies, dus je kan niet skippen! Wel kan:

PAGESEL daarzoSKPNZ

GOTO daarzoDB038 manual 3.8

Let op pagesel – banksel !

Page 20: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

20

Opdracht 1 : tel decimaal op 4 zeven-segment displays

Declareer 4 bytes waarin je 4 decimale digits (getallen) opslaat.

Maak een verhoog subroutine die de 4-dgit decimale waarde met 1 verhoogt. Let op de carry van een digit naar een hoger digit.

Laat de nieuwe waarde zien op de zeven-segment displays.

Weer verhogen, weer laten zien, etc. Zorg dat je maar 1 in de zoveel keer verhoogt.

Page 21: Les 5 - onderwerpen

2PROJ5 – PIC assembler

Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

21

oefening 2 : A/D, display

Schrijf een programma dat de potentiometer uitleest en (hexadecimaal) weergeeft op de rechter twee 7-segment displays.