📄 display.c
字号:
return;
for( ; posit<=len+1; posit++){
if((*Pt=='.')||(*Pt==':')||(*Pt=='@')||(*Pt=='%')){
posit--;
DisplayDigitalIcon(Line, posit, *Pt, ON, bFront);
}
else{
if(posit == len+1) break; // is specal char
DisplayChar(Line, posit, *Pt, bFront);
DisplayDigitalIcon(Line, posit, '.', OFF, bFront);
DisplayDigitalIcon(Line, posit, ':', OFF, bFront);
DisplayDigitalIcon(Line, posit, '@', OFF, bFront);
DisplayDigitalIcon(Line, posit, '%', OFF, bFront);
}
Pt++;
}
if(bFillSpace&&(posit<=len)){
for(;posit<=len;posit++){
DisplayChar(Line, posit, ' ', bFront);
DisplayDigitalIcon(Line, posit, '.', OFF, bFront);
DisplayDigitalIcon(Line, posit, ':', OFF, bFront);
DisplayDigitalIcon(Line, posit, '@', OFF, bFront);
DisplayDigitalIcon(Line, posit, '%', OFF, bFront);
}
}
}
void ForceBack2FrontProc(void){
uchar n;
for(n=0;n<BUF_SIZE;n++)
VFD.FrontBuff[n] = VFD.BakupBuff[n];
}
void IconBack2FrontProc(uchar offset, uchar bb){
if(VFD.BakupBuff[offset] & (0x1<<bb))
VFD.FrontBuff[offset] |= (0x1<<bb); // set
else
VFD.FrontBuff[offset] &= ~(0x1<<bb); // clear
}
void LineBack2FrontBuff(uchar StartAddr, uchar Len){
uchar n;
for(n=0;n<Len;n++)
VFD.FrontBuff[StartAddr+n] = VFD.BakupBuff[StartAddr+n];
}
// process all characters
void VFDBack2FrontProc(void){
uchar n;
if(bIconUpdate){
for(n=0;n<4;n++)
VFD.FrontBuff[n] = VFD.BakupBuff[n];
VFD.FrontBuff[8] = VFD.BakupBuff[8];
VFD.FrontBuff[9] = VFD.BakupBuff[9];
VFD.FrontBuff[18] = VFD.BakupBuff[18];
VFD.FrontBuff[19] = VFD.BakupBuff[19];
bIconUpdate=0;
}
if(bLn1Update){
LineBack2FrontBuff(4, 4);
// for(n=0;n<4;n++)
// VFD.FrontBuff[4+n] = VFD.BakupBuff[4+n];
IconBack2FrontProc(2,3);
bLn1Update=0;
}
if(bLn2Update){
LineBack2FrontBuff(10, 4);
IconBack2FrontProc(3,0);
bLn2Update=0;
}
if(bLn3UpDate){
LineBack2FrontBuff(14, 4);
IconBack2FrontProc(3,5);
bLn3UpDate=0;
}
if(bStrLnUpdate){
LineBack2FrontBuff(20, 16);
bStrLnUpdate=0;
}
}
void ClrLineFrontBuff(uchar StartAddr, uchar Len){
uchar n;
for(n=0;n<Len;n++)
VFD.FrontBuff[StartAddr+n] =0;
}
//Input: bForceEn=1--- force display; 0---normal flash icon & character
void VFDFlashProcess(bit bForceEn){
static bit bFreshFlag=0;
#if 1
if(FTimer512ms||bForceEn){ // on
if(bFlashLine1){bLn1Update=1; bFreshFlag=1; }
if(bFlashLine2){bLn2Update=1; bFreshFlag=1; }
if(bFlashLine3){bLn3UpDate=1; bFreshFlag=1; }
if(bFlashStr1){bStrLnUpdate=1; bFreshFlag=1; }
if(bBit.FlashScroll[0]||bBit.FlashScroll[1]||bBit.FlashScroll[2]){
bIconUpdate=1; bFreshFlag=1; }
if(bFreshFlag){
bFreshFlag=0;
VFDBack2FrontProc( );
}
}
else{ // off
if(bFlashLine1)
ClrLineFrontBuff(4, 4);
if(bFlashLine2)
ClrLineFrontBuff(10, 4);
if(bFlashLine3)
ClrLineFrontBuff(14, 4);
if(bFlashStr1)
ClrLineFrontBuff(20, 16);
if(bFlashProtect) DispIcon(Seg_Protect, OFF);
if(bFlashAlarm) DispIcon(Seg_Alarm, OFF);
if(bFlashOpen) DispIcon(Seg_Open, OFF);
if(bFlashClose) DispIcon(Seg_Close, OFF);
if(bFlashU1) DispIcon(Seg_U1, OFF);
if(bFlashU1_2) DispIcon(Seg_U1_2, OFF);
if(bFlashI1) DispIcon(Seg_I1, OFF);
if(bFlashP) DispIcon(Seg_P, OFF);
if(bFlashU2) DispIcon(Seg_U2, OFF);
if(bFlashU2_3) DispIcon(Seg_U2_3, OFF);
if(bFlashI2) DispIcon(Seg_I2, OFF);
if(bFlashQ) DispIcon(Seg_Q, OFF);
if(bFlashU3_1) DispIcon(Seg_U3_1, OFF);
if(bFlashU3) DispIcon(Seg_U3, OFF);
if(bFlashI3) DispIcon(Seg_I3, OFF);
if(bFlashS) DispIcon(Seg_S, OFF);
if(bFlashEQ) DispIcon(Seg_EQ, OFF);
if(bFlashEP) DispIcon(Seg_EP, OFF);
}
#endif
}
void VFDShiftChar(uchar ascii){
uchar i;
for(i=0;i<8;i++){ // move 1 character
VFD.FrontBuff[20+i*2] = VFD.FrontBuff[20+i*2+2];
VFD.FrontBuff[20+i*2+1]=VFD.FrontBuff[20+i*2+3];
}
DisplayChar(LN4, 8, ascii, FRNT_BUF);
}
// string buffer is VFD.StrLn
void VFDRollProcess(void){
uchar n,k;
static bit bBegin,bFTimer;
static idata RollLen,RollIndex,StrLen;
#if 1
// string lenth must <=0x40;
if(!(RollStatus & bit_roll_enable)){
StrLen=RxLen;
bBegin=0;
return;
}
if(!bBegin){ // initial var, ready to start roll
bBegin = 1;
bFTimer = FTimer256ms;
// StrLen=RxLen;
RollLen = StrLen+8; // +8 space
RollIndex = 0;
n = RollStatus & bit_roll_start_funt;
if(n==0x04){ // stop 1 sec
DisplayStr2Buff(LN4, 1, VFD.StrLn, FILLSPACE, FRNT_BUF);
for(n=0;n<StrLen;n++){
k=0x1;
if(n<8){
k <<=n;
if(VFD.StrLn[STR_SIZE-2] &k)
DisplayDigitalIcon(LN4,n+1, '.', ON, FRNT_BUF);
}
}
RollIndex = 7;
StrLen |=0xc0; // stop for 1 second
}
else if(n==0){
DisplayStr2Buff(LN4, 1, " ", NO_FILLSPACE, FRNT_BUF); // +8 space
DisplayChar(LN4, 8, VFD.StrLn[0],FRNT_BUF);
RollIndex = 0;
}
return;
}
if(FTimer256ms^bFTimer){ // exicute 1 time per 256ms
if(StrLen>=0x40){
StrLen -=0x40;
return;
}
bFTimer=FTimer256ms;
RollIndex++;
if(RollIndex>(RollLen&0x3f)){
RollIndex=0; // end of one time roll & ready for next roll sting
n=RollStatus & bit_roll_times;
if(n){
if(RollLen >= n){
RollLen &=0x3f;
RollStatus &=0xfe; // disenable roll string
n =RollStatus & bit_roll_end_funt;
if(n == 0x20){ // b5,b4 =2
DisplayStr2Buff(LN4, 1, VFD.StrLn, FILLSPACE, FRNT_BUF);
for(n=0;n<16;n++)
VFD.BakupBuff[20+n] = VFD.FrontBuff[20+n];
}
// else if(n == 0x10){ // clear screen
// FreshAllBuff(ALL_OFF);
// }
else // display backup buffer
VFDBack2FrontProc( );
return;
}
RollLen += 0x40;
}
}
if(RollIndex<StrLen){
VFDShiftChar(VFD.StrLn[RollIndex]);
if(RollIndex<8){
k=0x1;
k <<=RollIndex-1;
if(VFD.StrLn[STR_SIZE-2] & k)
DisplayDigitalIcon(LN4,8-1, '.', ON, FRNT_BUF);
}
else if(RollIndex<16){
k=0x1;
k <<=RollIndex-8;
if(VFD.StrLn[STR_SIZE-1] &k)
DisplayDigitalIcon(LN4,8-1, '.', ON, FRNT_BUF);
}
}
else
VFDShiftChar(' ');
}
#endif
}
#if 0
void TestChar(void){
static uchar ascii=0;
uchar Ln,posit;
ascii++;
if(ascii==10)
ascii = 'a';
if(ascii == 'z'+1)
ascii=0;
for(Ln=1;Ln<=4;Ln++){
Ln=4;
// for(posit=1;posit<=((Ln<4)?4:8);posit++)
// posit=7;
for(posit=1;posit<= 2;posit++)
DisplayChar(Ln,posit,ascii, FRNT_BUF);
}
}
#endif
// Input: Ln=1~4; Posit=1~4(8); Len=1~4(8)
void DisplayStr(uchar Ln, uchar posit, uchar Len, uchar *Str, bit bFillspace){
uchar BufLen,n;
BufLen=(Ln>=LN4)?(STR_SIZE-2):LN1_SIZE;
if(!posit||posit>BufLen||Ln<1||Ln>4)
return;
VFD.StrLn[STR_SIZE-2]=VFD.StrLn[STR_SIZE-1]=0;
for( ; posit<=Len; posit++){
if(posit>BufLen /*|| (!*Str) */)
break;
if((*Str=='.')||(*Str==':')||(*Str=='@')||(*Str=='%')){
posit--;
RxLen--;
if(posit<=8){ // posit 1 ~ posit8
VFD.StrLn[STR_SIZE-2] |= (n|0x1)<<(posit-1);
}
else if(posit<=16){ // posit9 ~ posit16
VFD.StrLn[STR_SIZE-1] |= (n|0x1)<<(posit-8);
}
}
else{
if(Ln==LN4) VFD.StrLn[posit-1] = *Str;
}
Str++;
}
if(bFillspace){
for( ; posit<=BufLen; posit++){
if(Ln==LN4) VFD.StrLn[posit-1] = ' ';
}
}
}
void FreshAllBuff(bit All_OnOff){
uchar i;
if(All_OnOff){
for(i=0;i<BUF_SIZE;i++){
VFD.FrontBuff[i]=0xff;
VFD.BakupBuff[i]=0xff;
}
}
else{
for(i=0;i<BUF_SIZE;i++){
VFD.FrontBuff[i]=0x0;
VFD.BakupBuff[i]=0x0;
}
}
}
void ClrAllFlag(void){
uchar n;
for(n=0;n<3;n++)
bBit.FlashScroll[n]=0;
Percent=PerModulus=0;
RollStatus=0;
}
// display negtive or positive symbol
void DisplaySign(uchar ln, bit sign, bit bFront){
uchar addr, uc;
if(ln==LN1){
addr=2; uc=0x08;
}
else if(ln==LN2){
addr=3; uc=0x01;
}
else if(ln==LN3){
addr=3; uc=0x20;
}
//////// write buffer ///////////////
if(bFront){
if(sign) VFD.FrontBuff[addr] |= uc;
else VFD.FrontBuff[addr] &= ~uc;
}
else{
if(sign) VFD.BakupBuff[addr] |= uc;
else VFD.BakupBuff[addr] &= ~uc;
}
}
void SetZeroSign(uchar Ln, uchar Posit, uchar Dot, bit sign, bit bFront){
uchar n,zero=0;
zero= (Dot & 0xf0)>>4;
for(n=0; n<zero; Posit--,n++)
DisplayChar(Ln, Posit, '0', bFront); // write 0 to buffer
if(Posit){ // write sign to buffer
if(sign) DisplayChar(Ln, Posit, '-', bFront);
else DisplayChar(Ln, Posit, ' ', bFront);
Posit--;
for (; Posit>0;Posit--)
DisplayChar(Ln, Posit, ' ', bFront);
DisplaySign(Ln, 0, bFront); // write sign to buffer
}
else
DisplaySign(Ln, sign, bFront); // write sign to buffer
}
///////////////////////////////////////////////////////
void DisplayDigit(uchar Ln, int intData, uchar Dot, bit bFront){
bit sign=0;
if(Ln<LN1||Ln>LN3)
return;
if(intData>9999)
intData=9999;
if(intData<0){
sign=1;
intData = (~intData)+1; // get positive data
}
DisplayChar(Ln, 4, intData%10, bFront);
if(intData<10){
SetZeroSign(Ln, 3, Dot, sign, bFront);
}
else if(intData<100){
DisplayChar(Ln, 3, (intData/10)%10,bFront);
SetZeroSign(Ln, 2, Dot, sign, bFront);
}
else if(intData<1000){
DisplayChar(Ln, 3, (intData/10)%10, bFront);
DisplayChar(Ln, 2, intData/100, bFront);
SetZeroSign(Ln, 1, Dot, sign, bFront);
}
else if(intData<10000){
DisplayChar(Ln, 3, (intData/10)%10, bFront);
DisplayChar(Ln, 2, (intData/100)%10, bFront);
DisplayChar(Ln, 1, intData/1000, bFront);
DisplaySign(Ln, sign, bFront);
}
DisplayDigitalIcon(Ln, 1, '.', Dot & 0x4,bFront); // set or clear dot
DisplayDigitalIcon(Ln, 2, '.', Dot & 0x2,bFront);
DisplayDigitalIcon(Ln, 3, '.', Dot & 0x1,bFront);
}
uchar CheckSum(uchar *Pt, uchar cnt){
uchar chksm=0,n;
for(n=0;n<cnt;n++)
chksm += Pt[n];
return chksm;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -