⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo.asm

📁 key scan and lcd display file it can run in the computer with sunplus compile
💻 ASM
📖 第 1 页 / 共 3 页
字号:
        R2 |= B_KeyReady;
        [GlobalFlag1] = R2;

        PUSH    R1,R1 TO [SP];
        CALL    F_ClrAllDigits;
        POP     R1,R1 FROM [SP];

SomeKeyIsPressed:
        CALL    F_ShiftDigitLeft;
        BP = Digit13;
        CALL    F_ShowDigit;

//------------------------------------------------
FinishedKeyCodeMapping:
        BP = KeyStatusBuf;
        R2 = 8;
ClrKeyStatusBuf:
        R1 = [BP];
        R1 = R1 LSL 4;
        R1 = R1 LSL 4;
        [BP++] = R1;
        R2 -= 1;
        JNZ     ClrKeyStatusBuf;

        R1 = 0;
        [KeyScanFlag] = R1;
        RETF;

.const  C_One       = 1;
.const  C_Two       = 2;
.const  C_Three     = 3;
.const  C_Four      = 4;
.const  C_Five      = 5;
.const  C_Six       = 6;
.const  C_Seven     = 7;
.const  C_Eight     = 8;
.const  C_Nine      = 9;
.const  C_Zero      = 10
.const  C_Star      = 11;
.const  C_Pound     = 12;

TB_KeyCode:
    .DW    C_One,   C_Four,  C_Seven, C_Star,  C_One,   C_Four,  C_Seven;
    .DW    C_Two,   C_Five,  C_Eight, C_Zero,  C_Two,   C_Five,  C_Eight;
    .DW    C_Three, C_Six,   C_Nine,  C_Pound, C_Three, C_Six,   C_Nine;
    .DW    C_One,   C_Four,  C_Seven, C_Star,  C_One,   C_Four,  C_Seven;
    .DW    C_Two,   C_Five,  C_Eight, C_Zero,  C_Two,   C_Five,  C_Eight;
    .DW    C_Three, C_Six,   C_Nine,  C_Pound, C_Three, C_Six,   C_Nine;
    .DW    C_One,   C_Four,  C_Seven, C_Star,  C_One,   C_Four,  C_Seven;
    .DW    C_Two,   C_Five,  C_Eight, C_Zero,  C_Two,   C_Five,  C_Eight;

//----------------------------------------------------------------------------*/
F_InitDisplay:
        CALL    F_ShowBatLevel;
        CALL    F_ShowOnHookSymbol;
        CALL    F_ShowDayTime;
        CALL    F_ShowWeek;
        CALL    F_ShowTotal;
        CALL    F_ShowNewTotal;
        GoTo    F_ShowYear;

//----------------------------------------------------------------------------------------
F_ShowBatLevel:
        R1 = [P_Seg0];
        R1 |= B_Com7;      // outline
        [P_Seg0] = R1;

        R2 = [BatLevel];
        BP = R2 LSR 4;
        BP = BP LSR 4;
        BP = BP LSR 4;
        BP += 1;
        TEST    BP,0x0007;
        JNZ     ShowBatLevel_05;
        BP -= 1;
ShowBatLevel_05:
        BP = BP LSR 1;
        BP += TB_PowerLevel;
        R1 = [BP];
        BP = TB_PowerSymbol;
        GoTo    ShowDigit_10;

TB_PowerLevel:
        .DW     0x0000;
        .DW     0x0001;
        .DW     0x0003;
        .DW     0x0007;

TB_PowerSymbol:
        .DW     P_Seg0,B_Com6, P_Seg0,B_Com5, P_Seg1, B_Com7,0;

//----------------------------------------------------------------------------*/
F_ShowOnHookSymbol:
        R1 = [P_Seg18];
        R1 |= B_Com7;                  //on hook symbol
        [P_Seg18] = R1;

        R1 = [P_Seg19];
        R1 |= B_Com7;
        [P_Seg19] = R1;

        R1 = [P_Seg17];
        R1 &= ~B_Com7;                 //off hook symbol
        [P_Seg17] = R1;
        RETF;

//----------------------------------------------------------------------------*/
F_ShowDayTime:
        R1 = [MonDayHr];
        [LcdMonDayHr] = R1;
        R1 = [MinSec];
        [LcdMinSec] = R1;

        R1 = [P_Seg16];
        R1 |= B_Com8;             //"-"
        [P_Seg16] = R1;

        R1 = [LcdMonDayHr];
        TEST    R1,0x3C00;
        JZ      ShowDayTime_22;   //illegal month

        R1 = R1 LSR 4;
        R1 = R1 LSR 4;
        R1 = R1 LSR 2;
        R1 &= 0x000F;
        CALL    F_BinaryToBcd;
        CMP     R1,0x000A;
        JNZ     ShowDayTime_20;
        R1 = 0;
ShowDayTime_20:
        BP = Month;
        CALL    F_ShowBcd;        //input : R1,R2 - BCD, BP - postion

        R1 = [LcdMonDayHr];
        R1 = R1 LSR 4;
        R1 = R1 LSR 1;
        R1 &= 0x001F;
        CALL    F_BinaryToBcd;
        BP = Day;
        CALL    F_ShowBcd;        //input : R1,R2 - BCD, BP - postion

ShowDayTime_22:
        R1 = [LcdMonDayHr];
        R1 &= 0x001F;
        CMP     R1,24;
        JNZ     ShowDayTime_23;
        RETF;                     //illegal hour

ShowDayTime_23:
        R3 = [P_Seg12];
        R3 &= 0xFFFF - (B_Com5+B_Com6);
        R3 |= B_Com6;
        CMP     R1,12;
        JB      ShowDayTime_25;
        R3 &= 0xFFFF - B_Com6;
        R3 |= B_Com5;

        CMP     R1,12;
        JBE     ShowDayTime_30;
        R1 -= 12;
        JMP     ShowDayTime_30;

ShowDayTime_25:
        CMP     R1,0;
        JNZ     ShowDayTime_30;
        R1 = 12;
ShowDayTime_30:
        [P_Seg12] = R3;

        CALL    F_BinaryToBcd;
        CMP     R1,0x000A;
        JNZ     ShowDayTime_50;
        R1 = 0;
ShowDayTime_50:
        BP = Hour;
        CALL    F_ShowBcd;        //input : R1,R2 - BCD, BP - postion

        R1 = [LcdMinSec];
        R1 = R1 LSR 4;
        R1 = R1 LSR 3;
        R1 &= 0x003F;
        CALL    F_BinaryToBcd;
        BP = Minute;
        GoTo    F_ShowBcd;        //input : R1,R2 - BCD, BP - postion

//----------------------------------------------------------------------------//
// Purpose : display Week of RTC or a call (Real Time Clock)
//----------------------------------------------------------------------------//
F_ShowWeek:
        R1 = [MonDayHr];
        [LcdMonDayHr] = R1;
        R1 = [Year];
        [LcdYear] = R1;

        R4 = [LcdMonDayHr];
        R4 = R4 LSR 4;
        R4 = R4 LSR 4;
        R4 = R4 LSR 2;
        R4 &= 0x000F;
        R4 -= 1;

        R2 = R4 + TB_1900WeekBase;
        R2 = [R2];          //Day VS. the month of 1900

        R1 = [LcdYear];
        R1 -= 1900;         //R1 - count of year
        R2 += R1;

        R1 = R1 LSR 2;      //R1 - count of leap year
        R2 += R1;

        CMP     R4,1;
        JA      ShowWeek_40;  //above than Feb.

        CALL    F_JudgeIfLeapYear;
        CMP     R3,0x8000;
        JNZ     ShowWeek_40;
        R2 -= 1;
ShowWeek_40:
        R1 = [LcdMonDayHr];
        R1 = R1 LSR 4;
        R1 = R1 LSR 1;
        R1 &= 0x001F;
        R1 -= 1;
        R2 += R1;
ShowWeek_45:                  //Divide by 7
        CMP     R2,7;
        JB      ShowWeek_50;
        R2 -= 7;
        JMP     ShowWeek_45;

ShowWeek_50:
        R1 = R2;
        R1 += TB_WeekPattern;
        R1 = [R1];
        BP = TB_WeekSymbol;
        GoTo    ShowDigit_10;

TB_WeekPattern:
        .DW     0x0001;
        .DW     0x0002;
        .DW     0x0004;
        .DW     0x0008;
        .DW     0x0010;
        .DW     0x0020;
        .DW     0x0040;

TB_WeekSymbol:
        .DW      P_Seg3, B_Com7, P_Seg4, B_Com7, P_Seg7, B_Com7;
        .DW      P_Seg8, B_Com7, P_Seg10,B_Com7, P_Seg11,B_Com7, P_Seg14,B_Com7,0;

//---------------------------------
// R1 - total calls in binary
//---------------------------------
F_ShowTotal:
        R2 = [P_Seg19];
        R2 |= B_Com8;                   //show 'TOTAL CALLS'
        [P_Seg19] = R2;

        R1 = [CidCnt];
        R1 &= 0x00FF;
        CALL    F_BinaryToBcd;
        BP = Total;
        GoTo    F_ShowBcd;

//---------------------------------
// R1 - new total calls in binary
//---------------------------------
F_ShowNewTotal:
        R2 = [P_Seg28];
        R2 |= B_Com8;                   //show 'NEW CALLS'
        [P_Seg28] = R2;

        R1 = [CidCnt];
        R1 = R1 LSR 4;
        R1 = R1 LSR 4;
        CALL    F_BinaryToBcd;
        BP = NewTotal;
        GoTo    F_ShowBcd;

//----------------------------------------------------------------------------//
// Purpose : display Year of RTC (Real Time Clock)
//----------------------------------------------------------------------------//
F_ShowYear:
        R1 = [Year];
        [LcdYear] = R1;

        R1 = [LcdYear];
        R1 -= 1900;
        R3 = 0x0091;
        CMP     R1,100;
        JB      ShowYear_20;
        R3 = 0x00A2;
        R1 -= 100;
ShowYear_20:
        CALL    F_BinaryToBcd;
        R2 = R2 LSL 4;
        R2 = R2 LSL 4;
        R2 = R2 LSL 4;
        R1 = R1 LSL 4;
        R1 = R1 LSL 4;
        R2 |= R1;
        R2 |= R3;

        BP = Digit5;             //start position

        R1 = R2 AND 0x000F;
        CALL    F_ShowDigit;
        R2 = R2 LSR 4;
        R1 = R2 AND 0x000F;
        CALL    F_ShowDigit;
        R2 = R2 LSR 4;
        R1 = R2 AND 0x000F;
        CALL    F_ShowDigit;
        R2 = R2 LSR 4;
        R1 = R2 AND 0x000F;
        GoTo    F_ShowDigit;

//---------------------------------
//  Input : R1
//  Output: R1 - high, R2 - low
//---------------------------------
F_BinaryToBcd:
        CALL    F_BinToBcd;

        CMP     R1,0;
        JNZ     BinaryToBcd_30;
        R1 = 0x000A;
BinaryToBcd_30:
        CMP     R2,0;
        JNZ     BinaryToBcd_99;
        R2 = 0x000A;
BinaryToBcd_99:
        RETF;

F_BinToBcd:
        R2 = R1;
        R1 = 0;
BinToBcd_10:
        CMP     R2,10;
        JB      BinToBcd_99;
        R2 -= 10;
        R1 += 1;
        JMP     BinToBcd_10;

BinToBcd_99:
        RETF;

//---------------------------------
// Input: R1 - high byte of BCD
//        R2 - low byte of BCD
//---------------------------------
F_ShowBcd:
        CALL    F_ShowDigit;
        R1 = R2;
        GoTo    F_ShowDigit;

//----------------------------------------------------------------------------//
// Purpose : shift all number on LCD to next right position,
//           the most right one is shifted out
// Don't change R1
//----------------------------------------------------------------------------//
F_ShiftDigitLeft:
        R4 = P_Seg1;
        BP = P_Seg4;
ShiftLeftLoop:
        R2 = [BP++];
        R2 &= 0x0600;       //b9,b10

        R3 = [R4];
        R3 &= 0xF9FF;
        R3 |= R2;
        [R4++] = R3;

        R2 = [BP++];
        R2 &= 0x0700;       //b9,b10

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -