仿真原理图:
部分程序:
#define LED_GLOBAL 1
#include "led.h"
void ledDelay(uint ms)
{
uchar delayi;
while(--ms)
{
for(delayi=0;delayi<124;delayi++);
}
}
void init_led(void)
{
LED=segLedCode[0];
LED_CS1=0;
LED_CS2=0;
LED_CS3=0;
LED_CS4=0;
}
void ledWrite(uchar c,uchar n,uchar mod)
{
if(CHARACTER==mod)
{
LED=c;
}
else if(DIGITAL==mod)
{
if((c-'0')<0x0a)
{
LED=segLedCode[c-'0'];
}
else
{
LED=segLedCode[0];
}
}
switch(n)
{
case 0x01:
{
LED_CS1=0;
ledDelay(10);
LED_CS1=1;
break;
}
case 0x02:
{
LED_CS2=0;
ledDelay(10);
LED_CS2=1;
break;
}
case 0x03:
{
LED_CS3=0;
ledDelay(10);
LED_CS3=1;
break;
}
case 0x04:
{
LED_CS4=0;
ledDelay(10);
LED_CS4=1;
break;
}
default:
break;
}
}
void ledSweepDisplay(uchar *segCode,uchar segCodeMod,uchar segNumber) //循环显示子函数
{
uchar segCount;
for(segCount=0;segCount<segNumber;segCount++)
{
if(segCodeMod&0x01) //1代表此处显示任意字符 *
{
ledWrite(segCode[segCount],segCount+1,CHARACTER);
}
else
{
ledWrite(segCode[segCount],segCount+1,DIGITAL);
}
segCodeMod=segCodeMod>>1;
}
}
#define TLC2543_GLOBAL
#include "TLC2543.h"
uint read_TLC2543(uchar channel)
{
register uchar i;
uint tempAD = 0;
while(!TLC2543GetEoc()); //wait TLC2543 free
_delay_us(3);
channel <<= 4;
TLC2543Clk(TLC2543_CLR);
TLC2543_Cs(TLC2543_SET);
TLC2543_Cs(TLC2543_CLR); //_CS TLC2543 select
_delay_us(3);
for( i = 0; i < 12; i ++ )
{
tempAD <<= 1;
if( TLC2543GetDo() ) //read value
{
tempAD |= 0x01;
}
if( channel&0x80 )
{
TLC2543Di(TLC2543_SET);
}
else
{
TLC2543Di(TLC2543_CLR);
}
channel <<= 1;
TLC2543Clk(TLC2543_SET);
nop();
TLC2543Clk(TLC2543_CLR);
}
temp=(uchar)(voltageRead/0x0fff);
if(i==4)
displayBuff[i-1]=digitalNumber[temp]|0x80;
else
displayBuff[i-1]=digitalNumber[temp];
voltageRead=voltageRead%0x0fff;
voltageReadTemp=voltageRead<<1;
voltageRead=0x0000;
for(j=0;j<5;j++)
voltageRead+=voltageReadTemp;//voltageRead=voltageRead*10
}
}
}