找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2230|回复: 1
打印 上一主题 下一主题
收起左侧

求大神,帮忙看看单片机的程序,用的TLC5615 数模转换

[复制链接]
跳转到指定楼层
楼主
ID:203219 发表于 2017-5-21 19:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
主要是主程序,和TLC5615 定义看不懂,求大神

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:203219 发表于 2017-5-21 19:06 | 只看该作者
#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 W1= P2^4;
sbit W2= P2^5;
sbit W3= P2^6;
sbit W4= 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[]=
{
        0x28,/*0*/
        0xEB,/*1*/
        0x32,/*2*/
        0x62,/*3*/
        0xE1,/*4*/
        0x64,/*5*/
        0x24,/*6*/
        0xEA,/*7*/
        0x20,/*8*/
        0x60,/*9*/
};        //共阳数码管段码表        没有小数点 0~9
uchar code table1[]=
{

        0x08,/*0*/
        0xCB,/*1*/
        0x12,/*2*/
        0x42,/*3*/
        0xC1,/*4*/
        0x44,/*5*/
        0x04,/*6*/
        0xCA,/*7*/
        0x00,/*8*/
        0x40,/*9*/
        0x29,/*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;

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

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

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

        W1=1;W2=1;W3=1;W4=0;
        P0=table1[10];
        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);       
                        }       
                }                       
        }
}








回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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