制作出来的实物图如下:
单片机源程序如下:
- #include "stc15.h" //reg51.h
- #include "intrins.h"
- #include "TM1637.h"
- typedef unsigned char u8;
- typedef unsigned int u16;
- sbit SO = P3^6;
- sbit SCK = P1^0;
- sbit CS = P3^7;
- /*------定义驱动数码管的片选表和断码表---------------*/
- /***************************数码管段选表*************************/
- unsigned char code SEGData[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x73,0x40,0x00,0x39};
- // 0 1 2 3 4 5 6 7 8 9 P - 灭 C
- unsigned char code SEGDataDp[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
- //有小数点只用于地址0xc1
- u16 temp,temp_1,t;
- u8 Flag_connect;
- bit flag;
- /******************定时器相关程序**********************/
- void time2_init(void) //定时器2初始化
- {
- AUXR |= 0x04; //使用模式1,16位定时器,使用"|"符号可以在使用多个定时器时不受影响
- T2L = 0xCD; //设置定时初值
- T2H = 0xD4; //设置定时初值
- AUXR |= 0x10; //定时器2开始计时
- IE2 |= 0x04; //开定时器2中断
- }
- void timer2 (void) interrupt 12 //Timer2 1ms中断函数
- {
- static u16 num;
- T2L = 0xCD; //设置定时初值
- T2H = 0xD4; //设置定时初值
- num++;
- if(num==170)
- {
- num=0;
- flag =1;
- }
-
- }
- void display( void )
- {
- if(Flag_connect==0) //Flag_connect为0 表示热电偶已连接,这时显示温度
- {
- TM1637_writeCammand(0x44);
- TM1637_writeData(0xc3, SEGData[temp%10]);
- TM1637_writeData(0xc2, SEGData[temp%100/10]);
- TM1637_writeData(0xc1, SEGData[temp%1000/100]);
- TM1637_writeData(0xc0, SEGData[temp/1000]);
- TM1637_writeCammand(0x8f);
- }
- else
- {
- TM1637_writeCammand(0x44);
- TM1637_writeData(0xc0, SEGData[16]);
- TM1637_writeData(0xc1, SEGData[16]);
- TM1637_writeData(0xc2, SEGData[16]);
- TM1637_writeData(0xc3, SEGData[16]);
- TM1637_writeCammand(0x8f);
- }
- }
复制代码
原理图: 无
仿真: 无
代码:
测温.rar
(763.18 KB, 下载次数: 302)
|