纯模块

#include"reg52.h"
#include"delay.h"
#define uchar unsigned char 
#define uint unsigned int 

uchar code SMG_position[9] = {0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar code SMG_duanma[15] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff,0xc6,0x8c,0x88};
uchar yi,er,san,si,wu,liu,qi,ba;

void InitHC138(uchar channel)
{
	switch(channel)
	{
		case 4:P2 = (P2&0x1f)|0x80;break;
		case 5:P2 = (P2&0x1f)|0xa0;break;
		case 6:P2 = (P2&0x1f)|0xc0;break;
		case 7:P2 = (P2&0x1f)|0xe0;break;
	}
}

void ShowSMG_Bit(uchar dat,uchar pos)
{
	InitHC138(7);P0 = 0xff;//俗称“消影”
	InitHC138(6);P0 = SMG_position[pos];
	InitHC138(7);P0 = SMG_duanma[dat];
}

void InitSystem()
{
	InitHC138(4);P0 = 0xff;
	InitHC138(5);P0 = 0x00;
	InitHC138(6);P0 = 0xff;
	InitHC138(7);P0 = 0xff;
}

void All_SMG()
{
	InitHC138(6);P0 = 0xff;
	InitHC138(7);P0 = 0xff;
}

void Display_SMG()//单片机运行速度非常快,只要时间小于10ms,通过人的眼睛是识别不了变化的
{
	ShowSMG_Bit(yi,1);Delay2ms();
	ShowSMG_Bit(er,2);Delay2ms();
	ShowSMG_Bit(san,3);Delay2ms();
	ShowSMG_Bit(si,4);Delay2ms();
	ShowSMG_Bit(wu,5);Delay2ms();
	ShowSMG_Bit(qi,7);Delay2ms();
	ShowSMG_Bit(ba,8);Delay2ms();
	All_SMG();Delay2ms();
}


void main()
{
	while(1)
	{
		
	}
}

delay.c

#inlcude"delay.h"
#include"intrins.h"

void Delay2ms()		//@11.0592MHz
{
	unsigned char i, j;

	_nop_();
	_nop_();
	i = 22;
	j = 128;
	do
	{
		while (--j);
	} while (--i);
}

void Delay10ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 108;
	j = 145;
	do
	{
		while (--j);
	} while (--i);
}

delay.h

#ifndef _delay_h
#define _delay_h

void Delay2ms();
void Delay10ms();

#endif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值