/************************************************************/
#include "SYSCFG.h"
/************************************************************/
volatile char W_TMP @ 0x70 ;//系统占用不可以删除和修改
volatile char BSR_TMP @ 0x71 ;//系统占用不可以删除和修改
/************************************************************/ //显示
void interrupt ISR(void); //中断函数
void xianshi_chushihua(); //显示初始化
void xianshi_jisuan(); //显示计算
void yanshi(); //延时
volatile char xianshi_a1 =0; //总显示的数据
volatile unsigned char xianshi_aa =0; //显示状态位
volatile unsigned char xianshi_c1 =0; //数码管百位字模
volatile unsigned char xianshi_c2 =0; //数码管十位字模
volatile unsigned char xianshi_c3 =0; //数码管个位字模
/************************************************************/
const unsigned char biao[]= //0-9,a-f,不显,负-
{
0x3f, //0,0
0x06, //1,1
0x5b, //2,2
0x4f, //3,3
0x66, //4,4
0x6d, //5,5
0x7d, //6,6
0x07, //7,7
0x7f, //8,8
0x6f, //9,9
0x77, //10,a
0x7c, //11,b
0x39, //12,c
0x5e, //13,d
0x79, //14,e
0x71, //15,f
0x00, //16,不显
0x40 //17,负-
};
/************************************************************/
#define led_wei1 PC1
#define led_wei1_out TRISC1
#define led_wei2 PB0
#define led_wei2_out TRISB0
#define led_wei3 PB2
#define led_wei3_out TRISB2
#define led_a PB7
#define led_a_out TRISB7
#define led_b PB4
#define led_b_out TRISB4
#define led_c PB1
#define led_c_out TRISB1
#define led_d PA4
#define led_d_out TRISA4
//#define led_e PA2←←←←←←←←←←
//#define led_e_out TRISA2←←←←←←←←←←
#define led_e PC0
#define led_e_out TRISC0
#define led_f PA3
#define led_f_out TRISA3
#define led_g PB3
#define led_g_out TRISB3
#define led_h PA0
#define led_h_out TRISA0
/*#define led_1 PC0
#define led_1_out TRISC0
#define led_2 PA7
#define led_2_out TRISA7*/
#define shuchu PA1
//#define shuchu_out TRISA1
/************************************************************/ //测温
void cewen_chushihua(); //测温初始化
/************************************************************/
/************************************************************/
main()
{
xianshi_chushihua(); //显示初始化
cewen_chushihua(); //测温初始化
while(1)
{
xianshi_jisuan(); //显示计算
yanshi();
yanshi();
xianshi_a1 ++;
if(xianshi_a1 >999){xianshi_a1 =0;}
}
}
/************************************************************/
void interrupt ISR(void) //中断函数
{
#asm;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
NOP;//系统设置不可以删除和修改
#endasm;//系统设置不可以删除和修改
if(T4UIE&&T4UIF)
{
T4UIF =1;
if(xianshi_aa ==0) //显示百位
{
led_wei1 =1; //消隐
led_wei2 =1;
led_wei3 =1;
if(xianshi_c1 &0b00000001){led_a =1;} else{led_a =0;}
if(xianshi_c1 &0b00000010){led_b =1;} else{led_b =0;}
if(xianshi_c1 &0b00000100){led_c =1;} else{led_c =0;}
if(xianshi_c1 &0b00001000){led_d =1;} else{led_d =0;}
if(xianshi_c1 &0b00010000){led_e =1;} else{led_e =0;}
if(xianshi_c1 &0b00100000){led_f =1;} else{led_f =0;}
if(xianshi_c1 &0b01000000){led_g =1;} else{led_g =0;}
if(xianshi_c1 &0b10000000){led_h =1;} else{led_h =0;}
led_wei1 =0;
led_wei2 =1;
led_wei3 =1;
}
if(xianshi_aa ==1) //显示十位
{
led_wei1 =1;
led_wei2 =1;
led_wei3 =1;
if(xianshi_c2 &0b00000001){led_a =1;} else{led_a =0;}
if(xianshi_c2 &0b00000010){led_b =1;} else{led_b =0;}
if(xianshi_c2 &0b00000100){led_c =1;} else{led_c =0;}
if(xianshi_c2 &0b00001000){led_d =1;} else{led_d =0;}
if(xianshi_c2 &0b00010000){led_e =1;} else{led_e =0;}
if(xianshi_c2 &0b00100000){led_f =1;} else{led_f =0;}
if(xianshi_c2 &0b01000000){led_g =1;} else{led_g =0;}
if(xianshi_c2 &0b10000000){led_h =1;} else{led_h =0;}
led_wei1 =1;
led_wei2 =0;
led_wei3 =1;
}
if(xianshi_aa ==2) //显示个位
{
led_wei1 =1;
led_wei2 =1;
led_wei3 =1;
if(xianshi_c3 &0b00000001){led_a =1;} else{led_a =0;}
if(xianshi_c3 &0b00000010){led_b =1;} else{led_b =0;}
if(xianshi_c3 &0b00000100){led_c =1;} else{led_c =0;}
if(xianshi_c3 &0b00001000){led_d =1;} else{led_d =0;}
if(xianshi_c3 &0b00010000){led_e =1;} else{led_e =0;}
if(xianshi_c3 &0b00100000){led_f =1;} else{led_f =0;}
if(xianshi_c3 &0b01000000){led_g =1;} else{led_g =0;}
if(xianshi_c3 &0b10000000){led_h =1;} else{led_h =0;}
led_wei1 =1;
led_wei2 =1;
led_wei3 =0;
}
xianshi_aa ++;
if(xianshi_aa >2){xianshi_aa =0;}
}
}
/************************************************************/
void xianshi_chushihua() //显示初始化
{
TIM4EN =1; //TIM4 模块时钟
SYSON =0; //睡眠模式下,系统时钟控制
T4ARPE =1; //计数周期的自动预装载
T4CKS1 =0; //00=Sysclk
T4CKS0 =0;
T4OPM =0; //单脉冲模式关闭
T4URS =1; //更新事件中断源计数器上溢
T4UDIS =0; //产生更新事件控制0=允许
T4CEN =1; //TIM4 计数器使能
T4PSC2 =1; //Timer4预分频器110 = 64
T4PSC1 =1;
T4PSC0 =0;
//T4CNT //Timer4计数值
TIM4ARR =103; //预装载值50HZ
//TIM4ARR =68; //预装载值75HZ
GIE =1; //全局中断
PEIE =1; //外设总中断
T4UIE =1; //Timer4 更新事件中断
//T4UG =1; //Timer4 更新事件软件中断
//T4UIF
/*
led_wei1 =1; //消隐
led_wei2 =1;
led_wei3 =1;
led_a =0;
led_b =0;
led_c =0;
led_d =0;
led_e =0;
led_f =0;
led_g =0;
led_h =0;
*/
led_wei1_out =0; //输出模式
led_wei2_out =0;
led_wei3_out =0;
led_a_out =0;
led_b_out =0;
led_c_out =0;
led_d_out =0;
led_e_out =0;
led_f_out =0;
led_g_out =0;
led_h_out =0;
}
/************************************************************/
void xianshi_jisuan() //显示计算
{
//xianshi_a1
unsigned char xianshi_b1;
unsigned char xianshi_b2;
unsigned char xianshi_b3;
xianshi_b1 =xianshi_a1 /100;
xianshi_b2 =xianshi_a1 %100/10;
xianshi_b3 =xianshi_a1 %10;
//xianshi_b1 =(xianshi_a1 >>8) &0x000f;
//xianshi_b2 =(xianshi_a1 >>4) &0x000f;
//xianshi_b3 =xianshi_a1 &0x000f;
xianshi_c1 =biao[xianshi_b1]; //百位
xianshi_c2 =biao[xianshi_b2]; //十位
xianshi_c3 =biao[xianshi_b3]; //个位
}
/************************************************************/
void cewen_chushihua() //测温初始化
{
TRISA7 =1; //PA7输入模式
ANSELA =1<<4; //第四路
//ADRESL //ADC 转换结果低有效位 (LSB)
//ADRESH //ADC 转换结果高有效位 (MSB)
ADCEN =1; //ADC 模块时钟
CHS2 =1; //100 = AN4
CHS1 =0;
CHS0 =0;
ADEX =0; //由指令置位 GO/DONE (软件触发)
//GO/DONE //启动 A/D 转换
ADON =1; //ADC 使能
ADFM =1; //右对齐
ADCS2 =1; //100 = SysClk/4
ADCS1 =0;
ADCS0 =0;
ADNREF1 =0; //负参考电压01 = GND
ADNREF0 =1;
ADPREF1 =0; //正参考电01 = VDD
ADPREF0 =1;
/*
ADPREF1 =0; //正参考电压00 = 内部 V ADC-REF
ADPREF0 =0;
ADINTREF1 =1; //10 = 3.0V
ADINTREF0 =0;
*/
}
/************************************************************/
void yanshi() //延时
{
unsigned char x1,x2;
for(x1 =100;x1 >0;x1 --)
for(x2 =80;x2 >0;x2 --);
}
/************************************************************/
/************************************************************/
/************************************************************/
/************************************************************/
|