?? armok0137229.txt
字號:
ret
;****
HEXtoDECadjd1:
ldi temp2,3
add temp2,temp0
sbrc temp2,3
mov temp0,temp2
ldi temp2,$30
add temp2,temp0
sbrc temp2,7
mov temp0,temp2
ret
;4、**** 4Bytes(32Bit)十六進制轉成5Bytes(40Bit)十進制子程序*************END
;5、**** 將5Bytes(40Bit)十進制cntxd送到LCD緩沖區LCDBufferBegin**********
SendDECtoLCDBuffer:
push temp0
push temp1
ldi XL,low(LCDBufferBegin)
ldi XH,high(LCDBufferBegin)
mov temp0,dData4
andi temp0,0xf0
swap temp0
st X+,temp0
mov temp0,dData4
andi temp0,0x0f
st X+,temp0
mov temp0,dData3
andi temp0,0xf0
swap temp0
st X+,temp0
mov temp0,dData3
andi temp0,0x0f
st X+,temp0
mov temp0,dData2
andi temp0,0xf0
swap temp0
st X+,temp0
mov temp0,dData2
andi temp0,0x0f
st X+,temp0
mov temp0,dData1
andi temp0,0xf0
swap temp0
st X+,temp0
mov temp0,dData1
andi temp0,0x0f
st X+,temp0
mov temp0,dData0
andi temp0,0xf0
swap temp0
st X+,temp0
mov temp0,dData0
andi temp0,0x0f
st X+,temp0
ldi XL,low(LCDBufferBegin)
ldi XH,high(LCDBufferBegin)
ldi temp1,9
SendDECtoLCDBufferloop: ;去除數值前面的零
ld temp0,X
tst temp0
brne SendDECtoLCDBufferEnd
ldi temp0,0x0a
st X,temp0
adiw XL,1
dec temp1
brne SendDECtoLCDBufferloop
SendDECtoLCDBufferEnd:
pop temp1
pop temp0
ret
;5、**** 將5Bytes(40Bit)十進制cntxd送到LCD緩沖區LCDBufferBegin*******END
;6、**** 功能1 初始化,內部測試、顯示檢測輸出全0~全9,無顯示(0x00~0x0F)******
LCDtest:
push temp0
push temp1
lds temp0,LCDtestCount
inc temp0
sts LCDtestCount,temp0
andi temp0,0x0f
ldi XL,low(LCDBufferBegin) ; X = 顯示緩沖區(10字節)
ldi XH,high(LCDBufferBegin)
ldi temp1,10 ; 清空
LCDtestloop:
st X+,temp0
dec temp1
brne LCDtestloop ;temp1不為0轉LCDtestloop,為0按順序執行
rcall LCD_BYTESoutput
LCDtestend:
pop temp1
pop temp0
ret
;6、**** 功能1 初始化,內部測試、顯示檢測輸出全0~全9,無顯示(0x00~0x0F)***END
;*************************************************************************
; 子函數
;**********************************************************************END
reset:
ldi temp0,LOW(StackBegin) ;**** 初識化堆棧
out SPL,temp0 ;SP =StackBegin
ldi temp0,HIGH(StackBegin)
out SPH,temp0
rcall InitData ;**** 設定1、4、1000、10的8次方、10的21次方和pi的浮點值
rcall InitIOPort ;**** 初識化I/O口
ldi temp0,7 ;**** 初始化,顯示輸出全8
sts LCDtestCount,temp0
rcall LCDTest
rcall InitTime ;**** 設定T/C0、T/C1、T/C2的工作方式。
sei
main:
in temp0,LCMeter
andi temp0,LCMeterMask
in temp1,FMeter
andi temp1,FMeterMask
or temp1,temp0
cpi ActionFlag,CountDataReady
brne NoData
cp temp1,ProgramSelect
brne ProgramSelectTrans
rcall DataTrans ;數據處理
clr ActionFlag
rjmp main
ProgramSelectTrans:
mov ProgramSelect,temp1
clr ActionFlag
NoData:
rjmp main ;
;**** 數據處理 *********************************
DataTrans:
push R13 ;保護浮點運算使用寄存區
push R14
push R15
push R16
push R17
push R18
push R19
push R20
push R21
push R22
push R23
push R24
push R25
push R26
push R27
push R28
push R29
ldi YH,HIGH(DataStack)
ldi YL,LOW(DataStack)
cpi ProgramSelect,SelectVHF
brne NoProgramSelectVHF
rjmp ProgramSelectVHF
NoProgramSelectVHF:
cpi ProgramSelect,SelectUHF
brne NoProgramSelectUHF
rjmp ProgramSelectUHF
NoProgramSelectUHF:
cpi ProgramSelect,SelectCY
brne NoProgramSelectCY
rjmp ProgramSelectCY
NoProgramSelectCY:
cpi ProgramSelect,SelectLC
brne NoProgramSelectLC
rjmp ProgramSelectLC
NoProgramSelectLC:
cpi ProgramSelect,SelectCAP
brne NoProgramSelectCAP
rjmp ProgramSelectCAP
NoProgramSelectCAP:
cpi ProgramSelect,SelectCx
brne NoProgramSelectCx
rjmp ProgramSelectCx
NoProgramSelectCx:
cpi ProgramSelect,SelectLx
brne NoProgramSelectLx
rjmp ProgramSelectLx
NoProgramSelectLx:
DataTransEnd:
pop R29
pop R28
pop R27
pop R26
pop R25
pop R24
pop R23
pop R22
pop R21
pop R20
pop R19
pop R18
pop R17
pop R16
pop R15
pop R14
pop R13
ret
ProgramSelectVHF:
mov hData0,CountDataBuffer0
mov hData1,CountDataBuffer1
mov hData2,CountDataBuffer2
mov hData3,CountDataBuffer3
rcall HEXtoDEC
rcall SendDECtoLCDBuffer
rcall LCD_BYTESoutput
rjmp DataTransEnd
ProgramSelectUHF:
mov hData0,CountDataBuffer0
mov hData1,CountDataBuffer1
mov hData2,CountDataBuffer2
mov hData3,CountDataBuffer3
ldi temp1,6
ProgramSelectUHFLoop: ;hData乘于64(移位6次)
lsl hData0
rol hData1
rol hData2
rol hData3
dec temp1
brne ProgramSelectUHFLoop
rcall HEXtoDEC
rcall SendDECtoLCDBuffer
rcall LCD_BYTESoutput
rjmp DataTransEnd
ProgramSelectCY:
mov hData0,CountDataBuffer0
mov hData1,CountDataBuffer1
mov hData2,CountDataBuffer2
mov hData3,CountDataBuffer3
rcall HEXtoDEC
rcall SendDECtoLCDBuffer
rcall LCD_BYTESoutput
rjmp DataTransEnd
ProgramSelectLC:
mov R16,CountDataBuffer0 ;FloatFLC
mov R17,CountDataBuffer1
mov R18,CountDataBuffer2
mov R19,CountDataBuffer3
rcall LONG2FP
sts FloatFLCDataByte0,R16
sts FloatFLCDataByte1,R17
sts FloatFLCDataByte2,R18
sts FloatFLCDataByte3,R19
mov hData0,CountDataBuffer0
mov hData1,CountDataBuffer1
mov hData2,CountDataBuffer2
mov hData3,CountDataBuffer3
rcall HEXtoDEC
rcall SendDECtoLCDBuffer
rcall LCD_BYTESoutput
rjmp DataTransEnd
ProgramSelectCAP:
;**** Cref=((FCAP*FCAP)/(FLC*FLC-FCAP*FCAP))*CAP ,CAP=1000pF
;**** Lref=1/(4*pi*pi*FLC*FLC*Cref)
mov R16,CountDataBuffer0
mov R17,CountDataBuffer1
mov R18,CountDataBuffer2
mov R19,CountDataBuffer3
rcall LONG2FP
sts FloatFCAPDataByte0,R16 ;FCAP的浮點值
sts FloatFCAPDataByte1,R17
sts FloatFCAPDataByte2,R18
sts FloatFCAPDataByte3,R19
mov R21,R16 ;(FCAP*FCAP)
mov R22,R17
mov R23,R18
mov R24,R19
rcall MPY32F
sts DataBuffer10,R16
sts DataBuffer11,R17
sts DataBuffer12,R18
sts DataBuffer13,R19
lds R16,FloatFLCDataByte0 ;(FLC*FLC)
lds R17,FloatFLCDataByte1
lds R18,FloatFLCDataByte2
lds R19,FloatFLCDataByte3
mov R21,R16
mov R22,R17
mov R23,R18
mov R24,R19
rcall MPY32F
lds R21,DataBuffer10 ;(FLC*FLC-FCAP*FCAP)
lds R22,DataBuffer11
lds R23,DataBuffer12
lds R24,DataBuffer13
rcall SUB32F
mov R21,R16
mov R22,R17
mov R23,R18
mov R24,R19
lds R16,DataBuffer10 ;((FCAP*FCAP)/(FLC*FLC-FCAP*FCAP))
lds R17,DataBuffer11
lds R18,DataBuffer12
lds R19,DataBuffer13
rcall DIV32F ;Cref=((FCAP*FCAP)/(FLC*FLC-FCAP*FCAP))*CAP
lds R21,Float10E3Byte0 ;CAP=1000pF
lds R22,Float10E3Byte1
lds R23,Float10E3Byte2
lds R24,Float10E3Byte3
rcall MPY32F
sts FloatCrefDataByte0,R16 ;保存Cref浮點值
sts FloatCrefDataByte1,R17
sts FloatCrefDataByte2,R18
sts FloatCrefDataByte3,R19
;**** Lref=1/(4*pi*pi*FLC*FLC*Cref)
;**** =10E21/FloatCref/4/Floatpi/Floatpi/FloatFLC/FloatFLC
mov R21,R16
mov R22,R17
mov R23,R18
mov R24,R19
lds R16,Float10E21Byte0
lds R17,Float10E21Byte1
lds R18,Float10E21Byte2
lds R19,Float10E21Byte3
rcall DIV32F ;10E21/FloatCref
lds R21,Float4Byte0
lds R22,Float4Byte1
lds R23,Float4Byte2
lds R24,Float4Byte3
rcall DIV32F ;10E21/FloatCref/4
lds R21,FloatpiByte0
lds R22,FloatpiByte1
lds R23,FloatpiByte2
lds R24,FloatpiByte3
rcall DIV32F ;10E21/FloatCref/4/Floatpi
lds R21,FloatpiByte0
lds R22,FloatpiByte1
lds R23,FloatpiByte2
lds R24,FloatpiByte3
rcall DIV32F ;10E21/FloatCref/4/Floatpi/Floatpi
lds R21,FloatFLCDataByte0
lds R22,FloatFLCDataByte1
lds R23,FloatFLCDataByte2
lds R24,FloatFLCDataByte3
rcall DIV32F ;10E21/FloatCref/4/Floatpi/Floatpi/FloatFLC
lds R21,FloatFLCDataByte0
lds R22,FloatFLCDataByte1
lds R23,FloatFLCDataByte2
lds R24,FloatFLCDataByte3
rcall DIV32F ;10E21/FloatCref/4/Floatpi/Floatpi/FloatFLC/FloatFLC
sts FloatLrefDataByte0,R16 ;保存Lref浮點值
sts FloatLrefDataByte1,R17
sts FloatLrefDataByte2,R18
sts FloatLrefDataByte3,R19
rcall FP2LONG
mov hData0,R16
mov hData1,R17
mov hData2,R18
mov hData3,R19
; mov hData0,CountDataBuffer0
; mov hData1,CountDataBuffer1
; mov hData2,CountDataBuffer2
; mov hData3,CountDataBuffer3
ProgramSelectCAPEnd:
rcall HEXtoDEC
rcall SendDECtoLCDBuffer
rcall LCD_BYTESoutput
rjmp DataTransEnd
ProgramSelectCx:
;**** Cx=((FLC*FLC)/(FCx*FCx)-1)*Cref
mov R16,CountDataBuffer0
mov R17,CountDataBuffer1
mov R18,CountDataBuffer2
mov R19,CountDataBuffer3
rcall LONG2FP
sts FloatFCxDataByte0,R16 ;FCx的浮點值
sts FloatFCxDataByte1,R17
sts FloatFCxDataByte2,R18
sts FloatFCxDataByte3,R19
mov R21,R16 ;(FCx*FCx)
mov R22,R17
mov R23,R18
mov R24,R19
rcall MPY32F
sts DataBuffer10,R16
sts DataBuffer11,R17
sts DataBuffer12,R18
sts DataBuffer13,R19
lds R16,FloatFLCDataByte0 ;(FLC*FLC)
lds R17,FloatFLCDataByte1
lds R18,FloatFLCDataByte2
lds R19,FloatFLCDataByte3
mov R21,R16
mov R22,R17
mov R23,R18
mov R24,R19
rcall MPY32F
lds R21,DataBuffer10
lds R22,DataBuffer11
lds R23,DataBuffer12
lds R24,DataBuffer13
rcall DIV32F ;(FLC*FLC)/(FCx*FCx)
lds R21,Float10E0Byte0
lds R22,Float10E0Byte1
lds R23,Float10E0Byte2
lds R24,Float10E0Byte3
rcall SUB32F ;((FLC*FLC)/(FCx*FCx)-1)
lds R21,FloatCrefDataByte0
lds R22,FloatCrefDataByte1
lds R23,FloatCrefDataByte2
lds R24,FloatCrefDataByte3
rcall MPY32F ;Cx=((FLC*FLC)/(FCx*FCx)-1)*Cref
rcall FP2LONG ;結果轉成4字節整數
sts CxDataByte0,R16
sts CxDataByte1,R17
sts CxDataByte2,R18
sts CxDataByte3,R19
mov hData0,R16
mov hData1,R17
mov hData2,R18
mov hData3,R19
rcall HEXtoDEC
rcall SendDECtoLCDBuffer
rcall LCD_BYTESoutput
rjmp DataTransEnd
ProgramSelectLx:
;**** Lx=((FLC*FLC)/(FLx*FLx)-1)*Lref
mov R16,CountDataBuffer0
mov R17,CountDataBuffer1
mov R18,CountDataBuffer2
mov R19,CountDataBuffer3
rcall LONG2FP
sts FloatFLxDataByte0,R16 ;FLx的浮點值
sts FloatFLxDataByte1,R17
sts FloatFLxDataByte2,R18
sts FloatFLxDataByte3,R19
mov R21,R16 ;
mov R22,R17
mov R23,R18
mov R24,R19
lds R16,FloatFLCDataByte0 ;(FLC/FLx)
lds R17,FloatFLCDataByte1
lds R18,FloatFLCDataByte2
lds R19,FloatFLCDataByte3
rcall DIV32F ;
mov R21,R16 ;
mov R22,R17
mov R23,R18
mov R24,R19
lds R21,Float10E0Byte0
lds R22,Float10E0Byte1
lds R23,Float10E0Byte2
lds R24,Float10E0Byte3
rcall SUB32F ;((FLC/FLx)*(FLC/FLx)-1)
lds R21,FloatLrefDataByte0
lds R22,FloatLrefDataByte1
lds R23,FloatLrefDataByte2
lds R24,FloatLrefDataByte3
rcall MPY32F ;Lx=((FLC/FLx)*(FLC/FLx)-1)*Lref
rcall FP2LONG ;結果轉成4字節整數
sts LxDataByte0,R16
sts LxDataByte1,R17
sts LxDataByte2,R18
sts LxDataByte3,R19
mov hData0,R16
mov hData1,R17
mov hData2,R18
mov hData3,R19
ProgramSelectLxEnd:
rcall HEXtoDEC
rcall SendDECtoLCDBuffer
rcall LCD_BYTESoutput
rjmp DataTransEnd
;**** 數據處理 *********************************END
;7、**** 初始化 清空SRAM ******************************************************
InitSRAM:
clr temp0
ldi XL,low(SRAMSTART) ;X =SRAMSTART
ldi XH,high(SRAMSTART)
ldi temp1,4
ZeroSRAMloop:
ldi temp2,0xff
ZeroSRAMloop1:
st X+,temp0
dec temp2
brne ZeroSRAMloop1 ;temp2不為0轉,為0按順序執行
dec temp1
brne ZeroSRAMloop ;temp1不為0轉,為0按順序執行
ret
;7、**** 清空SRAM ******************************************************
;8、**** 初識化I/O口****************************************************
InitIOPort:
ldi temp0,InitPORTB
out PORTB,temp0
ldi temp0,InitDDRB
out DDRB,temp0
ldi temp0,InitPORTC
out PORTC,temp0
ldi temp0,InitDDRC
out DDRC,temp0
ldi temp0,InitPORTD
out PORTD,temp0
ldi temp0,InitDDRD
out DDRD,temp0
ret
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -