2.02.2009

有人說他要program PT6961,但是看不懂中文,所以我自己翻譯一下

PT6961 can be controlled by MCU via a bus similiar to SPI interface (SDI/SDO/CLK/CS).
The 7-seg display and keyboard is implemented by scaning the hardware pin.

The "SPI" protocol:
The 1st byte is command, and the proceeding N bytes are datas (IN/Out).
The highest 2 bits of Command byte are Command Index, the remainding bits are the command content.
All the data bytes behind the Command byte are Data.

Command 1: Display Mode Setting

There are 18 control lines for controlling 7-seg display, so can drive 6 digits + 12 segment and 7 digits + 11 segments, 2 types of 7-seg.


Command 2: Data Setting Command

用來讀寫PT6961內部的memory (register ?)。用一個bit來決定是Read還是write。
Command之後就是Data (in/out)。
Read Command代表讀取Scan Key的內容,
KeyScan一次Scan K1,K2,K3三個key。
Scan Line有SG1 - SG10。
Read Data依照Scan的內容,每一個byte只有用到前6個bit,代表兩個Scan Line。
所以keyscan總共有5個byte。
Write Command代表寫入七段顯示輸出記憶體
一個七段顯示器需要12個bit,使用2個byte。
所以write command使用的memory有 7 x 2 = 14 byte


Command 3: Address Setting Command

Set the memory address for displaying.
顯示memory也是一樣,因為PT6961支援一個digit最多支援12 segment。
所以memory一個digit需要2個byte (16 bit),但是最高4 bit不使用。只用12 bit.

Command 4: Display Control Command

Turn On/Off the scanning operation for 7-seg display.
Set the duty cycle (to adjust the brightness)


Sample Code from PTC :
Command 0x03 1 : 7 digit 11 seg
Command 0x8F 4 : Display On, Pulse width 14/16
----clear ram----
Command 0x40 2 : Normal, Increment, Write to disp
Command 0xC0 - Data 0x00 repeat 14. 3 : write 14 datas to ram, start from 0
----load---------
Command 0x44 2 : Normal, Fix, Write to disp
----address:data set
Command 0x44 2 : Normal, Fix, Write to disp
Command Addr - Data Data
-0xC0 : 0x38 write 0x38 on 0
-0xC2 : 0x18 write 0x18 on 2
-0xC4 : 0x38 write 0x38 on 4
-0xC6 : 0x2C
-0xC8 : 0x3C
-0xCA : 0x1C
-0xCC : 0x30
REPEAT 4 Times
----set ram
Command 0x40 2 : Normal, Increment, Write to disp
Command 0xC0 Data 0xFF repeat 14 3 : Write 14 0xFF to disp starts from 0
----read key
Command 0x42 Read Data repeat 4 2 : Normal, Increment, Read 4 data.


spec的recommand algorithm:
Command 2
Command 3 Clear Memory
Command 1
Command 4 Disp OFF
Command 1
Command 4 Disp ON
Loop -
Command 2 Write Data
Command 3
Command 1
Command 4


It has no response when using PIC's internal SPI controller to communicate to PT6961, so I use GPIO to control, it's OK:

The code do Initialization:

void Pt6961Init(void)
{
char i;

STB=1;
SCL=1;

// command 2 : memory r/w, address inc
STB=0;
sout(0x40);
STB=1;

// command 3 : address set, and data
STB=0;
sout(0xC0);
for(i=0;i<14;i++)
sout(0x00);
STB=1;

// command 1 : display mode : digit & seg
STB=0;
sout(0x02);
STB=1;

// command 4 : disp on/off, disp duty
STB=0;
sout(0x87);
STB=1;

// command 1 : display mode
STB=0;
sout(0x02);
STB=1;

// command 4 : disp on/off, disp duty
STB=0;
sout(0x8F);
STB=1;

}

the sout function :

void sout(char data)
{
char i;
for(i=0;i<8;i++){
SCL=0;
SDO = data&0x01;
SCL=1;
data = data >> 1;
}
}

The code to send data to LED:

void LedPrint(char *str)
{
char data;
char i=0;

// command 2
STB=0;
sout(0x40); // write mode, auto inc address
STB=1;

// command 3
STB=0;
sout(0xC0); // set write start address=0
sout(str[0]); // 1st digit
sout(0x00); // 1 digit occupy 2 bytes
sout(str[1]); // 2nd digit
sout(0x00);
sout(str[2]); // 3rd digit
sout(0x00);
STB=1;
}

The Codes to Read KeyScanCode: data[5] is the result, only the heading 6 bits in each byte are effective.

// Read
STB=0;
sout(0x42); // read mode, auto inc address
data[0]=sin(); // read in 1st scan line only 0-5 useable
data[1]=sin(); // 2nd
data[2]=sin(); // 3rd
data[3]=sin(); // 4th
data[4]=sin(); // 5th
STB=1;

sin() 是

char sin(void)
{
char i;
char rc=0;

for(i=0;i<8;i++){
SCL=0;
rc = rc>>1;
SCL=1;
if(SDI)
rc |= 0x80;
}

return rc;
}



So, there are something wrong in the datasheet..
這一顆chip的protocol是固定將STB Low後第一個byte作Command,之後的都是Data,所以在任何Command後都可以加Data。 至於Data的動作就由上次Command 2的Read/Write bit來決定是Read Data或是Write Data。
如果是Write Data,Write Target Address就依照上次 Command 2中address auto increment bit的狀態跟Command 3 : target address的設定值決定。

沒有留言: