⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap13.asm

📁 Motorola 6812芯片开发的接口程序。
💻 ASM
字号:
; Chapter 13 6812 assembly language programs; Jonathan W. Valvano; This software accompanies the book,; Real Time Embedded Systems published by Brooks Cole;; Program 13.18. Global variables for fuzzy controller in 6812 assembly.         org  $800; crisp inputsspeed:   ds   1acceleration: ds 1; input membership variablesfuzvar:  ds   0    ; inputsEPL:     ds   1    ; speed way too fastEPS:     ds   1    ; speed too fastEZE:     ds   1    ; speed OKENS:     ds   1    ; speed too slowENL:     ds   1    ; speed way too slowDPL:     ds   1    ; speed decreasing a lotDPS:     ds   1    ; speed decreasingDZE:     ds   1    ; speed constantDNS:     ds   1    ; speed increasingDNL:     ds   1    ; speed increasing a lotfuzout:  ds   0    ; outputs   OPL:     ds   1    ; add a lot of power to systemOPS:     ds   1    ; add some power to systemOZE:     ds   1    ; leave power as isONS:     ds   1    ; subtract some power from systemONL:     ds   1    ; subtract a lot of power from systemBREAK:   ds   1    ; apply break?; input membership variables relative offsetsepl:     equ  0    ; speed way too fasteps:     equ  1    ; speed too fasteze:     equ  2    ; speed okens:     equ  3    ; speed too slowenl:     equ  4    ; speed way too slowdpl:     equ  5    ; speed decreasing a lotdps:     equ  6    ; speed decreasingdze:     equ  7    ; speed constantdns:     equ  8    ; speed increasingdnl:     equ  9    ; speed increasing a lot;output membership variablesopl:     equ  10   ; add alot of power to systemops:     equ  11   ; add some power to systemoze:     equ  12   ; leave power as isons:     equ  13   ; subtract some power from systemonl:     equ  14   ; subtract alot of power from systembreak:   equ  15   ; apply break?;crisp outputsdpower:  ds   1; Program 13.19. Definition of the error input function in 6812 assembly.         org  $F000; format is Point1,Point2,Slope1,Slope2s_tab:   dc.b  192,255,8,0      ;EPL         dc.b  128,244,5,8      ;EPS         dc.b  112,144,16,16    ;EZE         dc.b  32,128,8,5       ;ENS         dc.b  0,64,0,8         ;ENL; Program 13.20. Definition of the acceleration input function in 6812 assembly.a_tab:   dc.b  244,255,16,0     ;DPL         dc.b  160,255,16,4     ;DPS         dc.b  64,192,8,8       ;DZE         dc.b  0,96,4,16        ;DNS         dc.b  0,32,0,16        ;DNL; Program 13.21. Definition of the fuzzy rules in 6812 assembly.rules:   dc.b  enl,dnl,$FE,opl,$FE       ; if ENL and DNL then OPL         dc.b  ens,dnl,$FE,opl,$FE       ; if ENS and DNL then OPL         dc.b  eze,dnl,$FE,opl,$FE       ; if EZE and DNL then OPL         dc.b  enl,dns,$FE,opl,$FE       ; if ENL and DNS then OPL         dc.b  ens,dns,$FE,ops,$FE       ; if ENS and DNS then OPS         dc.b  eze,dns,$FE,ops,$FE       ; if EZE and DNS then OPS         dc.b  enl,dze,$FE,opl,$FE       ; if ENL and DZE then OPL         dc.b  ens,dze,$FE,ops,$FE       ; if ENS and DZE then OPS         dc.b  eze,dze,$FE,oze,$FE       ; if EZE and DZE then OZE         dc.b  eps,dze,$FE,ons,$FE       ; if EPS and DZE then ONS         dc.b  epl,dze,$FE,onl,break,$FE ; if EPL and DZE then ONL         dc.b  eze,dps,$FE,ons,$FE       ; if EZE and DPS then ONS         dc.b  eps,dps,$FE,ons,$FE       ; if EPS and DPS then ONS         dc.b  eps,dps,$FE,onl,break,$FE ; if EPL and DPS then ONL         dc.b  eze,dpl,$FE,onl,break,$FE ; if EZE and DPL then ONL         dc.b  eps,dpl,$FE,onl,break,$FE ; if EPS and DPL then ONL         dc.b  epl,dpl,$FE,onl,break,$FE ; if EPL and DPL then ONL         dc.b  $FF; Program 13.22. Ritual and main program for fuzzy controller in 6812 assembly.addsingleton: dc.b 255,138,128,118,0  ; 128 subtracted,  +127,10,0,-10,-128ritual:  sei        ;make atomic         bset #$20,TIOS  ;OC5         movb #$80,TSCR  ;enable, no fast clr         movb #$33,TMSK2 ;1us clk         bset #$20,TMSK1 ;Arm OC5         ldaa #$20       ;clear C5F         staa TFLG1         ldd  TCNT       ;current time         addd #10000     ;first in 10 ms         std  TC5          cli             ;enable         rtsmain:    lds  #$0C00         ldd  #100         ; initial duty cycle 1% is off         std  dutycycle         jsr  ritual       ; initialize OC interrupt         bra  *; Program 13.23. Interrupt handler for fuzzy controller in 6812 assembly.timehan: ldaa #$20  ;clear C5F          staa TFLG1 ;Acknowledge          ldd  TC5                         addd #10000 ;next in 10 ms               std  TC5               jsr  measurespeed ; crisp input speed;reg A is speed 0 to 255         ldx  #s_tab         ldy  #fuzvar         mem          ; calculate EPL         mem          ; calculate EPS         mem          ; calculate EZE         mem          ; calculate ENS         mem          ; calculate ENL         jsr  measureacceleration ; crisp input acceleration ;reg A is acceleration 0 to 255         ldx  #a_tab         mem          ; calculate DPL         mem          ; calculate DPS         mem          ; calculate DZE         mem          ; calculate DNS         mem          ; calculate DNL         ldab #6cloop:   clr  1,y+  ; clear OPL,OPS,OZE,ONS,ONL,BREAK         dbne b,cloop         ldx  #rules         ldy  #fuzvar         ldaa #$FF         rev         ldy  #fuzout         ldx  #addsingleton         ldab #5         wav         ediv         tfr  y,d         subb #128         stab dpowerchange   ldab dpower         sex  b,d         addd dutycycle; 200 Hz squarewave is 10000 cycles; correct range is 100 to 9600 cycles         cpd  #100         bhs  nolowlow:     ldd  #100   ; underflow         bra  setnotlow:  cpd  #9600         bls  sethigh:    ldd  #9600  ; overflowset:     std  dutycycle         rti; Program 13.24. Fuzzification function for the temperature input in 6812 assembly.; format is Point1,Point2,Slope1,Slope2T_tab:   dc.b  160,255,16,0      ;Hot         dc.b  64,192,8,16       ;Normal         dc.b  0,64,0,8          ;Cold; Program 13.25. Fuzzification function for the temperature error  input in 6812 assembly.E_tab:   dc.b  144,255,16,0      ;TooHot         dc.b  64,192,8,16       ;OK         dc.b  0,96,0,16         ;TooCold; Program 13.26. Global variables in 6812 assembly.; input membership variablesfuzvar:  ds   0    ; inputsHot:     ds   1    Normal:  ds   1   Cold:    ds   1    TooHot:  ds   1    OK:      ds   1   TooCold: ds   1    ; output membership variablesfuzout:  ds   0    ; outputs   NoHeat:  ds   1    ; turn off heaterSomeHeat: ds  1    ; apply some heatMaxHeat: ds   1    ; turn on heaterNoFan:   ds   1    ; turn off fanSomeFan: ds   1    ; apply some fanMaxFan:  ds   1    ; turn on fan; input membership variables relative offsetshot:     equ  0    normal:  equ  1    cold:    equ  2    toohot:  equ  3    ok:      equ  4    toocold: equ  5   ;output membership variablesnoheat:  equ  6    ; turn off heatersomeheat: equ 7    ; apply some heatmaxheat: equ  8    ; turn on heaternofan:   equ  9    ; turn off fansomefan: equ  10   ; apply some fanmaxfan:  equ  11   ; turn on fan; Program 13.27. Fuzzy rules in 6812 assembly.rules:  dc.b hot,toohot,$FE,noheat,maxfan,$FE     ; use fan for max cooling        dc.b hot,ok,$FE,noheat,somefan,$FE        ; use fan for some cooling        dc.b normal,toohot,$FE,noheat,nofan,$FE   ; no fan for normal temps        dc.b normal,ok,$FE,noheat,nofan,$FE       ; perfect         dc.b normal,toocold,$FE,someheat,nofan,$FE ; a little heat         dc.b cold,ok,$FE,noheat,nofan,$FE         ; cold but perfect         dc.b cold,toocold,$FE,maxheat,maxfan,$FE  ; fast warmup         dc.b $FF; Program 13.28. Fuzzy controller in 6812 assembly.Heatsingleton: dc.b 0,50,255  Fansingleton: dc.b 0,128,255  timehan: ldaa #$20  ;clear C5F          staa TFLG1 ;Acknowledge          ldd  TC5                         addd #10000 ;next in 10 ms               std  TC5                      jsr  MeasureTemperatire ; crisp input temperature, T;reg A is temperature 0 to 255 (units 0.5鸉)         ldx  #T_tab         ldy  #fuzvar         mem          ; calculate Hot         mem          ; calculate Normal         mem          ; calculate Cold         jsr  MeasureError ; crisp input error, E ;reg A is error 0 to 255  (128 means no error) (units 0.125鸉)         ldx  #E_tab         mem          ; calculate TooHot         mem          ; calculate OK         mem          ; calculate TooCold         ldab #6cloop:   clr  1,y+  ; clear NoHeat, SomeHeat, MaxHeat, NoFan, SomeFan, MaxFan         dbne b,cloop         ldx  #rules         ldy  #fuzvar         ldaa #$FF         rev         ldy  #NoHeat   ; pointer to NoHeat, SomeHeat, MaxHeat         ldx  #Heatsingleton         ldab #3         wav         ediv         tfr  y,d         stab Heat         ldy  #NoFan   ; pointer to NoFan, SomeFan, MaxFan         ldx  #Fansingleton         ldab #3         wav         ediv         tfr  y,d         stab Fan         rti

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -