?? zz-yjcut.asm
字號:
;-----------------------------------------------
;單相表加485通訊的鄭州表程序
;主 芯 片:PIC16C72
;CPU:128bytes,22 I/O,2KROM,I2C/SPI,無USART
;-----------------------------------------------
;#include <pic16f72.inc>
indf equ h'0000'
tmr0 equ h'0001'
pcl equ h'0002'
status equ h'0003'
fsr equ h'0004'
porta equ h'0005'
portb equ h'0006'
portc equ h'0007'
pclath equ h'000a'
intcon equ h'000b'
pir1 equ h'000c'
tmr1l equ h'000e'
tmr1h equ h'000f'
t1con equ h'0010'
t2con equ h'0012'
sspcon equ h'0014'
ccpr1l equ h'0015'
ccpr1h equ h'0016'
ccp1con equ h'0017'
adresh equ h'001e'
adcon0 equ h'001f'
option_reg equ h'0081'
trisa equ h'0085'
trisb equ h'0086'
trisc equ h'0087'
pie1 equ h'008c'
pr2 equ h'0092'
sspadd equ h'0093'
sspstat equ h'0094'
adcon1 equ h'009f'
;-----------------------------------------------
;bzreg
; 0: 表示這一位是不是第一位
; 1: 表示前十位是不是已經接收完成
; 2: 表示一幀數據已經接收完成
; 3: 999999999999
; 4: 密碼正確
; 5: 33是否發送完畢
; 6: 此時發送的字節是FE
; 7: 本次通訊為鄭州協議通訊
;flag
; 0: 是否已完成掉電保護寫EEPROM
; 1: 繼電器合閘,拉閘標志
; 2: 繼電器拉、合閘延時標志
; 3: 2度電保存標志
; 4: 是否為正常的CF
; 5: 表示電表常數有誤
; 6:
; 7: 表示CF是否已經累加過
cblock 0x020
r0
r1
r2
temp1
iic_count
iic_back_addr
iic_addr
txbuf
rxbuf
eeprom
bcount
bitcount
delay_loops
zz_cnt
bzreg
length
endc
cblock 0x030
rx_timel
rx_timeh
rx_cnt
rx_sta
rx_fsr
rx_buff
rx_count
tx_cnt
tx_sta
tx_fsr
tx_buff
tx_count
status_temp
w_temp
fsr_temp
pclath_temp
endc
cblock 0x040
lcdtemp1
num1
bcd1
bcd2
bcd3
bcd4
bcd5
bcd6
aen1_zong
aen2_zong
aen3_zong
aen4_zong
aen_plusnum
num2
flag
metercons
endc
cblock 0x050
id1
id2
id3
id4
id5
id6
txdat1 ,txdat2, txdat3, txdat4, txdat5
txdat6 ,txdat7, txdat8, txdat9, txdat10
txdat11,txdat12,txdat13,txdat14,txdat15
txdat16,txdat17,txdat18,txdat19,txdat20
txdat21,txdat22,txdat23,txdat24,txdat25
txdat26,txdat27,txdat28,txdat29,txdat30
txdat31,txdat32,txdat33,txdat34,txdat35
txdat36,txdat37,txdat38,txdat39,txdat40
endc
cblock 0x0a0
relay_cnt1
relay_cnt2
display_cn1
display_cn2
flag_display
endc
;----------------------------------
#define ee_sda portb,1
#define ee_scl portb,2
#define con portb,3
#define usart_wr portc,6 ;portc,5
#define rx_pin portc,5 ;portc,4
#define tx_pin portc,7 ;portc,6
#define pwm portc,2
#define ht1621_cs portc,0
#define ht1621_rd portc,1
#define ht1621_wr portc,3 ;portc,2
#define ht1621_data portc,4 ;portc,3
#define pdown portb,5
#define cf portb,6
#define pdtest porta,3
#define relay_on porta,2
#define relay_off porta,1
#define relay_led portb,0
;-------------------------------
; 4MHz
#define tmr1h_cons278 0xfe ;265(feea)
#define tmr1l_cons278 0xf0
#define tmr1h_cons833 0xfc ;830.5(fc9a) 825(fca0)
#define tmr1l_cons833 0xa0
#define tmr1h_cons833_st 0xfc
#define tmr1l_cons833_st 0x50 ;0x5a
#define tmr1h_rx_cs 0xfd ;0xfd ;850(fc85)
#define tmr1l_rx_cs 0xb5 ;0xea ;0xc0
#define tmr1h_cons2byte 0xfc ;800
#define tmr1l_cons2byte 0xca ;0xba
#define slv_addr_r 0xa1
#define slv_addr_w 0xa0
#define lcdon 0x03
#define sysen 0x01
#define rc256 0x18
#define bias3 0x29
di equ 7
do equ 6
;-------------------------------
#define i2c_aen1_zong 0x00
#define i2c_cons 0x07
#define i2c_cs_aen1 0x0a
#define i2c_id1 0x10
#define i2c_code00 0x30
#define i2c_code01 0x34
#define i2c_code02 0x38
#define i2c_jbh1 0x40
#define i2c_ccbh1 0x50
#define i2c_first 0x60
;*****************************************************
org 0x000
clrf status
clrf pclath
goto start
org 0x004
nop
;*****************************************************
sio_rx_init
movwf w_temp
swapf status,0
bcf status,5
movwf status_temp
movf fsr,0
movwf fsr_temp
movf pclath,0
movwf pclath_temp
movlw high sio_rx_init
movwf pclath
clrwdt
movlw 0x18
subwf rx_count,0
btfsc status,0
goto sio_over_er
bsf status,5
movf display_cn1,0
addlw 1
movwf display_cn1
btfsc status,0
incf display_cn2
call relay_delay
bcf status,5
btfss pir1,0
goto init_over
; bcf pir1,0
btfss usart_wr ;if usart=0, goto tx write program
goto sio_tx_data
btfsc rx_sta,0 ;是否已接
goto sio_rx_datas
btfss rx_pin ;判斷RX_PIN是不是0,是0表示接收到起始位!
goto sio_rx_lop
movlw 0x01
addwf rx_timel
btfss status,0
goto init_rx_loop1
incf rx_timeh
movf rx_timeh,0
sublw 0x08
btfsc status,0
goto init_rx_loop1
clrf rx_timel
clrf rx_timeh
clrf rx_sta
clrf rx_count
clrf bzreg
init_rx_loop1
movlw tmr1h_cons278
movwf tmr1h
movlw tmr1l_cons278
movwf tmr1l
goto init_over
sio_rx_lop
clrf rx_timel
clrf rx_timeh
bsf rx_sta,0 ;設置已接收到起始位的標志位
btfsc rx_sta,2 ;rx_sta,2=0表示接收第一個字節數據,=1表示接收的是第一個以后的字節
goto $+3
movlw txdat1 ;設置間接尋址的首地址
movwf rx_fsr ;把首地址暫存在 rx_fsr中
movlw tmr1h_cons833_st
movwf tmr1h
movlw tmr1l_cons833_st
movwf tmr1l
bsf rx_sta,2
movlw 0x08
movwf rx_cnt
goto init_over
sio_rx_datas
btfsc rx_sta,4
goto rx_byte_cs
btfsc rx_sta,1
goto rx_1byte_over
rrf rx_buff
bcf rx_buff,7
btfsc rx_pin
bsf rx_buff,7
movlw tmr1h_cons833
movwf tmr1h
movlw tmr1l_cons833
movwf tmr1l
decfsz rx_cnt
goto init_over
bsf rx_sta,4
bcf rx_sta,1
goto init_over
rx_byte_cs
bcf rx_sta,4
bcf rx_sta,5
btfsc rx_pin
bsf rx_sta,5
movf rx_buff,0
movwf temp1
bcf rx_sta,6
call sio_byte_cs
btfsc status,0
call cs_1
btfss status,0
call cs_0
bsf rx_sta,1
movlw tmr1h_rx_cs
movwf tmr1h
movlw tmr1l_rx_cs
movwf tmr1l
goto init_over
cs_1
btfss rx_sta,5
bsf rx_sta,6
retlw 0
cs_0
btfsc rx_sta,5
bsf rx_sta,6
retlw 0
rx_1byte_over
bcf rx_sta,0
bcf rx_sta,1
bsf rx_sta,2
movf rx_fsr,0
movwf fsr
movf rx_buff,0
movwf indf
incf rx_fsr
incf rx_count
movlw tmr1h_cons278
movwf tmr1h
movlw tmr1l_cons278
movwf tmr1l
movf txdat1,0
xorlw 68h
btfsc status,2
goto init_over
sio_over_er
clrf rx_sta
clrf rx_count
clrf rx_fsr
goto init_rx_loop1
init_overzz8
incf zz_cnt
bsf bzreg,6
movf zz_cnt,0
xorlw 9
btfss status,2
goto init_over
clrf zz_cnt
bcf bzreg,6
bsf bzreg,5
goto sio_normal
init_overzz41
bsf bzreg,6
incf zz_cnt
movf zz_cnt,0
xorlw .41
btfss status,2
goto init_over
clrf zz_cnt
clrf bzreg
goto sio_normal
init_over
bcf pir1,0
movf fsr_temp,0
movwf fsr
movf pclath_temp,0
movwf pclath
swapf status_temp,0
movwf status
swapf w_temp,1
swapf w_temp,0
retfie
;**************************************
sio_tx_data
btfsc tx_sta,0
goto sio_tx_byte
bcf tx_pin
bsf tx_sta,0 ;start bit send ?
movlw 0x09
movwf tx_cnt
movlw tmr1h_cons2byte
movwf tmr1h
movlw tmr1l_cons2byte
movwf tmr1l
goto init_over
sio_tx_byte
btfsc flag,6
goto sio_tx_fe
btfsc tx_sta,2
goto sio_tx_stop
btfsc tx_sta,3
goto sio_tx_byte_loop
btfss bzreg,6
goto $+3
movlw 33h
goto $+4
movf tx_fsr,0
movwf fsr
movf indf,0
movwf tx_buff
movwf temp1
bsf tx_sta,3
call sio_byte_cs
sio_tx_byte_loop
rrf tx_buff
btfss status,0
bcf tx_pin
btfsc status,0
bsf tx_pin
decfsz tx_cnt
goto $+3
bsf tx_sta,2 ;9 bits send over ?
bcf tx_sta,3
movlw tmr1h_cons2byte
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -