- Labornetzteil AliExpress         
Ergebnis 1 bis 2 von 2

Thema: AtMega8 kleine Bibliothek

Baum-Darstellung

Vorheriger Beitrag Vorheriger Beitrag   Nächster Beitrag Nächster Beitrag
  1. #2
    Erfahrener Benutzer Fleißiges Mitglied Avatar von avr_racer
    Registriert seit
    01.04.2014
    Ort
    MecklenburgVorpommern
    Beiträge
    175
    zeitschleifen.asm
    Code:
    ;************************zeitschleifen******************************************
    wait1us:nop
            ret
    
    wait6us:
            ldi            temp0,$06
    wait6us1:
            dec            temp0
            brne                wait6us1
            ret            
    
    wait9us:
            ldi            temp0,$0a        
    wait9us1:
            dec            temp0
            brne                 wait9us1
            ret
    
    wait10us:
            ldi            temp0,$0c    
    wait10us1:
            dec            temp0
            brne                 wait10us1
            ret
    
    
    wait25us:
            ldi            temp4,$20
    wait25us1:        
            dec            temp4
            brne               wait25us1        
            ret
    
    wait50us:
            ldi            temp4,$41
    wait50us1:        
            dec            temp4
            brne             wait50us1        
            ret
    
    wait55us:
            ldi            temp0,$41
    wait55us1:
            dec            temp0
            brne                wait55us1
            ret
    
    wait58us:
            ldi            temp4,$4c
    wait58us1:    
            dec            temp4
            brne                 wait58us1        
            ret
    
    wait60us:
            ldi            temp0,$4e
    wait60us1:
            dec            temp0
            brne                wait60us1
            ret
    
    wait64us:
            ldi            temp0,$54
    wait64us1:
            dec            temp0
            brne                wait64us1
            ret
    
    wait70us:
            ldi            temp0,$5a
            nop
    wait70us1:
            dec            temp0
            brne                wait70us1
            nop
            nop
            ret
    
    wait100us:
            ldi            temp4,$83
    wait100us1:
            dec            temp4
            brne                wait100us1
            ret        
    
    wait500us:
            ldi            temp1,$03
    wait500us1:
            ldi            temp0,$dd
    wait500us2:
            dec            temp0
            brne                wait500us2
            dec            temp1
            brne                wait500us1
            ret
    
    wait1ms:ldi            temp3,$06
    wait1ms1:
            ldi            temp4,$df
    wait1ms2:
            dec            temp4
            brne              wait1ms2
            dec            temp3
            brne              wait1ms1
            ret
    
    wait10ms:ldi                temp3,$60
    wait10ms1:
            ldi            temp4,$df
    wait10ms2:
            dec            temp4
            brne                wait10ms2
            dec            temp3
            brne                 wait10ms1
            ret
    
    waitxms:   rcall                 wait1ms
            dec            temp0
            brne                waitxms
            ret
    
    wait150ms:
            ldi            temp0,$96
            rjmp           waitxms
    
    wait750ms:
            ldi            temp1,$08
    wait750ms1:
            ldi            temp2,$63
    wait750ms2:
            rcall            wait1ms
            dec            temp2
            brne           wait750ms2
            dec            temp1
            brne           wait750ms1
            ret        
    
    wait1s:    ldi            temp1,$0a
    wait1s1:    ldi            temp2,$63
    wait1s2:    rcall            wait1ms
            dec            temp2
            brne           wait1s2
            dec            temp1
            brne           wait1s1
            ret


    mathe.asm
    Code:
    .def math1h     = r8
    .def math1l     = r9
    .def math2h     = R10
    .def math2l     = r11
    .def matherghh    = r12
    .def mathergh    = r13
    .def mathergl    = r14
    .def mathergll    = r15
    .def temp0        = r16
    .def cnt        = r21
    
    ;**********SRAM
    .equ     erg_k        =    $0060            ;erg_k wird bis zu 5 weiteren bytes genutzt sprich erg_k+5
    
                    rcall                  load_math_word           ;hier werden die Zahlen aus dem SRAM geladen die +, -, x, / werden sollen
                   
                    rcall                   add_2_16bit                 ;16bit + 16bit = 17bit nutzt 3Byte
                    ;rcall                  sub_2_16bit                 ;16bit - 16bit = <16bit
                    ;rcall                  smul_2_16bit               ;16bit x 16bit = 32bit nutzt 4Byte für AVR's ohne mul-Befehl
                    ;rcall                  hmul_2_16bit               ;16bit x 16bit = 32bit nutzt 4Byte für AVR's mit mul-Befehl
                    ;rcall                  sdiv_2_16bit                ;16bit / 16bit = <16bit nur Software da kein DIV-Befehl vorhanden 
    
                   rcall                load_hex_dez           ;zu wandelnde Werte in in X und Z Pointer laden               z.B                       FF Hex = 255 Dez laden
                   rcall                   hex_dez                       ;Werte stehen als Byte bereit ohne ASCII Convertierung   Wandlung  Byte      1   2   3  4   5
                                                                                                                                                                                            00 00 00 02 55   
    */
    
    load_math_word:
             lds            temp0,$0070
             mov            math1h,temp0
             lds            temp0,$0071
             mov            math1l,temp0
    
             lds            temp0,$0072
             mov            math2h,temp0
             lds            temp0,$0073
            mov            math2l,temp0
             ret
    
    ;*********Addition 16bit + 16bit Vorzeichenlos
    ;math2h:math2l + math1h:math1l = matherhh:mathergh:mathergl:mathergll
    ;   r10:r11          r8:r9     =   r12   :  r13   :  r14     
    add_2_16bit:
            rcall            clr_erg
            add            math2l,math1l        ;mathxl lowbytes adden
            adc            math2h,math1h        ;mathxlh highbytes adden + Carry
            brcc                add_2_16bit_2        ;wenn Carry gesetzt
            adc            mathergh,yl            ;dann ins 3te Ergbyte speichern quasi Überlauf
    add_2_16bit_2:        
            mov            mathergl,math2h        ;in ergreg schubsen
            mov            mathergll,math2l
            ret
    
    ;*********Subtraktion 16bit - 16bit mit Vorzeichenanzeige
    ;math2h:math2l - math1h:math1l = matherhh:mathergh:mathergl:mathergll
    ;   r10:r11          r8:r9     =   r12   :  r13   :  r14   :  r15   
    sub_2_16bit:
            ldi            yl,'+'
            sts            erg_k+5,yl            ;grundsätzlich erstmal plus
            rcall            clr_erg
            sub            math2l,math1l        ;mathxl lowbytes suben
            sbc            math2h,math1h        ;mathxlh highbytes suben - Carry
            brcc           sub_2_16bit_2        ;wenn Carry gesetzt
            sbc            mathergh,yl            ;dann ins 3te Ergbyte speichern quasi Unterlauf
            com            mathergh            ;da minus einerkomplement macht aus ff=00
            com            math2h                ;da minus einerkomplement macht aus ff=00
            neg            math2l                ;da minus zweierkomplement macht aus ff=01
            ldi            yl,'-'            
             sts            erg_k+5,yl            ;zeigt an, das dass ERG negativ ist
    sub_2_16bit_2:        
             mov            mathergl,math2h        ;in ergreg schubsen
             mov            mathergll,math2l
             ret
    
    ;*********Multiplikation 16bit * 16bit Vorzeichenlos Software
    ;math1h:math1l * math2h:math2l = matherhh:mathergh:mathergl:mathergll
    ;    r8:r9          r10:r11    =   r12   :  r13   :  r14   :  r15
    smul_2_16bit:
            rcall           clr_erg                ;löschen
            ldi            cnt,$10                ;16bit zum multiplzieren
    smul_2_16bit2:
            lsl            mathergll            ;bei jedem Durchgang erg x 2
            rol            mathergl
            rol            mathergh
            rol            matherghh
            
            lsl            math1l                ;Multiplikant
            rol            math1h
            brcc           smul_2_16bit4        ;C = 0 ?
            rcall           smul_add_erg_16bit    ;wenn nicht dann addieren
    smul_2_16bit4:
            dec            cnt                    ;bitcnt -1
            brne           smul_2_16bit2        ;sprung zu Label
             ret
    
    smul_add_erg_16bit:
             add            mathergll,math2l    ;Multiplikator zum Zwischenergebniss
             adc            mathergl,math2h        ;dazuaddieren
             adc            mathergh,yl
            adc            matherghh,yl
             ret
    
    ;*********Multiplikation 16bit * 16bit Vorzeichenlos HARDWARE
    ;math2h:math2l * math1h:math1l = matherhh:mathergh:mathergl:mathergll
    ;   r10:r11          r8:r9     =   r12   :  r13   :  r14   :  r15
    hmul_2_16bit:
            rcall           clr_erg                ;löschen
            mul            math1l,math2l        ;multiplizieren
            add            mathergll,r0        ;
            adc            mathergl,r1            ;Ergebnisse addieren
        
            mul            math1l,math2h        ;multiplizieren
            add            mathergl,r0
            adc            mathergh,r1            ;Ergebnisse addieren
                            
            mul            math1h,math2l        ;multiplizieren
            add            mathergl,r0
            adc            mathergh,r1            ;Ergebnisse addieren
            adc            matherghh,yh    
            
            mul            math1h,math2h        ;multiplizieren
             add            mathergh,r0
             adc            matherghh,r1        ;Ergebnisse addieren
        
            r et
    
    ;*********Division 16bit / 16bit Vorzeichenlos
    ;math1h:math1l / math2h:math2l = matherhh:mathergh:mathergl:mathergll
    ;    r8:r9          r10:r11    =   r12   :  r13   :  r14   :  r15
    sdiv_2_16bit:
            rcall           clr_erg                ;Ergreg löschen
             cp            math2l,yl
            cpc            math2h,yh
            breq          sdiv_2_16bit4
             ldi            cnt,$10                ;bitcnt
             mov            yl,math1l            ;Divident in Y-Pointer schieben
            mov            yh,math1h            ;
    sdiv_2_16bit1:
             lsl            yl                    ;pro Durchgang x2
             rol            yh                    ;links shiften 
             rol            mathergll            ;Restbildung
             rol            mathergl            ;
             cp            mathergll,math2l    ;
            cpc            mathergl,math2h        ;
            brcs           sdiv_2_16bit3        ;Rest < DIVISOR
    sdiv_2_16bit2:
            adiw          yh:yl,$01            ;Ergebniss +1
            sub            mathergll,math2l    ;
            sbc            mathergl,math2h        ;
    sdiv_2_16bit3:
            dec            cnt
            brne          sdiv_2_16bit1
    sdiv_2_16bit4:
            push          mathergl            ;wieder tauschen 
            push           mathergll            ;das alles in den ErgRegs steht
            mov            mathergll,yl        ;
            mov            mathergl,yh            ;
            pop            yl                    ;hier steht der Rest diesen *10, dann wieder teilen = Kommastellen
            pop            yh                    ;oder Divident *10,100,1000 usw dann teilen Kommastellen vorgezogen
            ret
    
    ;original AtmelRoutine
    div_2_16bit:
            rcall           clr_erg                ;ergreg löschen
             cp            math2l,yl
            cpc            math2h,yh            ;vergleich Divisor  
            breq          div_2_16bit6        ;= 0 sprung
            l di            cnt,$11    
             clc                                
    div_2_16bit2:
             rol            math1l
             rol            math1h                ;DIVIDENT Teilender
            dec            cnt
            brne          div_2_16bit3        
            rjmp          div_2_16bit5
    div_2_16bit3:
             rol            mathergll            ;RESTbildung
             rol            mathergl
             sub            mathergll,math2l    ;Erg minus DIVISOR Teiler
            sbc            mathergl,math2h        ;
            brcc           div_2_16bit4        ;
             add            mathergll,math2l    ;Erg + DIVISOR
             adc            mathergl,math2h        ;rückgängig machen
            clc                                ;Carry löschen
            rjmp          div_2_16bit2        ;sprung zu Label
    div_2_16bit4:    
            sec                                ;Carry setzen
            rjmp          div_2_16bit2        ;sprung zu Label
    div_2_16bit5:
            push          mathergl
            push                mathergll            ;Rest puschen
            mov            mathergll,math1l    ;alles so drehen 
            mov            mathergl,math1h        ;das es in den ErgRegs steht
            pop            yl                    ;Rest popen
            pop            yh
    div_2_16bit6:    
            ret
    
    ;***************Ergebnissregister löschen************
    clr_erg:      clr            yl                    ;löschen
             clr            yh                    
             clr            matherghh
             clr            mathergh            
             clr            mathergl
            clr            mathergll
             ret
    /*
    ;**********Wandlungsvorbereitung von HEX in DEZ******
    load_hex_dez:
             mov            zh,matherghh        ;highhigh
            mov            zl,mathergh            ;highlow
            mov            xh,mathergl            ;high
            mov            xl,mathergll        ;low
            ret
    
    hex_dez:   ;lds            zh                ;wenn ZH=ff>>LCD=42949967295
            ;lds            zl                ;wenn ZL=ff>>LCD=16777215       bei ZH=0
            ;lds            xh,                ;wenn XH=ff>>LCD=65535            bei ZH:ZL=0
            ;lds            xl,                ;wenn xl=ff>>LCD=255,             bei XH=0
            push           yl
            push           yh
            push           xl
            push           xh
            push                 zl
            push            zh
            rcall            load_Ypontr            ;Speicherbereich laden          
                ldi                   cnt,$ff                ;
    num_1000000000:                            ;Milliarden 
            inc             cnt
                    subi           xh, byte2(1000000000)
                    sbci           zl, byte3(1000000000)
            sbci            zh,    byte4(1000000000)
                    brcc           num_1000000000
                    swap          cnt
            st            y,cnt     
                ldi              cnt,$0a
    num_100000000:                             ;100Millionen
            dec            cnt                    ;+1
                    subi            xh, byte2(-100000000)
                    sbci           zl, byte3(-100000000)
            sbci           zh,    byte4(-100000000)
            brcs           num_100000000        ;ja
             ld            temp0,y
             or            cnt,temp0
            st            y+,cnt                ;fertig speichern
            ldi              cnt,$ff                ;
    num_10000000:                            ;10Millionen
            inc              cnt
                    subi           xl, byte1(10000000)
                    sbci              xh, byte2(10000000)
            sbci           zl,    byte3(10000000)
                    sbci             zh, 0
               brcc             num_10000000
                   swap          cnt
                st            y,cnt       
               ldi               cnt,$0a
    num_1000000:                             ;1Million
            dec             cnt                    ;+1
                    subi           xl, byte1(-1000000)    ;
                    sbci           xh, byte2(-1000000)    ;vergleich auf >1000000
                    sbci           zl,    byte3(-1000000)
            brcs            num_1000000            ;ja
            ld            temp0,y
            or            cnt,temp0
            st            y+,cnt                ;fertig speichernn      
            ldi              cnt,$ff                ;
    num_100000:                                ;100Tausend
            inc                   cnt
                    subi           xl, byte1(100000)
                    sbci              xh, byte2(100000)
            sbci           zl,    byte3(100000)
                    brcc                  num_100000
                  swap          cnt
            st            y,cnt    
                ldi              cnt,$0a
    num_10000:                                 ;10Tausend
            dec            cnt                    ;+1
                    subi           xl, byte1(-10000)    ;
                    sbci            xh, byte2(-10000)    ;vergleich auf >10000
                    sbci                zl, byte3(-10000)
            brcs                  num_10000            ;ja
                    ld            temp0,y
            or            cnt,temp0
            st            y+,cnt                ;fertig speichern      
            ldi              cnt,$ff                
    num_1000:                                ;Tausender 
             inc            cnt
                     subi          xl, low(1000)
                     sbci          xh, high(1000)
                     brcc          num_1000
                     swap        cnt
             st            y,cnt        
             ldi            cnt,$0a
    num_100:  dec           cnt                    ;100
                    subi           xl, low(-100)
                    sbci           xh, high(-100)
                    brcs           num_100
               ld            temp0,y
            or            cnt,temp0
            st            y+,cnt    
            ldi             cnt,$ff
    num_10:    inc             cnt                    ;Zehner + Einer
                    subi            xl, 10
                    brcc            num_10
            subi           xl, -10
                  swap         cnt
            or            cnt,xl
            st            y+,cnt 
            pop            zh
            pop            zl
            pop            xh
            pop            xl
            pop            yh
            pop            yl
            ret
    
    load_Ypontr:
            ldi            yh,high(erg_k)            
            ldi            yl,low(erg_k)        ;speicherpunkt laden
            ret
    */
    Geändert von avr_racer (15.01.2019 um 14:40 Uhr)

Ähnliche Themen

  1. [ERLEDIGT] Mein ATMega8 hat eine kleine Output Power?
    Von Elektrobot im Forum AVR Hardwarethemen
    Antworten: 5
    Letzter Beitrag: 03.10.2012, 18:41
  2. ASURO-Bibliothek in C++ ?
    Von ehenkes im Forum Asuro
    Antworten: 3
    Letzter Beitrag: 13.06.2007, 18:34
  3. ASURO-Bibliothek
    Von Cortes im Forum Asuro
    Antworten: 6
    Letzter Beitrag: 01.08.2006, 20:24
  4. DOS - Bibliothek
    Von hacker im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 1
    Letzter Beitrag: 14.04.2006, 01:54
  5. datenblatt bibliothek
    Von djdune im Forum Konstruktion/CAD/3D-Druck/Sketchup und Platinenlayout Eagle & Fritzing u.a.
    Antworten: 3
    Letzter Beitrag: 18.02.2005, 12:37

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

12V Akku bauen