Skip to content

Instantly share code, notes, and snippets.

@talayhan
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save talayhan/7b4ef3a38bf1c30cac0b to your computer and use it in GitHub Desktop.

Select an option

Save talayhan/7b4ef3a38bf1c30cac0b to your computer and use it in GitHub Desktop.
HCS12 Microcontroller Notes Part1

HCS12 Microcontroller Notes

NOT: Bu döküman HCS12 1. Labı için oluşturulmumş çalışma notları, en sonda lab soruları ve cevapları bulunmaktadır. Dili yarı Türkçe, yarı Azmanca olucak şekilde kullanılmaya gayret gösterilmiştir.

Memory Types

Ram: Random Access Memory (can read and write) ROM: Read Only Memory (programmed at factory) PROM:Programmable Read Only Memory (Programmed once at site) EPROM: Erasable Programmable Read Only Memory EEPROM: Electrically Erasable Programmable Read Only Memory

MC9S12

12 KB RAM 4 KB EEPROM (Normally can only access 3 KB) 256 KB Flash EEPROM (Can access 16 KB at a time)

HCS12 Address Space

HCS12 Address Space

Little Notes: Hem assebmly, hemde C kullanarak programlanabilir.

Von Neumann Versus Harvard Architecture

  • Von Neumann'da Program and Data Memory tek parça halinde. HCS12 de bu mimariyi kullanmakta.

  • Harvard'da ise Program memory ve Data Memory ayrı şekilde tasarlanmış.

Von Neumann vs Harvard Architecture

Little-Endian vs Big-Endian

  1. Little Endian
  2. Big Endian MIPS, IBM S/360, HCS12

big endian

little endian

Registers and HCS12 Registers

HCS12 de bulunan register tipleri;

A -- Accumulator, 8 bit MAR -- Memory Address Register 16 bit MDR -- Memory Data Register 8 bit IR -- Instruction Register 8 bit PC -- Program Counter 16 bit T -- Temporary Register 8 bit


X Index Register | Y Index Register | SP Stack Pointer | (16 bits) PC Program Counter | D Accumulator | Acumulator D = A + B | Condition Code Register | (8 bits)

Condition Code Register = |S|X|H|I|N|Z|V|C|

Note: Daha sonra condition code registerların ne yaptığına bakılacak, açıklama eklenecektir.

Sample Program

Add the contents of the bytes at locations $1000 and $1001, subtract one, and store the result in $1002. The program starts at location $2000.

Kullanacağımız instructionlar.

  • LDAA - Verilen memory lokasyonundaki değeri A ya yükler.
  • ADDA - Verilen memory lokasyonundaki değeri A ile toplar ve A ya yazar.
  • DECA - A daki değeri 1 azaltır.
  • STAA - Verilen memory lokasyonuna A daki değeri kaydedir.
    org $2000

    LDAA $1000
    ADDA $1001
    DECA
    STAA $1002

#HCS12 Slayt_2

  • HCS12 can address 2^16 bytes.
  • 2^16 = 2^6 x 2^10 = 64 x 1024 = 64 KB
  • Lowest address
  • Highest address
  • LDAA (Load Accumulator A) byte koyuyor.
  • LDD (Load Double Accumulator) word koyuyor.

Some HCS12 Instructions

  1. STAB - address : B nin içerisindeki değeri, verilen adrese kor.
  2. ADDA - address : Verilen adresteki değeri A ile toplayıp A ya yazar.
  3. CLRB - clears B: B ye sıfır atar.
  4. INCA - adds 1 to A+1 -> A
  5. DECB - B-1 -> B
  6. LSRA - Accumulator A yı 2 ye böler. Aptalca.
  7. ASRA - aynı arithmetic hali. Akıllca.
  8. SWI - Software interrupt

Örnek Problem Çözme

Hafızanın $1205 nolu adresine ve $1206 nolu adresine iki rastgele sayı koyun (dc.b ile). Bu sayıları toplayıp $1207 nolu adrese koyun. Kod $2000 nolu adresten başlasın.

            
            START equ $2000 ; absolute address to place my code data

mainLoop:   
            LDAA $1205
            ADDA $1206
            STAA $1207

endProg:    STOP    ; end program

            org $1205
            dc.b $07
            dc.b $09

Note: Constant koyarak yapmanın diğer hali.

    
    org $1205
    num1:  dc.b 1
    num2:  dc.b 3

Note: Array ile yapmak istersek.

mainLoop:
            LDAA #02
            STAA num1
            INCA
            STAA num1+1 
            STAA $1209
            
endProg:    STOP                  ; end program
        

    org $1205
    num1: ds.b 2

GTU Micro 1.Lab

Sorular aşağıdaki gibidir.

Micro Lab 1 Sorular

Çözümün Source Kodu:

    
    ; Load num and add other numbers
    LDAA num1
    ADDA num2
    ADDA num3

    ; store the result
    STAA $2003

    ; store FF to set PORTB
    LDAA #$FF
    STAA DDRB

    ; set pins on the PORTB
    LDAA $2003
    STAA PORTB

    ; end program
    SWI


    ORG $2000
    num1: dc.b 4
    num2: dc.b 4
    num3: dc.b 4
    data: dc.b 1

Note:

Ekstra olarak simülasyonda ve dragon board üzerinde gösterilmesini istedi. Dragon Board Led olan kısımdaki com port kullanılacak.

Analog Discovery pinleri üzerinde p0, p1, p2, p3 gösterilmesini istedi. Onda da ground bağlanılması gerekli ekstra olarak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment