专注电子技术学习与研究
当前位置:单片机教程网 >> 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);  
    }  
}  

关闭窗口

相关文章