📄 shuma.c
字号:
/*****************************************************************************
;文件名称:SHUMA.C
;创建日期:2007.6.19
;创 建 人:何 呈
; E-mail : hecheng@hrbeu.edu.cn
;修改日期:2007.6.19
;参考文档:无
;特殊说明: 完成数码管测试
;编译环境:Keil uVision3
******************************************************************************/
#include <reg52.h>
#include <intrins.h>
#define show_date P2
#define uchar unsigned char
#define uint unsigned int
sbit show_choice1=P3^4;
sbit show_choice0=P3^5;
sbit sound=P1^5;
//定义全局变量
uchar shuma; //数码管显示的内容 88H,83H,0c6H,0a1H,86H,8eH
code uchar Shu_ma[16]={0x0C0,0x0F9,0x0A4,0x0B0,0x099,0x092,0x082,0x0F8,0x080,0x090,0x88,0x83,0x0c6,0x0a1,0x86,0x8E}; //段查表
/*****************************************************************************
;函 数 名:void Delay(uint n)
;功 能: 延时函数
;说 明:除略延时(需要精确时,使用软件仿真)
;入口参数:无
;返 回 值:无
;创 建 人: 何 呈
;创建日期:2007.6.20
;修改日期:2007.6.20
******************************************************************************/
void Delay(uint n)
{
while(n--);
}
/*****************************************************************************
;函 数 名:void Show_Led(uchar n)
;功 能: 显示函数
;说 明:显示范围00~99
;入口参数:无
;返 回 值:无
;创 建 人: 何 呈
;创建日期:2007.6.20
;修改日期:2007.6.20
******************************************************************************/
void Show_Led(uchar n)
{
uchar i;
show_date=Shu_ma[n/10];
show_choice1 = 0;
for(i=0;i<100;i++)
_nop_();
show_choice1 = 1;
show_date=Shu_ma[n%10];
show_choice0 = 0;
for(i=0;i<100;i++)
_nop_();
show_choice0 = 1;
}
/*****************************************************************************
;函 数 名:void Show_Led(uchar n)
;功 能: 显示函数
;说 明:16进制显示,显示范围00~FF
;入口参数:无
;返 回 值:无
;创 建 人: 何 呈
;创建日期:2007.6.20
;修改日期:2007.6.20
******************************************************************************/
void Show_Hex(uchar n)
{
uchar i;
uint j;
for(j=0;j<400;j++)
{
show_date=Shu_ma[n/16];
show_choice1 = 0;
for(i=0;i<100;i++)
_nop_();
show_choice1 = 1;
show_date=Shu_ma[n%16];
show_choice0 = 0;
for(i=0;i<100;i++)
_nop_();
show_choice0 = 1;
}
}
/*****************************************************************************
;函 数 名:void time_0(void) interrupt 1 using 1
;功 能: 定时器中断函数
;说 明:在中断中调用了数码显示函数
;入口参数:无
;返 回 值:无
;创 建 人: 何 呈
;创建日期:2007.6.20
;修改日期:2007.6.20
******************************************************************************/
void time_0(void) interrupt 1 using 1
{
EA= 0; //关闭中断
TH0=64473/256;
TL0=64473%256;
Show_Led(shuma);
EA= 1; //打开中断
}
/*****************************************************************************
;函 数 名:void Init_Led(void)
;功 能: 初始化程序
;说 明:初始P2 和 P3.5 P3.4 T0
;入口参数:无
;返 回 值:无
;创 建 人: 何 呈
;创建日期:2007.6.20
;修改日期:2007.6.20
******************************************************************************/
void Init_Led(void)
{
show_date = 0;
show_choice1 = 1;
show_choice0 = 1;
EA= 0; //关闭中断
TMOD=(TMOD&0xf0)|0x01;
TH0=0xff00/256;
TL0=0xff00%256;
ET0=1; //
}
/*****************************************************************************
;函 数 名:void Test_End_Led(void)
;功 能: 测试数码管程序
;说 明:在此处不能关闭了全局中断! /\/\/\/\ ^_^ /\/\/\/\/\
因为要使用串口的接收中断
;入口参数:无
;返 回 值:无
;创 建 人: 何 呈
;创建日期:2007.6.20
;修改日期:2007.6.20
******************************************************************************/
void Test_End_Led(void)
{
EA= 1; //打开中断
TR0=0; //T0工作关闭
PT0=0; //低优先级
show_date = 0;
show_choice1 = 1;
show_choice0 = 1;
}
/*****************************************************************************
;函 数 名:void Test_Start_Led(void)
;功 能: 测试数码管程序
;说 明:无
;入口参数:无
;返 回 值:无
;创 建 人: 何 呈
;创建日期:2007.6.20
;修改日期:2007.6.20
******************************************************************************/
void Test_Start_Led(void)
{
uchar i=100;
Init_Led();
EA= 1; //打开中断
TR0=1; //T0工作开启
PT0=0; //低优先级
while(i--)
{
shuma = i;
Delay(3000);
}
Test_End_Led();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -