本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
#include <reg52.h>
#include "leddri.h"
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
/* Global Variable */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*
uchar code LedSegTable[LED_TABLE_LEN]={'0',0x10,'1',0x76,'2',0x28,'3',0x24
,'4',0x46,'5',0x84,'6',0x80,'7',0x36,'8',0x00,'9',0x04
,'_',0xff};
*/
/* case uln2003 is invert logic */
/*uchar code LedSegTable[LED_TABLE_LEN]={'0',~0x10,'1',~0x76,'2',~0x28,'3',~0x24
,'4',~0x46,'5',~0x84,'6',~0x80,'7',~0x36,'8',~0x00,'9',~0x04
,' ',~0xff}; //762yong
*/
uchar code LedSegTable[LED_TABLE_LEN]={0x30,0xee,0x5e,0xef,0x31,0x88,0x5f,0x89,0x32,0xd6,0x60,0xd7,0x33,0xda,0x61,0xdb,
0x34,0xb8,0x62,0xb9,0x35,0x7a,0x63,0x7b,0x36,0x7e,0x64,0x7f,0x37,0xc8,0x65,0xc9,0x38,0xfe,0x66,0xff,
0x39,0xfa,0x67,0xfb,0x20,0x00,0x4e,0x01}; // 2051dai xiao shu dian ce shi
/*uchar code LedSegTable[]={0x30,0xee,0x5e,0xef,0x31,0x88,0x5f,0x89,0x32,0xd6,0x60,0xd7,0x33,0xda,0x61,0xdb,
0x34,0xb8,0x62,0xb9,0x35,0x7a,0x63,0x7b,0x36,0x7e,0x64,0x7f,0x37,0xc8,0x65,0xc9,0x38,0xfe,0x66,0xff,
0x39,0xfa,0x67,0xfb,0x20,0x00,0x4e,0x01}; // 2051dai xiao shu dian ce shi*/
uchar code LedLenghTable[MAX_LINES]={2,4,4,4,4}; // Led module length, each can be diffrent
uchar code LedModuleAddTable[MAX_LINES]={0,2,6,10,14}; // Each line's address in Led show data buffer
uchar LedDispBuff[MAX_SHOW_LEN];
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* */
/* FUNCTION: LEDShow */
/* */
/* REMARKS: Display Information In Refered Line */
/* */
/* INPUT: LineNo, from 0 to MAX_LINES-1 */
/* ShowData, ASCII String */
/* */
/* OUTPUT: TRUE means it is first time,FALSE not */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void LEDShow(uchar LineNo,char *ShowData)
{
uchar i,j,BuffPoint,k;
uchar OutData;
if(LineNo>=MAX_LINES) return;
BuffPoint=LedModuleAddTable[LineNo]; // Get target address offset
for(i=0;i<LedLenghTable[LineNo];i++) // Get Led code
{
for(j=0;j<LED_TABLE_LEN;j+=2) // Search led table
{
if(ShowData[i]==LedSegTable[j]) // Case found
{
break;
}
}
if(j<LED_TABLE_LEN)
{ // Found seg code, Set to led show buffer
LedDispBuff[BuffPoint]=LedSegTable[j+1];
}
else // Not find, default set
{
LedDispBuff[BuffPoint]=LED_DATA_DEFAULT;
}
BuffPoint++; // Next byte
}
for(i=0,k=0;i<MAX_LINES;i++)
{
k+=LedLenghTable[i]; //得到数据长度
}
for(i=(k-1);i!=255;i--) //指向最后一个数据
{
OutData=LedDispBuff[i];
for(j=0;j<8;j++)
{
PinSIOClk=0;
PinSIOClk=0;
OutData=OutData<<1; /* Right shift 1 bit */
PinSIOData=CY; /* Get high bit */
PinSIOData=CY;
PinSIOClk=1;
PinSIOClk=1;
}
}
PinSIOLatch = 0;
PinSIOLatch = 0;
soft_10us();
PinSIOLatch = 1; // Latch data
PinSIOLatch = 0;
soft_10us();
}
void LedBufferReset()
{
unsigned char i;
for(i=0;i<MAX_SHOW_LEN;i++)
//for(i=0;i<20;i++)
{
LedDispBuff[i]=LED_DATA_DEFAULT;
}
} |