indr == 0x00
tcc == 0x01
pc == 0x02
status == 0x03
r3 == 0x03
c == 0
dc == 1
z == 2
p == 3
t == 4
ps0 == 5
ps1 == 6
rst == 7
;;
rsr == 0x04
port5 == 0x05
b1_pin == 0
b_pin == 1
g_pin == 2
r_pin == 3
;
port6 == 0x06
g1_pin == 7
sda == 2
sck == 1
;;
;;INTERRUPT STATUS REGISTER
rf == 0x0f;;INTERRUPT STATUS REGISTER
tcif == 0;;TCC TIMER OVERFLOW INTERRUPT FLAG,0->DISABLE
;;SET WHEN TCC TIMER OVERFLOW,RESET IN SOFTWARE
icif == 1;;PORT INPUT CHANGE INTERRUPT FLAG,0->DISABLE
;;SET WHEN PORT6 INPUT CHANGES,RESET IN SOFTWARE
exif == 2;;EXTERNAL INTERRUPT FLAG,0->DISABLE
;;SET BY FALLING EDGE ON /INT,RESET IN SOFTWARE
;;BIT3-BIT7 NOT USE
;;
;;CONT ==@0B--------;;CONTROL REGISTER
;;BIT0-BIT2 TCC/WDT PRESCALER BITS
;;PSR2 PSR1 PSR0 TCC RATE WDT RATE
;; 0 0 0 1 : 2 1 : 1
;; 0 0 1 1 : 4 1 : 2
;; 0 1 0 1 : 8 1 : 4
;; . . . . .
;; . . . . .
;; 1 1 1 1 :256 1 :128
pab == 3;;PRESCALE ASSIGNMENT BIT
;;0->TCC
;;1->WDT
te == 4;;TCC SIGNAL EDGE
;;0->LOW TO HIGH ADD TCC
;;1->HIGH TO LOW ADD TCC
ts == 5;;TCC SIGNAL SOURCE
;;0->INTERNAL INSTRUCTION CYCLE CLOCK
;;1->TRANSITION ON TCC PIN
;;/INT == 6;;INTERRUPT ENABLE FLAG
;;0->MASKED BY DISI OR HARDWARE INTERRUPT
;;1->ENABLE BY ENI/RETI INSTRUCTION
;;BIT7 NOT USE
;;I/O PORT CONTROL REGISTER
ioc5 == 0x05;;I/O PORT CONTROL REGISTER
;;0->OUTPUT PORT,1->INPUT PORT
ioc6 == 0x06;;I/O PORT CONTROL REGISTER
;;0->OUTPUT PORT,1->INPUT PORT
;;PULL DOWN CONTROL REGISTER
iocb == 0x0b;;0->ENABLE 1->DISABLE
;;7 6 5 4 3 2 1 0
;; P62 P61 P60 P52 P51 P50
;;OPEN DRAIN CONTROL REGISTER
iocc == 0x0c;;0->DISABLE 1->ENABLE
;;7 6 5 4 3 2 1 0
;;P67 P66 P65 P64 P62 P61 P60
;;PULL HIGH CONTROL REGISTER
iocd == 0x0d;;0->ENABLE 1->DISABLE
;;7 6 5 4 3 2 1 0
;;P67 P66 P65 P64 P62 P61 P60
;;WDT CONTROL REGISTER
ioce == 0x0e;;WDT CONTROL REGISTER
;;BIT7-->ENABLE WATCHDOG TIME
;;0->DISABLE,1->ENABLE
;;BIT6->DEFINE THE FUNCTION OF P60(INT)PIN
;;0->I/O PIN,1->INT PIN
;;BIT0-BIT5 NOT USE
;;INTERRUPT MASK REGISTER
iocf == 0x0f;;INTERRUPT MASK REGISTER
tcie == 0;;TCIF INTERRUPT ENABLE BIT
;;0->DISABLE
;;1->ENABLE
icie == 1;;ICIF INTERRUPT ENABLE BIT
;;0->DISABLE
;;1->ENABLE
exie == 2;;EXIF INTERRUPT ENABLE BIT
;;0->DISABLE
;;1->ENABLE
;;BIT3-BIT7 NOT USED
;============================================================
;===RAM AND FLAG DEFINE======================================
icflag == 0x10
do == 0
;
txbuf == 0x11
rxbuf == 0x12
cnt == 0x13
num == 0x14 ;
addr == 0x15
;
a_buf == 0x16
r3_buf == 0x17
;
flag == 0x18
time_bit0 == 0
time_bit1 == 1
time_bit2 == 2
time_bit3 == 3
time_bit4 == 4
time_bit5 == 5
time_bit6 == 6
time_bit7 == 7
;
iccounter == 0x19
;
color_loop == 0x1b
key_loop == 0x1c
;
loop_counter == 0x1e;
loop_counter1 == 0x1f
;
sfr_addr == 0x20
sfw_addr == 0x21
;
loop_counter3 == 0x22
loop_counter4 == 0x23
;
color_loop1 == 0x24
color_loop2 == 0x25
loop_counter7 == 0x26
;===========================================================
;===CONST DEFINE============================================
data_tcc == 0d235
;============================================================
;==============主程序清单=====================================
;============================================================
;============================================================
org 0x00
jmp start
;
org 0x08
jmp time
;
org 0x30
;======================================================
;============启动信号========================================
tx_start: mov a,@0b01111001
iow ioc6
nop
bs port6,sda
bs port6,sck
call icdelay
bc port6,sda
call icdelay
bc port6,sck
ret
;
;======================================================
;======================================================
;===============停止信号===============================
tx_stop: mov a,@0b01111001
iow ioc6
nop
bc port6,sda
bs port6,sck
call icdelay
bs port6,sda
call icdelay
bc port6,sda
bc port6,sck
ret
;
;======================================================
;======================================================
;===========发应答信号======================================
mack: mov a,@0b01111001
iow ioc6
nop
bc port6,sda
bs port6,sck
call icdelay
bc port6,sck
bs port6,sda
ret
;
;==========================================================
;==========发非应答信号=====================================
mnack: mov a,@0b01111001
iow ioc6
nop
bs port6,sda
bs port6,sck
call icdelay
bc port6,sda
bc port6,sck
ret
;
;==========================================================
;======================================================
;===向I2C写N字节,I2C首地址存于ADDR中,源数据的起始地址===
;===指针在ACC中========================================
;======================================================
wrnbyte: clr icflag
mov rsr,a ;源数据地址送R4中
mov a,@0xa0
mov txbuf,a
call tx_start
call tx
mov a,addr
mov txbuf,a
call tx
;
wrloop: mov a,indr
mov txbuf,a
call tx
inc rsr
djz num
jmp wrloop
call tx_stop
ret
;
;============================================================
;===从I2C读N字节,待读出的起始地址ADDR中,读出的数据存在以ACC===
;===为起始地址指针的寄存器中===================================
;=============================================================
rdnbyte: clr icflag
mov rsr,a ;目标地址送R4中
mov a,@0xa0
mov txbuf,a
call tx_start
call tx
mov a,addr
mov txbuf,a
call tx
call tx_start
相关文章