#include <REG51.h>
#define c_register 7
#define n_register 15
#define r_register 14
sbit Din = P2^1;
sbit ENB = P2^2;
sbit CLK = P2^3;
void MC145170_Reset(void)
{
unsigned char Bit_shift_counter;
Bit_shift_counter=0;
CLK=0;
ENB=1;
Din=0;
while(Bit_shift_counter<4)
{
CLK=1;
Bit_shift_counter++;
CLK=0;
}
/* ENB????,???????,Din???0? */
Bit_shift_counter=0;
ENB=0;
while(Bit_shift_counter<3)
{
CLK=1;
Bit_shift_counter++;
CLK=0;
}
/* ENB????,???????,Din?1? */
Din=1;
CLK=1;
CLK=0;
/* ENB????,???????,Din?0. */
Din=0;
CLK=1;
CLK=0;
/* ?????????,??Reset */
ENB=1;
}
void MC145170_Write_C_N_R_BitGrabber_Register(char BitGrabber_Register,unsigned int Bit_Stream)
{
CLK =0;
ENB =0;
while (BitGrabber_Register>=0)
{
Din=(Bit_Stream>>BitGrabber_Register)&0x0001; //???????????,&0x0001???
CLK=1; //???????
CLK=0;
BitGrabber_Register --;
}
ENB=1; //????
}
void main()
{
MC145170_Reset();
MC145170_Write_C_N_R_BitGrabber_Register( c_register,0x63);
MC145170_Write_C_N_R_BitGrabber_Register( r_register,5000);
MC145170_Write_C_N_R_BitGrabber_Register( n_register,12648);
while(1);
}