microcontrollers 8051 based microcontroller xc888 from infineon 08/2011 roggemans m. (mgm)

119
Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Upload: louisa-van

Post on 04-Jun-2015

232 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Microcontrollers

8051 based microcontrollerXC888 from Infineon

08/2011Roggemans M. (MGM)

Page 2: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

LES 1

• Doelstellingen:– situering vak, afspraken labo en evaluatie toelichten– concept embedded oplossing probleem– blokdiagramma computersysteem– wat is een microcontroller?– hoe ziet een basis 8051 er uit– XC888 mogelijkheden en blokdiagramma– memorymap 8051/XC888– MOV instructies (inwendige adressering)

Page 3: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Situering van het vak

• Embedded systemen• Hardware georienteerd• Hoort bij interfacetechnieken• Basis voor embedded systemen derde jaar• Basis voor “C” programmeren• Specifieke uitwerking onderdeel

computersystemen

Page 4: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Afspraken Labo Microcontrollers

• Aanwezigheid niet verplicht• Passieve aanwezigheid verboden• Actieve participatie verplicht

• Misbruik infrastructuur verboden:– niet eten of drinken in labo– respect voor apparatuur

• Stiptheid verplicht!!

Page 5: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Cursusmateriaal

• Nederlandstalige cursus:– thuis lezen als herhaling/voorbereiding les (min 5X)

• XC888 condensed (onmisbaar in labo)

• Stick:– bevat info van telescript (onmisbaar in labo)

– bevat eigen programma’s (onmisbaar in labo)

• XC888 microcontroller kit met USB kabel (onmisbaar in labo)

• Slides (PPT) (beknopte versie cursus) (onmisbaar in labo)

Page 6: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Evaluatie

• GEEN permanente evaluatie:– lessen zijn er om te oefenen en vragen te stellen

• Open boek examen (praktische opgave):– vak kan je enkel leren door te doen!!!– vak vraagt zekere incubatietijd!!!– blok en examenperiode onvoldoende tijd!!!

• Je mag op het examen alles gebruiken behalve communicatiemiddel of laptop

Page 7: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Examenverloop en quotering

• Opgave beschikbaar op papier (moet je afgeven)• Je moet op de PC’s van het labo werken• Examen duurt 1,5u

Puntenverdeling:• Flowchart (5/20) (DIGITALE BEOORDELING)

• Werkt het programma 100% (5/20) (DIGITALE BEOORDELING)

• Programma (10/20) (ANALOGE BEOORDELING)

Page 8: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Concept embedded oplossing probleemVoedingsspannings-

bewakingSysteemvoeding Systeemclock

T sensor

Vref (DC)

CPU8/16/32 bit

AnalogeI/O

poort

Businterface

JTAGinterface

Timer/Countercircuits

Seriële interface

Debugsysteem (PC)

Adresbus

Databus

Signaalbewerking

Opto-coupler

Digitale I/O poort Digitale I/O poort

Powersavingmodes

Netspanning Batterij

Analogesignalen

SignaalbewerkingAnaloge

ingang

Analogeuitgang

Schakelaar

Galvanischgescheiden

digitale ingang

I2CSPIUSB

UART

MICROCONTROLLER

Externeinterruptingangen

Externebusinterface

Digitale signalen

ADC

DAC

I supply

Page 9: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Concept embedded oplossing probleem

• Universele hardware• Relatie tussen input en output :

• eenvoudig aanpasbaar (software=programma)• kan afhankelijk zijn van input en output (adaptief(remmen voertuig))• kan gebaseerd zijn op ervaringsgegevens (FUZZY)• is aanpasbaar nadat product verkocht is (firmware upgrade)• aanpasbaar aan voorkeuren gebruiker

+, -, x, /logische bewerkingen

voorwaardelijke beslissingen

Input:schakelaarsspanningen

seriëelsensoren

...

Output:spanningen

LED'scontactoren

motorenseriëel

...

Page 10: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Blokdiagramma computersysteem

CPU

X-talOsc.

PORADRES

DECODER

ROM(FLASH)(EPROM)

(EEPROM)

SRAM

ADRESBUS

DATABUS

PAR.POORT

SER.POORT

TIMERCOUNTER

Page 11: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Wat is een microcontroller?

Page 12: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Voordelen microcontroller (t.o.v. discrete computer)

• Slechts enkele componenten:– eenvoudige PCB– weinig kans op hardware fouten– betrouwbaar– low cost– kleine afmetingen

Nadeel microcontroller (t.o.v. discrete computer):

– minder flexibel (je koopt een totaal pakket, maar er is wel veel keuze)

– minder rekenkracht/geheugen

Page 13: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CPU

X-talOsc.

PORADRES

DECODER

ROM(FLASH)(EPROM)

(EEPROM)

SRAM

ADRESBUS

DATABUS

PAR.POORT

SER.POORT

TIMERCOUNTER

Basis 8051CPU

X-talOsc.

PORADRES

DECODER

ROM(FLASH)(EPROM)

(EEPROM)

SRAM

ADRESBUS

DATABUS

PAR.POORT

SER.POORT

TIMERCOUNTER

Page 14: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XC888

Page 15: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XC888

Page 16: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Memory map 8051 (XC888)

GPR

00000001

0002

00000001

0002

FFFDFFFEFFFF

FFFD

00040003

00040003

FFFFFFFE

XRAMDATA memory

ROMCODE memory

PROGRAMMA

CPU

Registers

SFR

PIOSIOAD

Timers

00

02

FFFE

8180

FEFF

01

8081

Data bus

Adres bus

RD#

WR#

PSEN#

8 bit 8 bit

MOVC@DPTR

MOVX@DPTR

I/O & control

Read/Write16 bit adres 8 bit adres

Read/WriteRead only

Controlebus

Page 17: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XC888

Page 18: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Memory map 8051 (XC888)

General Purpose Registers

Page 19: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Memory map 8051 (XC888)

Onderste 128 GPR’s

Page 20: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Memory map 8051 (XC888)

SFR’s “oude” 8051

Page 21: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Memory map 8051 (XC888)

SFR’s XC888

Page 22: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Memory map 8051 (XC888)

Page 23: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Effectieve geheugenkaart XC888

Page 24: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

De MOV instructies

Mnemonic OP-CODE Uitvoeringssnelheid Symbolische werking

Page 25: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Alle MOV instructies (tussen registers met 8 bit getallen)

Page 26: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

LES 2

• Doelstellingen:– Testen en verdelen van de hardware– Verkennen van de IDE (Integrated design environment) en

Infineon FLOAT software– Overlopen schema’s XC888 bord– maken programma’s (via sjabloon):

• schakelaars naar LED’s• knipperlicht zonder tijdsvertraging (basis uitvoeringstijd instructies)

• knipperlicht vaste snelheid (met delaya0k05s)

• knipperlicht variabele snelheid (met delaya0k05s)

• looplicht variabele snelheid (rotate instucties)• Knight rider (hehaald gebruik rotate instructies)

Page 27: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Hardware XC888 bord

Page 28: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Hardware XC888 bord

Page 29: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Hardware XC888 bord

Page 30: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Hardware XC888 bord

Page 31: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Hardware XC888 bord

Page 32: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Hardware XC888 bord

Page 33: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Hardware XC888 bord

Page 34: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Hardware XC888 bord

Page 35: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Hardware schakelaars & LED’s

Page 36: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 3

• Doelstellingen:– MOVX en MOVC– looplicht via tabel (DJNZ, CJNE, DB, DPTR)– gebruik van de drivers voor:

• STDIO (herhaling les 2)• Diverse (aanvulling/ herhaling les 2)• LCD• ADC• Arithmetic• IIC

– teller op LCD scherm (8 bit hex en 8 bit decimaal, inc en dec)

Page 37: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

MOVC & MOVX

Page 38: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

DPTR instructies

Page 39: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

DJNZ of lussen tellen

Page 40: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CJNE of getallen testen

Page 41: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XCEZ

; standaard I/O:; initdipswitch klaar zetten poort 4 voor gebruik met de

dipswitch

; initftoetsen klaar zetten 4 functieschakelaars onderaan scherm

; initleds klaar zetten LED's als outputs

Page 42: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XCEZ

; I2C interface (minimale interface op 100kbit/s) enkel master mode!!

; initiic klaar zetten iic interface; iicstart genereren van een startconditie op iic poort; iicstop genereren stop conditie op iic poort; iicinbyteack lezen van 1 byte met ack (accu=output); iicinbytenack lezen van 1 byte met nack (accu=output)

; iicoutbyte schrijven van 1 byte (accu=input, c=waarde ack bit slave)

Page 43: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XCEZ

; LCD interace ; initlcd klaar zetten LCD voor gebruik (incl i2c init); lcdoutchar schrijven van ascii code (accu=input); lcdoutbyte schrijven hex waarde accu naar LCD; lcdoutnib afdrukken 4 laagste bits accu op LCD; lcdoutmsga afdrukken ascii string @dptr, tot 000h code; lcdlighton backlight aan; lcdlightoff backlight uit; lcdbuzon buzzer aan; lcdbuzof buzzer uit

Page 44: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XCEZ

; Seriële interface (via USB stekker!!); initsio klaar zetten seriële poort 9600 baud; siooutchar afdrukken ascii code (accu=input); siooutbyte afdrkken getal in accu ; siooutnib afdrukken 4 laagste bits accu; siooutmsga afdrukken ascii string @dptr tot 000h code; sioinchar inlezen van 1 ascii code in de accu

; sioinbufa inlezen van ascii buffer vanaf adres strtbuf, max 20h karakters!

Page 45: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XCEZ

; ADC; initadc klaar zetten ADC voor minimaal gebruik; adclm335 uitlezen lm35 (a-b) bevat resultaat; adcpotmeter uitlezen van de potmeter (a-b) bevat resultaat

Page 46: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XCEZ; Arithmetic:; mul16 vermenigvuldigen 2 16 bit getallen; mul32 vermenigvuldigen 2 32 bit getallen; div16 delen 2 16 bit getallen; div32 delen 2 32 bit getallen; add16 optellen 2 16 bit getallen; add32 optellen 2 32 bit getallen; sub16 verschil 2 16 bit getallen; sub32 verschil 2 32 bit getallen; hexbcd8 omvormen 8 bit hex naar bcd; hexbcd16 omvormen 16 bit hex naar bcd; bcdhex8 omvormen 8 bit bcd naar hex; bcdhex16 omvormen 16 bit bcd naar hex

Page 47: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XCEZ

; Diverse; delaya0k05s tijdsvertraging (waarde in accu)*0,05s; delay1ms tijdsverraging 1 milliseconde; delay10us tijdsvertraging 10 microseconde; XCsw2xtal overschakelen rc naar kristal (Pauwels Danny); mapregs selecteer de SFR's in de mapped area; nomapregs selecteer de SFR's in de non-mapped area

Page 48: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 4

• Doelstellingen– talstelsels– basis wiskundige berekeningen (+,-,x,/, 8 en 16 bit, CY vlag)

– teller op LCD (een decimaal en een hex, stand dip-switches bij op tellen, een decimaal en een hex stand dip-switches er van aftrekken (4 tellers!!))

– uurwerk in uu:mm:ss, met software delay

Page 49: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Talstelsels

Getal=voorstelling!!Decimaal getal:

– 0, 1, 2, 3, 4, 5, 6, 7, 8, 9– waarde afhankelijk plaats getal 123 1 2 3

Binair getal:– 0, 1– waarde afhankelijk plaats getal 1001 1 0 0 1

Page 50: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Talstelsels

Hexadecimaal getal:– 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F– waarde afhankelijk plaats getal FF

BCD getal:– 0, 1, 2, 3, 4, 5, 6, 7, 8, 9– binair gecodeerd: 0000, 0001, 0010, 0011, ...

Page 51: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Talstelsels

Page 52: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Optelling

Page 53: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)
Page 54: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Verschil berekenen

Page 55: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

INC en DEC

Page 56: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Vermenigvuldigen en delen

Page 57: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 5

• Doelstellingen:– Overlopen instructieset (adhv. CONDENSED) :

• speciale “verplaats” instructies• logische instructies (ANL, ORL, XRL)• bit-instructies• voorwaardelijke sprongen• stack bij subroutines (LCALL, RET, PUSH en POP)

– Programma looplicht 1 uit 4 via functieschakelaars:• contactdender• overnamecontact

Page 58: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Basis stack

werking

ffh

00h

7fh

80h 80h

ffh

SFR (I/O)GPR

81h=SP85h

Stack ruimte

85h

86h

90h

Eerste byte gebruikt als stack

Wordt niet gebruikt als stack

Indirect adresseerbare registers Direct adresseerbare registers

Page 59: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

subroutine aanroepen

LCALL

RET

Subroutine

LCALL

Returnaddress 1

Returnaddress 2

Page 60: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

STACK bij CALL en RET

instructie ninstructie n+1instructie n+2instructie n+3call subroutineinstructie n+5instructie n+6

XXYY

Externe controller-geheugen met

instructiesAdres vande

instructies16-bits

Interne controller-geheugen

Stack-pointer register(wijst naar intern

geheugen in decontroller)

07h

08h

09h

0Ah

0Bh

SP+1

SP+1

YYXX

SP na reset

SP 8-bit

subroutine

return

1

2

3

4 5

opslaanLSB

opslaanMSB

Program counter 16-bit

PC = subroutine

6

7

8

9

PChigh =XXSP-1

PClow =YYSP-1

Jump to XXYY

Jump to subroutine

PChigh PClow

Page 61: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 6

• Doelstellingen:– principe AD omvorming– lezen potmeter (via driver)– lezen temperatuur en omrekening (via driver)– mogelijkheden ADC XC888

Page 62: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

ADC

Page 63: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

ADC SAR

Page 64: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

ADC sample and hold

Page 65: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

ADC 1LSB

1LSB= Vref/(aantal schaaldelen)

5v/1024=0,0048828125v4,096v/1024=0,004v

5v/256=0,01953125v4,096v/256=0,016v

Page 66: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XC888 ADC

Page 67: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XC888 ADC

Page 68: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 7

• Doelstellingen:– Timers 0, 1 – Timer 2 beknopt– CCU6 met PWM– Oefening:

• meten tijdsinterval indrukken 2 schakelaars (t0 in 16 en 24 bit mode, hex op LCD)

• PWM aansturen LED’s P3

Page 69: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Timers 0 & 1

Page 70: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Timers 0 & 1

Page 71: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Timers 0 & 1

Page 72: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Timers 0 & 1

Page 73: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Timers 0 & 1

Page 74: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Timer 2 (21) Up-down count with reload

Page 75: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Timer 2 (21) capture

Page 76: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Timer 2 (21)

Page 77: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

Page 78: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

Page 79: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

Page 80: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

•Gebruik p3.7 om een PWM signaal te genereren met CCU6 en T13•Initialiseer p3.7 (zie figuur onderaan slide)•Initialiseer T13•Lees potmeter en gebruik signaal om PWM in te stellen (10 bit)

Page 81: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

Page 82: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

Page 83: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

Page 84: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

Page 85: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

Page 86: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

Page 87: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CCU 6

Page 88: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 8

• Doelstellingen:– Uitleg interrupt op 8051 en generiek– Belang van:

• PUSH-POP• uitvoeringstijd• flowchart

– Oefening:• knipperlicht op interrupt, teller LCD in hoofdprogramma• teller lcd in interrupt, looplicht in hoofdprogramma

– Uitleggen hoe interrupt interval instelbaar

Page 89: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Interrupt

Tijd

1 cyclus programma

Test HW Test HW Test HW

Geen test HW Geen test HW Geen test HW

Page 90: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Initialisaties(geen interrupts)

Taak 1

Test HW

Speciaal 1

Speciaal 2

Taak 2

Taak 3

Initialisaties(ook interrupts)

Taak 1

Taak 2

Taak 3

Interruptroutine

Speciaal 1

Speciaal 2

RETI

Met interruptZonder interrupt

Hoofdprogramma

Hoofdprogramma

Neen

Ja

Door hardware opgestart

Page 91: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Interrupts

• Noodzakelijk wanneer hardware niet kan wachten op polling door CPU

• Wordt gegenereerd door hardware:– timers, I/O pinnen, ADC, SIO, system,...

• Initialisatie nodig:– hardware die interrupt zal genereren– CPU

• Er moet een interruptroutine klaar staan

Page 92: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Interrupt structuur

Page 93: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Interrupt structuur

Page 94: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

CPU

sca

nt in

terr

upt i

nput

s

Perif

erie

die

inte

rrup

t op

wek

t

Interrupts en prioriteit toelaten

Page 95: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Interrupt vectoren

Page 96: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)
Page 97: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Algemene opmerkingen interrupt:

• Per interruptroutine is er een bijkomende flowchart.

• De interruptroutine onderbreekt het hoofdprogramma.

• PUSH-POP!!• Uitvoeringstijd interruptroutine.• Prioriteiten kunnen nodig zijn.

Page 98: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 9

• Doelstelling:– Bufferles:

• Afwerken oefeningen• Stellen van vragen• Bijkomende uitleg

Page 99: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 10

• Doelstellingen:– Gebruik van de seriële poort via driver routines– Belang van level shifters en baud rate– Programma:

• rekenmachine via hyperterminal (USB poort)• op interrupt echo ingegeven karakters, looplicht als

hoofdprogramma

Page 100: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

XCEZ

; Seriële interface (via USB stekker!!); initsio klaar zetten seriële poort 9600 baud; siooutchar afdrukken ascii code (accu=input); siooutbyte afdrkken getal in accu ; siooutnib afdrukken 4 laagste bits accu; siooutmsga afdrukken ascii string @dptr tot 000h ; sioinchar inlezen van 1 ascii code in de accu

; sioinbufa inlezen van ascii buffer vanaf adres strtbuf, max 20h karakters!

Page 101: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Seriële poort hardware

• Controller beschikt over:– 2 UART poorten (met LIN mogelijkheid)– 2 CAN nodes– 1 SPI poort (Synchronous serial channel)– 1 IIC poort (maar enkele via bitbanging)

• LET OP!!!– Bij ontwerp XC888 bord werden keuzes gemaakt

naar mogelijke level shifters!!– Je kan selecteren op welke pinnen SIO naar buiten

komt!

Page 102: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)
Page 103: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)
Page 104: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 11

• Doelstellingen:– Uitleg over parallelle poorten– Uitleg over stappenmotoren– Uitleg over DC motoren– oefening met stappenmotor– pwm dc motor, meten op tegenEMK

Page 105: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

PIO

Page 106: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

PIO

Page 107: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

PIO als input;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; initdipswitch is een subroutine die de pinnen van poort 4 insteld als input met; pull-up weerstanden ingeschakeld. Hierdoor kunnen schakelaars gebruikt worden naar; massa zonder extra weerstanden.;; Gebruikt geen registers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

initdipswitch: push syscon0 ;juiste map selecteren mov syscon0,#004h push port_page ;tijdelijk bewaren (later herstellen) mov port_page,#001h ;selecteer poort page 1 mov p4_pudsel,#0ffh ;selecteer pull_up device mov p4_puden,#0ffh ;selectie inschakelen mov port_page,#000h ;pagina 0 selecteren mov p4_dir,#000h ;poort 4 als input schakelen pop port_page ;herstellen in oorspronkelijke staat pop syscon0 ;pagina terug herstellen ret

Page 108: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

PIO als output;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; initleds is een routine die de poort 3 als output schakeld. De LED's; worden gedoofd (actief laag om ze te laden branden).;; Gebruikt geen registers;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

initleds: push syscon0 ;juiste map selecteren mov syscon0,#004h push port_page ;tijdelijk bewaren (later herstellen) mov port_page,#000h ;selecteer poort page 0 mov p3_dir,#0ffh ;poort 3 als output schakelen pop port_page ;herstellen in oorspronkelijke staat pop syscon0 ;pagina terug herstellen ret

Page 109: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 12

• Doelstellingen:– Speciale mogelijkheden:

• Fail safe werking– Spanningsbewaking– Software bewaking– Beveiligde bits– Bewaking systeemklok

• Snelheid processor wijzigen• Snelheid software deterministisch maken• Low power mogelijkheden (hier generiek bespreken)

– Afwerken oefeningen vorige les– Software delay maken met gekende uitvoeringstijd

Page 110: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Fail safe werking:• Systeem kan de fout ingaan door:

– storingen in voedingsspanning• spanningsbewaking • overspanningsbeveiliging

– storingen in programmaverloop (externe of interne factoren)

• externe beinvloeding (EMC, EMI)• eventuele bugs in code• uitblijven van verwachte signalen (inputs)

– defect gaan van de hardware (heel duur om op te vangen)

• space, nucleaire toepassingen, ...

– Bewaking van de systeemklok (oscillator watchdog, zie verder)

Page 111: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Fail-safe werking: spanningsbewaking(Embedded Voltage Regulator)

Page 112: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Fail safe werking: software bewaking

Page 113: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Fail safe werk-ing:

beveiligde bits

Page 114: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Snelheid processor aanpassen:

• OSC:– RC, XTAL, TTL-klok– kunnen gekozen worden uit gamma aan

mogelijkheden (toepassingsafhankelijk, wat is beschikbaar in systeem)

• PLL: – aanpassen ingangsklok aan basisfrequentie

hardware– bewaking ingangsklok

Page 115: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Snelheid processor aanpassen:

fsys moet 96MHz zijn

Page 116: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Snelheid processor aanpassen:

Page 117: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Snelheid processor aanpassen:

Page 118: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Snelheid programma deterministisch maken:

UITVOEREN ALS: lcall dffch of lcall dfffh

Page 119: Microcontrollers 8051 based microcontroller XC888 from Infineon 08/2011 Roggemans M. (MGM)

Les 13

• Doelstellingen:– stellen van vragen– afwerken van oefeningen– oplossen specifieke problemen