?? ht1380.c
字號:
#include <reg51.h>
#include "HT1380.h"
//極短延時函數(shù):nNop()
void nNop(uchar x)
{
for(;x>0;x--);
}
//向SPI寫一字節(jié)數(shù)據(jù)函數(shù):SPI_WriteByte()
void SPI_WriteByte(uint x)
{
uchar i;
uint temp = 0x01;
SetPinDIO(0);
for(i=0;i<8;i++)
{
PinDIO = x & temp;
SetSCLK(1);
temp = temp << 1;
SetSCLK(0);
}
}
//向SPI讀一字節(jié)數(shù)據(jù)函數(shù):SPI_ReadByte()
uint SPI_ReadByte(void)
{
uchar i;
uint temp = 0x00;
SetPinDIO(1);
for(i=0;i<8;i++)
{
SetSCLK(1);
temp = (temp >> 1) | PinDIO;
SetSCLK(0);
}
return(temp);
}
//寫命令加寫數(shù)據(jù)函數(shù):WriteByte()
void WriteByte(uint x, uint y)
{
uchar i,j;
SetPinDIO(0);
for(i=0;i<8;i++)
{
PinDIO = x & 0x01;
SetSCLK(1);
x >>= 1;
SetSCLK(0);
}
for(j=0;j<8;j++)
{
PinDIO = y & 0x01;
SetSCLK(1);
y >>= 1;
SetSCLK(0);
}
}
//寫命令加讀數(shù)據(jù)函數(shù):ReadByte()
uint ReadByte(uint x)
{
uchar i,j;
uint temp = 0x00;
uint temp1;
SetPinDIO(0);
for(i=0;i<8;i++)
{
PinDIO = x & 0x01;
SetSCLK(1);
x >>= 1;
SetSCLK(0);
}
SetPinDIO(1);
for(j=0;j<8;j++)
{
SetSCLK(1);
temp1 = PinDIO;
temp1 <<= j;
temp = temp | temp1;
SetSCLK(0);
}
return(temp);
}
//使能(啟動)時鐘函數(shù):StartClock()
void StartClock(void)
{
SetREST(0);
nNop(1);
SetREST(1);
WriteByte(0x8e,0x00); //置WP = 0
SetREST(0);
nNop(1);
SetREST(1);
WriteByte(0x80,0x00); //置CH = 0
SetREST(0);
}
//單字節(jié)模式對HT1380寫數(shù)據(jù)函數(shù):HT1380_Single_Write()
void HT1380_Single_Write(uint RegNum, uint Data)
{
uint Cmd;
Cmd = 0x80 | (RegNum << 1);
//StartClock();
SetREST(1);
WriteByte(Cmd,Data);
SetREST(0);
//nNop(10);
}
//單字節(jié)模式對HT1380讀數(shù)據(jù)函數(shù):HT1380_Single_Read()
uint HT1380_Single_Read(uint RegNum)
{
uint Data;
uint Cmd;
Cmd = 0x81 | (RegNum << 1);
SetREST(1);
Data = ReadByte(Cmd);
SetREST(0);
return(Data);
}
//多字節(jié)模式對HT1380寫數(shù)據(jù)函數(shù):HT1380_Burst_Write()
void HT1380_Burst_Write(uint Data_Array[])
{
uint i,j,k;
uint Cmd = 0xbe;
uint temp;
SetPinDIO(0);
SetREST(1);
for(i=0;i<8;i++)
{
PinDIO = Cmd & 0x01;
SetSCLK(1);
Cmd >>= 1;
SetSCLK(0);
}
for(j=0;j<8;j++)
{
temp = Data_Array[j];
for(k=0;k<8;k++)
{
PinDIO = temp & 0x01;
SetSCLK(1);
temp >>= 1;
SetSCLK(0);
}
}
SetREST(0);
}
//多字節(jié)模式對HT1380讀數(shù)據(jù)函數(shù):HT1380_Burst_Read()
void HT1380_Burst_Read(uint Data_Array[])
{
uint i,j,k;
uint Cmd = 0xbf;
uint temp;
SetPinDIO(0);
SetREST(1);
for(i=0;i<8;i++)
{
PinDIO = Cmd & 0x01;
SetSCLK(1);
Cmd >>= 1;
SetSCLK(0);
}
SetPinDIO(1);
for(j=0;j<8;j++)
{
for(k=0;k<8;k++)
{
SetSCLK(1);
temp = PinDIO;
temp >>= k;
Data_Array[j] |= temp;
SetSCLK(0);
}
}
SetREST(0);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -