找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3558|回复: 8
收起左侧

数控可调直流稳压电源程序

[复制链接]
ID:139093 发表于 2016-11-14 21:04 | 显示全部楼层 |阅读模式
#include "reg52.h"

//宏定义
#define uchar unsigned char
#define uint  unsigned int

//按键定义
sbit KEY1= P2^0;
sbit KEY2= P2^1;
sbit KEY3= P2^2;
sbit KEY4= P2^3;

//数码管定义
sbit W4= P2^4;
sbit W3= P2^5;
sbit W2= P2^6;
sbit W1= P2^7;

//DAC定义
sbit  CS_5615=P3^2;
sbit CLK_5615=P3^3;
sbit DAT_5615=P3^4;

//报警指示定义
sbit led = P3^6;
sbit Duan= P3^7;

uint  U;
uchar flag=0;
uint  a=0;

uchar code table[]=
{
        0xc0,/*0*/
        0xf9,/*1*/
        0xa4,/*2*/
        0xb0,/*3*/
        0x99,/*4*/
        0x92,/*5*/
        0x82,/*6*/
        0xf8,/*7*/
        0x80,/*8*/
        0x90,/*9*/
};        //共阳数码管段码表        没有小数点 0~9
uchar code table1[]=
{

        0x40,/*0*/
        0x79,/*1*/
        0x24,/*2*/
        0x30,/*3*/
        0x19,/*4*/
        0x12,/*5*/
        0x02,/*6*/
        0x78,/*7*/
        0x00,/*8*/
        0x10,/*9*/
        0xe3 /*U*/
};//带小数点的编码            0~9


void delay_ms(uint z)                          //延时函数
{
  uint a,b;
  for(a=z;a>0;a--)
   for(b=5;b>0;b--);
}

void  shuma(uint buf)
{
        uchar a,b,c,d;
        a=buf/1000;
        b=buf%1000/100;
        c=buf%100/10;
        d=buf%10;

        W2=W3=W4=1;        W1=0;
        P0=table[a];
        delay_ms(60);

        W1=W3=W4=1; W2=0;
        P0=table1[b];
        delay_ms(60);

        W1=W2=W4=1; W3=0;
        P0=table[c];
        delay_ms(60);

        W1=W2=W3=1; W4=0;
        P0=table1[d];
        delay_ms(60);
}

void tlc_5615(uint buf)
{
        uint a,c;
        c=buf;   
    CS_5615=0;
        for(a=16;a>0;a--)
        {
         DAT_5615=c>>15;      
         c=c<<1;
         CLK_5615=1;
         CLK_5615=0;                
    }
        CLK_5615=1;
        CLK_5615=0;
        CLK_5615=1;
        CLK_5615=0;
        CS_5615=1;
}

//主函数
void main(void)
{
        uchar n,i;
        n=5;
        U=0;
        led=0;
        delay_ms(3000);
        led=1;
        while(1)
        {                
    tlc_5615(U);
                shuma(U/n*10);
                if(flag==0)
                {
                        if(KEY1==0)
                        {
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                if(KEY1==0)
                                {
                                        if(U<120*n)                         //最大电压
                                        U=U+n;
                                        else if(U>=120*n)
                                        {
                                                led=0;
                                                for(i=0;i<50;i++)
                                                shuma(U/n*10);
                                                led=1;
                                        }

                                }       
                        }
                        if(KEY2==0)
                        {
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                if(KEY2==0)
                                {
                                        if(U>=n)
                                        U=U-n;
                                }       
                        }                       
                        if(KEY3==0)
                        {
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                if(KEY3==0)
                                {
                                        U=50*n;       
                                }       
                        }       
                        if(KEY4==0)
                        {
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                shuma(U/n*10);
                                if(KEY4==0)
                                {
                                        U=0;
                                }       
                        }
                }
                if(Duan==0)
                {
                        delay_ms(10);
                        if(Duan==0)
                        {
                                flag=1; //过流标志置高
                                led=0;
                                U=0;
                                tlc_5615(0);       
                        }       
                }                       
        }
}

回复

使用道具 举报

ID:1 发表于 2016-11-14 21:23 | 显示全部楼层
有电路图吗?
回复

使用道具 举报

ID:139093 发表于 2016-12-23 11:18 | 显示全部楼层

有原理图呢
回复

使用道具 举报

ID:96881 发表于 2017-2-28 18:24 | 显示全部楼层
请问有没有电原理图呢?谢谢
回复

使用道具 举报

ID:185661 发表于 2017-5-1 21:21 | 显示全部楼层
没原理,没电路图,,
回复

使用道具 举报

ID:232626 发表于 2017-9-12 13:52 | 显示全部楼层
,正在了解这方面的内容,先给个记号。
回复

使用道具 举报

ID:217754 发表于 2017-9-30 22:19 | 显示全部楼层
这东西。得留个印。期待图纸
回复

使用道具 举报

ID:249545 发表于 2017-12-9 11:39 | 显示全部楼层
求老师给相应图纸.求完整图纸.谢谢!
回复

使用道具 举报

ID:139093 发表于 2018-9-20 11:19 | 显示全部楼层
有啊
,等下我发上来
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表