欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

專注電子技術學習與研究
當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

基于51單片機驅動S8330E C語言程序

作者:huqin   來源:本站原創   點擊數:  更新時間:2013年11月15日   【字體:

 //S8330E是日本精工的一個電源IC,需要軟件調節電壓輸出值  
#include <reg52.h>  
#include <intrins.h>  
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<Second*100+MS100*10;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;        //芯片資料有點問題,只需要在STB=0時送數據,然后STB=1即有效  
    for(i=0;i<8;i++) //而不需要前后各一個脈沖,芯片說在SEB=0時候Vout輸出Min也不對  
    {           //只有前面時序圖似乎有點正確,后面的詳細操作過程說明有些問題  
        DIN = (lv>>(7-i))&0x01;  
        CLK = 0;  
        _nop_();  
        _nop_();  
        _nop_();  
        _nop_();  
        _nop_();  
        _nop_();  
        CLK = 1;  
        _nop_();  
        _nop_();  
        _nop_();  
        _nop_();  
        _nop_();  
        _nop_();  
  
    }  
    CLK = 0;        //送完一組數據后,CLK須為0,見時序圖,否則輸入數據無效  
    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);  
    }  
}  

關閉窗口

相關文章