⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 用18B20和DS1302来测试温度和显示时间 并在12864上显示
💻 C
字号:
#include <msp430x14x.h>
#include "BoardConfig.h"
#include "ds1302.h"
#include "DS18B20.h"
#include "gdata.h"
#include "cryfucns.h"
//要显示的6位温度数字
uchar dN[6],disptemp[8];   

void Disp_Numb(uint temper);
/*************************主函数*************************/
void main( void )
{
    uchar i;
    
    WDTCTL = WDTPW + WDTHOLD;           //关狗
    BoardConfig(0xba); 
    /*------选择系统主时钟为8MHz-------*/
    BCSCTL1 &= ~XT2OFF;                 //打开XT2高频晶体振荡器
    do
    {
        IFG1 &= ~OFIFG;                 //清除晶振失败标志
        for (i = 0xFF; i > 0; i--);     //等待8MHz晶体起振
    }
    while ((IFG1 & OFIFG));             //晶振失效标志仍然存在?
    BCSCTL2 |= SELM_2 + SELS;           //MCLK和SMCLK选择高频晶振
   
    //计数时钟选择SMLK=8MHz,1/8分频后为1MHz
    TACTL |= TASSEL_2 + ID_3; 
    //打开全局中断
    _EINT();
    Reset_DS1302();
    
    
    
    /*****测试更改和读出时间*****/
    Set_DS1302(wdata);   
    Get_DS1302(rdata);
    
    _NOP();         //在此处设置断点,观察rdata是否与wdata一致
    
    /*****测试连续读写时间寄存器*****/
    BurstWrite1302(bwdata);
    BurstRead1302(brdata);
    
    _NOP();         //在此处设置断点,观察brdata是否与bwdata一致
    
    /*****测试连续读写RAM*****/
    BurstWriteRAM(rwdata);
    BurstReadRAM(rrdata);
    
    _NOP();         //在此处设置断点,观察rrdata是否与rwdata一致

    
    while(1)
    {
       Disp_Numb(Do1Convert());
      // Disp1Char(4,1,dN[5]+0x30);
      // Disp1Char(5,1,dN[4]+0x30);
      // Disp1Char(6,1,0x2e);i         //0x2e是小数点对应的ASCII码值
      // Disp1Char(7,1,dN[3]+0x30);
      // Disp1Char(8,1,dN[2]+0x30);
       //Disp1Char(9,1,dN[1]+0x30);
      // Disp1Char(10,1,dN[0]+0x30
        BurstRead1302(rdata);
        disptemp[6] = shuzi[(rdata[0]&0xf0)>>4];
        disptemp[7] = shuzi[rdata[0]&0x0f];
        disptemp[3] = shuzi[(rdata[1]&0xf0)>>4];
        disptemp[4] = shuzi[rdata[1]&0x0f];
        disptemp[0] = shuzi[(rdata[2]&0xf0)>>4];
        disptemp[1] = shuzi[rdata[2]&0x0f];
       // DispNchar(4,1,8,disptemp);
        delay(50000);
    

 
    }          
}

/*******************************************
函数名称:Disp_Numb
功    能:将从DS18B20读取的11bit温度数据转换
          成数码管显示的温度数字
参    数:temper--11bit温度数据
返回值  :无
********************************************/
void Disp_Numb(uint temper)
{
    uchar i;
    
    for(i = 0;i < 6;i++) dN[i] = 0; //初始化显示变量

    //数值转换
    if(temper & BIT0) 
    {
        dN[0] = 5;
        dN[1] = 2;
        dN[2] = 6;
    }
    if(temper&BIT1)     
    {
        dN[1] += 5;
        dN[2] += 2;
        dN[3] += 1;
    }
    if(temper & BIT2)     
    {
        dN[2] += 5;
        dN[3] += 2;
        if(dN[2] >= 10)
        {
            dN[2] -= 10;
            dN[3] += 1;
        }
    }
    if(temper&BIT3)     
    {
        dN[3] += 5;
    }
    if(temper & BIT4)
    {
        dN[4] += 1;
    }
    if(temper & BIT5)     
    {
        dN[4] += 2;
    }
    if(temper & BIT6)
    {
        dN[4] += 4;
    }
    if(temper & BIT7)     
    {
        dN[4] += 8;
        if(dN[4] >= 10)
        {
            dN[4] -= 10;
            dN[5] += 1;
        }
    }
    if(temper & BIT8)
    {
        dN[4] += 6;
        dN[5] += 1;
        if(dN[4] >= 10)
        {
            dN[4] -= 10;
            dN[5] += 1;
        }
    }
    if(temper & BIT9)
    {
        dN[4] += 2;
        dN[5] += 3;
        if(dN[4] >= 10)
        {
            dN[4] -= 10;
            dN[5] += 1;
        }
    }
    if(temper & BITA)
    {
        dN[4] += 4;
        dN[5] += 6;
        if(dN[4] >= 10)
        {
            dN[4] -= 10;
            dN[5] += 1;
        }
        if(dN[5] >= 10)
        {
            dN[5] -= 10;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -