|
//LED.c
#include <pic.h>
#include "ext_fuc.h"
#include "led.h"
#define GET_BIT(io ,bit) ( (io & (1<<bit))>>bit )
void NumToBuf(unsigned char num)//数值转换成码值
{
unsigned char tmp1,tmp2;
if (num>99) num=99;
/*
tmp1=(num/10);
tmp2=num-tmp1*10;
*/
tmp2=num%10;//取整数余数
tmp1=(num-tmp2)/10;
DisplayBuf[0]=tmp1;
DisplayBuf[1]=tmp2;
return;
}
void init_LED()
{
DisplayBuf[0]=0x7;
DisplayBuf[1]=0x8;
return;
}
//显示第一位LED
void Dis_LED1()
{
unsigned char tmp;
//段值清零
PORTC=0xff;
RA1=1;
Delayms(1);
tmp=DisplayBuf[0];
if (tmp>9) return;
//写段值
PORTC=leddata[tmp];
RA1=GET_BIT(leddata[tmp],6);
//写位值
RA5=1;
Delayms(1);
//清位值
RA5=0;
return;
}
//显示第一位LED
void Dis_LED2()
{
unsigned char tmp;
//段值清零
PORTC=0xff;
RA1=1;
Delayms(1);
tmp=DisplayBuf[1];
if (tmp>9) return;
//写段值
PORTC=leddata[tmp];
RA1=GET_BIT(leddata[tmp],6);
//写位值
RA4=1;
Delayms(1);
//清位值
RA4=0;
return;
}
void Dispaly()
{
Dis_LED1();
Dis_LED2();
return;
} |
|