基于51單片機(jī)驅(qū)動(dòng)S8330E C語(yǔ)言程序
#include
#include
sbit DIN = P1^0;
sbit CLK = P1^1;
sbit STB = P1^2;
sbit Key = P3^4;
sbit LED = P1^7;
void Delay(unsigned int MS)
{
unsigned char us,usn;
while(MS!=0)
{
usn = 2; //for 12M
while(usn!=0)
{
us=0xf6;
while (us!=0){us--;};
usn--;
}
MS--;
}
}
void DelayKey(unsigned int Second , unsigned int MS100)
{ //輸入精確到0.1S,是用,
unsigned int i;
for(i=0;i
if(Key==0)
{
Delay(20);
while(Key==0) {Delay(20);}
break;
}
else Delay(10);
}
}
void LEDOnOfF(unsigned char n)
{
unsigned char i;
LED = 1;
for(i=0;i<2*n;i++)
{
LED = ~LED;
Delay(30);
}
}
void SetVout(unsigned char lv)
{
unsigned char i;
STB = 0; //芯片資料有點(diǎn)問(wèn)題,只需要在STB=0時(shí)送數(shù)據(jù),然后STB=1即有效
for(i=0;i<8;i++) //而不需要前后各一個(gè)脈沖,芯片說(shuō)在SEB=0時(shí)候Vout輸出Min也不對(duì)
{ //只有前面時(shí)序圖似乎有點(diǎn)正確,后面的詳細(xì)操作過(guò)程說(shuō)明有些問(wèn)題
DIN = (lv>>(7-i))&0x01;
CLK = 0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
CLK = 1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
CLK = 0; //送完一組數(shù)據(jù)后,CLK須為0,見(jiàn)時(shí)序圖,否則輸入數(shù)據(jù)無(wú)效
STB = 1;
LEDOnOfF(3);
}
void main (void)
{
unsigned char i;
Delay(10);
DelayKey(1,0);
LEDOnOfF(1);
DelayKey(1,0);
for(i=0;i<=255;i=i+5)
{
SetVout(i);
DelayKey(0,2);
}
}
評(píng)論