📄 数码管.c
字号:
#include<at89x51.h>
#include<intrins.h>
#define unchar unsigned char
code unchar TAB[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; //共阳数码管段
unchar m,sz[8];
unsigned int i,a=0,b,c,d=0,th,h,tc,c,ts,s;
sbit SDATA_595 = P2^0 ; /*串行数据输入*/
sbit SCLK_595 = P2^1; /*移位时钟脉冲*/
sbit RCK_595 = P2^2; /*输出锁存器控制脉冲*/
static void WR_595(unsigned char data num2 )
{
unsigned char data count1;
for(count1=0;count1<=7;count1++)
{
if((num2&0x80)==0x80) /*最高位为1,则向SDATA_595发送1*/
SDATA_595=1; /*发出数据的最高位*/
else
SDATA_595=0;
num2<<=1; /*右移位*/
SCLK_595=0; /*产生上生沿*/
SCLK_595=1;
}
}
/*-------------------------------------------------------------------------------
打开锁存,更新74595输出子程序
---------------------------------------------------------------------------------*/
static void Out_595(void)
{
RCK_595=0;
_nop_();
_nop_();
RCK_595=1; /*上升沿锁存数据*/
}
void disp(void)
{
WR_595(TAB[1]);//送段数据
WR_595(0x01);//位选通
Out_595(); //锁存信号
WR_595(TAB[2]);
WR_595(0x02);
Out_595();
WR_595(TAB[3]);
WR_595(0x04);
Out_595();
WR_595(TAB[4]);
WR_595(0x08);
Out_595();
WR_595(TAB[5]);
WR_595(0x10);
Out_595();
WR_595(TAB[6]);
WR_595(0x20);
Out_595();
WR_595(TAB[7]);
WR_595(0x40);
Out_595();
WR_595(TAB[8]);
WR_595(0x80);
Out_595();
WR_595(0xff);
WR_595(0xff);
Out_595();}
/*-----------------------------------------------------------------
主函数
---------------------------------------------------------------*/
main()
{
while(1)
{
disp(); //显示子函数
calculate();//处理数据函数
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -