BS814A-2 Serial Interface Application Description

BS814A-2 Serial Interface Application Description
BS814A-2 Serial Interface Application Description
D/N: HA0346E
Introduction
This text shows how the BS814A-2 serial interface is used.
Description
Transfer Format (Data & Clock)
Data Transfer Timing
Data Format
Start bit: When a key changes state, the Data pin outputs a low level to wake up the
master, which can then read the key status.
Bit 0 : Key1 sate – "0" = touched, "1" = not touched
Bit 1 : Key2 sate – "0" = touched, "1" = not touched
Bit 2 : Key3 sate – "0" = touched, "1" = not touched
Bit 3 : Key4 sate – "0" = touched, "1" = not touched
Bit 6~4 : Checksum – the total number of "0" is used to indicate how many keys have
been touched.
Bit 7 : Stop bit, always a "1", high level.
Bit
7
6~4
3~0
Descriptions
Function
Stop bit
Check Sum
Key4 ~ Key1 State
0: Touched / 1: Nnot Touched
1
100
0000
Check Sum = 100, Four keys are touched.
1
011
0001, 0010, 0100 or 1000
Check Sum = 011, Three keys are touched.
1
010
0011, 0101, 0110, 1001, 1010 or 1100
Check Sum = 010, Two keys are touched.
1
001
0111, 1011, 1101 or 1110
1
000
1111
Data
Stream
Check Sum = 001, One key is touched.
Check Sum = 000, No key is touched.
4-key Serial Data Stream Format
1
BS814A-2 Serial Interface Application Description
Program Flowchart
START
Initial
Clock Pin & Data Pin as Input
Set Clock Pin Low
Delay 30us
Set Clock Pin as Input
Read Data Pin State
Delay 30us
N
Get 8bits ?
Y
Error Function
N
Stop bit & Check
Sum Correct ?
Y
END
2
BS814A-2 Serial Interface Application Description
Program Example
SET Clock_C
SET Data_C
CLR Receive_Buffer
MOV A,8
MOV Receive_Count, A
Receive_Loop:
CLR Clock
CLR Clock_C
MOV A,20
SDZ Acc
JMP $-1
;----Read bit
SET Clock_C
SET C
SNZ Data
CLR C
RRC Receive_Buffer
MOV A,20
SDZ Acc
JMP $-1
SDZ Receive_Count
JMP Receive_loop
SNZ Receive_buffer.7
JMP Receive_error
MOV A,Receive_buffer
MOV Data_Buffer,A
CLR Key_pressed_Amount
MOV
RRC
SNZ
INC
SDZ
JMP
A,4
Data_Buffer
C
Key_Pressed_Amount
ACC
$-4
SWAPA Receive_buffer
XOR A,Key_Press_Amount
AND A,00000111B
SZ Z
JMP Receive_error
RET
Receive_error:
;set Clock pin as input
;set Data pin as input
;clear the Data Receive Buffer
;receive 8 bits of data
;Clock = low
;-----Delay
;delay 30us
;Clock = high
;read data through the data pin
;
;
;rotate data to the Receive Buffer
;-----Delay
;delay 30us
;-----Count down Receive_Count
;Receive 8 bits of data ?
;------Verify Data
;check stop bit = 1 ?
;--;
;
;
;----;
;total number of touched keys
;
;
;
;
;---- -Verify Check Sum
;
;data correct
;--do error function
RET
3
BS814A-2 Serial Interface Application Description
Additional Information
 Both the BS814A-2 Data pin and Clock pin have an integrated pull high resistor.
 When the touch key device detects that a touch key has been pressed, it will output a
low level on the Data pin which can be used to wake up the master MCU.
 The touch key status data can be read by using a polling method or waiting for the Data
pin to change to a low level.
 When a low clock signal is received, the key status data is prepared by the touch key
device. When the clock signal changes to a high level, the master reads the touch key
status data from the Data pin. Every 8 clock periods form a data group.
 After reading a data group, it is suggested to use the checksum bits to determine the
data integrity.
If there are any errors in reading the data, it is necessary to wait for about 6ms and
then read the data again.
4