?? f6.inc
字號:
;//********************************************************************************************************
RESET_V equ 0x0000
ISR_V equ 0x0004
High2k equ 0x0800
;//*********************************************************************
;常數定義
_ClkIn equ D'5068800' ; OSC=5.0688MHz
_ClkOut equ (_ClkIn >> 2)
;MaxLength=DataLength+8
DataLength equ D'18' ; length of data(include DI0,DI1)
StartDelay equ D'10' ; 充電開始有個延遲,否則工作電流超不過截止電流
V_StartDelay equ D'3' ; 放電開始有個延遲,否則工作電流超不過截止電流
C_arrived equ D'3' ; 達到判據的次數
LSB equ 0x00
MSB equ 0x07
AT24C02 equ 0xA0 ; CAT24C02 芯片
PWM_WIN equ 0x06 ; 占空比還有5個周期就要跳變
;//#define Percent100 ; 占空比100%
#ifdef Percent100
TriScope equ H'03FF' ;三角波上到100%
HalfScope set (TriScope>>1) ;中點采樣
#endif
#define Percent40 ; 占空比40%
#ifdef Percent40
TriScope equ H'0199' ;三角波只能上到5V的40%,即2V,1024*0.4=409=H'0199'
HalfScope set (TriScope>>1) ;中點采樣
#endif
;#define Percent10 ; 占空比10%
#ifdef Percent10
TriScope equ H'0066' ;三角波只能上到5V的10%,即2V,1024*0.1=102=H'0066'
HalfScope set (TriScope>>1) ;中點采樣
#endif
; //-------------------- 定時器 T1 設置 -------------------------------
;TMR1H:TMR1L=65536-累加次數=65536-(延遲時間/tc)=65536-T*_ClkOut (分頻比為1:1)
; 1tc=4/5068800=0.789us
;#define Timer50ms ; 定時50毫秒
;#define Timer20ms ; 定時20毫秒
;#define Timer10ms ; 定時10毫秒
#define Timer5ms ; 定時5毫秒
#ifdef Timer50ms
;例:T=50ms T1_TICK=65536-T*_ClkOut=65536-0.05*5068800/4=65536-63360=2176=H'0880'
T1_TICK equ H'0880'
SEC1divTimer equ D'10'
RevTime equ D'4' ; 接收超時 4*50ms=200ms
#endif
#ifdef Timer20ms
;例:T=20ms T1_TICK=65536-T*_ClkOut=65536-0.02*5068800/4=65536-22344=40192=H'9D00'
T1_TICK equ H'9D00'
SEC1divTimer equ D'25'
RevTime equ D'10' ; 接收超時 10*20ms=200ms
#endif
#ifdef Timer10ms
;例:T=10ms T1_TICK=65536-T*_ClkOut=65536-0.01*5068800/4=65536-12672=52864=H'CE80'
T1_TICK equ H'CE80'
SEC1divTimer equ D'50'
RevTime equ D'20' ; 接收超時 20*10ms=200ms
#endif
#ifdef Timer5ms
;例:T=5ms T1_TICK=65536-T*_ClkOut=65536-0.005*5068800/4=65536-6336=59200=H'E740'
T1_TICK equ H'E740'
SEC1divTimer equ D'100'
RevTime equ D'40' ; 接收超時 40*5ms=200ms
#endif
T1CON_INIT equ B'00000001' ; 分頻比為1:1,定時器方式,TMR1ON=1
;T1CON_INIT equ B'00000000' ; 分頻比為1:1,定時器方式,TMR1ON=0
;//----- T1CON Bits ---------------------------------------------------------
;T1CKPS1 EQU H'0005'
;T1CKPS0 EQU H'0004'
;T1OSCEN EQU H'0003'
;NOT_T1SYNC EQU H'0002'
;T1INSYNC EQU H'0002' ; Backward compatibility only
;TMR1CS EQU H'0001'
;TMR1ON EQU H'0000'
; //-------------------- 波特率設置 ------------------------------------------------------------
; 5.0688MHz crystal,
#define HighSpeed ;Baud Rates for Asynchronous Mode (BRGH = 1)
#ifdef HighSpeed
;BRGH=1,高速: SPBRG=fosc/(16x 波特率)-1
TXSTA_INIT equ B'01000100' ;bit2(BRGH)=1
;SPBRG_INIT equ 0x41 ;4800bps,error=0
SPBRG_INIT equ 0x20 ;9600bps,error=0
;SPBRG_INIT equ 0x10 ;19200bps,error=-2.94%
#else
; BRGH=0,低速: SPBRG=fosc/(64x 波特率)-1
TXSTA_INIT equ B'01000000'
SPBRG_INIT equ 0x41 ;1200bps,error=0
;SPBRG_INIT equ 0x20 ;2400bps,error=
;SPBRG_INIT equ 0x10 ;4800bps,error=
;SPBRG_INIT equ 0x07 ;9600bps,error=
#endif
RCSTA_INIT equ B'11010000'
;// -------------------- PWM設置 ------------------------------------------------------------
;#define fPWM ;PWM的頻率=4.95K,分辨率10位
;#ifdef fPWM
PR2_INIT equ 0xFF ;Period register
CCPR1L_INIT equ B'00000000' ;占空比00%
CCP1CON_INIT equ B'00001100' ;ccp2X(bit5)=0,ccp2Y(bit4)=0
;#endif
OPTION_INIT equ B'10001001' ; weak pull-ups are disabled,
; Prescaler(1:2) to WDT ,WDT timeout=36ms
; bit6=INTEDG:=0表示RB0為下降沿觸發
INTCON_INIT equ B'11010000'
;bit7: GIE on
;bit6: PEIE on
;bit5: T0IE off
;bit4: INTE on
;bit3: RBIE off
T2CON_INIT equ B'00000000' ; setup Timer2,1:1 prescale, int clock
; //-----------------------------------------------------------------------------------------------
;
;>>>> PORTA <<<<
#define R46 PORTA,0 ;PWM的四個微調電阻R46,R47,R48,RR49
#define R47 PORTA,1 ;輸出0接通
#define CH PORTA,2 ;充電控制:輸出0有效,1關閉
#define DISCH PORTA,3 ;放電控制:輸出0有效,1關閉
#define BUTTON PORTA,4 ;設置/校準允許鍵(24wc02'wp)
#define WP PORTA,4 ;24wc02'wp(設置/校準允許鍵),復用
#define Enable485 PORTA,5 ; '1':485接收,'0':485發送
#define R46_TRIS TRISA,0
#define R47_TRIS TRISA,1
#define CH_TRIS TRISA,2
#define DISCH_TRIS TRISA,3
#define WP_TRIS TRISA,4
#define BUTTON_TRIS TRISA,4
PORTA_TRIS equ B'00010011' ; =0:output(復位為高阻)
PORTA_LATCH equ B'00111100'
;>>>> PORTA <<<<
;>>>> PORTB <<<<
; //--------7756 control setup I/O--------------------------
#define irqb PORTB,0 ;IRQ Bit的意思, 波形寄存器滿
#define csb PORTB,1 ;CS Bit的意思
#define RedLed PORTB,2 ;高亮
#define GreenLed PORTB,3
#define RST7756 PORTB,4
;//#define CF PORTB,5
#define RST7756_TRIS TRISB,4
PORTB_TRIS equ B'00100001'
PORTB_LATCH equ B'00110001'
;>>>> PORTB <<<<
;>>>> PORTC <<<<
#define SDA PORTC,0
#define SCL PORTC,1
#define PWM PORTC,2 ; CCP1用作PWM output
#define SCK PORTC,3
#define SDI PORTC,4
#define SDO PORTC,5
#define TX PORTC,6
#define RX PORTC,7
#define SDA_TRIS TRISC,0
#define SCL_TRIS TRISC,1
#define PWM_TRIS TRISC,2
PORTC_TRIS equ B'10010000'
PORTC_LATCH equ B'11011011'
;//// PORTC <<<<
#define TRUE 1
#define FALSE 0
; //--------------------------------------------------------------------------------------------
; Register File Variables
BFIIC equ 0x20 ; IIC數據緩沖區 20H--27H
; //--------------------------------------------------------------------------------
CBLOCK 0x28 ; EEPROM
BYTES
SourcePointer
DestPointer
SubAddress ; sub-address of slave (used in I2C_HIGH.ASM)
EETEMP ; load this reg with the data to be transmitted
ByteNumber ; 發送字節計數
tempCount ; The bit number (0:7) transmitted or received
I ;
; ---------------------------------------------------------------------
LoadOn ; 流程加載寄存器
WorkFlag ; 工作標志
fCOMM ; 通信標志字節
ByteReceived ; 串行通信已收字節數
RevTemp ; 發送時,因為關閉了接收中斷,也可以調用
OVERTIME
SecsPassed ; 流程已進行時間(滿StartDelay秒之后再判截止電流)
C_SEC ; 記滿 SEC1divTimer是1秒
; ---------------------------------------------------------------------
C_MIN ; 記滿60是1分
Minutes ; 分的累加器,靜置用
PWRUP55 ; registers to test at power up to
PWRUPAA ; see if warm start or cold start
spi ; spi reg data =0c hex
wordlen ; word length for rotate
VI_CSamp
I_sample_low ; lsb
; ---------------------------------------------------------------------
I_sample_middle ;
I_sample_high ; msb
V_sample_low ; lsb
V_sample_middle ;
V_sample_high ; msb
PWM_LOW ; New PWM1 duty cycle value
PWM_HI ; New PWM1 duty cycle value
DC_LOW
KeepValue_MID
DC_HI
ResistNet ; 記錄R46~R49的值
outd1 ; out to 7756 1st byte (msb 1st) of word
outd2 ; out to 7756 2st byte (msb 1st) of word
insd1 ; in from 7756 1st byte (msb 1st) of word
insd2 ; in from 7756 2st byte (msb 1st) of word
insd3 ; in from 7756 3st byte (msb 1st) of word
ENDC
; ---------------------------------------------------------------------
CBLOCK 0x50 ;通訊緩沖區50H-6FH:32 bytes
SERIALBUFFER ;通訊緩沖區首地址
A0 ;從站地址low
A1 ;從站地址middle
A2 ;從站地址high
CCODE ;控制碼
SBL ;數據長度
DI0 ;數據標識高位
DI1 ;數據標識高位
SDATA ;有效數據區
ENDC
; ---------------------------------------------------------------------
CBLOCK 0x71 ; EEPROM
fFLAG ; 通用標志
fFLAG2
TEMP
C_IVariety ; 電流采樣大于100mA的次數
C_LowerTerm ; 小于截止電流的次數
T1use ; used in timer1 interrupt
J
M
C_T
C_TermT_LOW ; 充放電計時
C_TermT_HI
;不能超過7FH
ENDC
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -