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

📄 demo.asm

📁 key scan and lcd display file it can run in the computer with sunplus compile
💻 ASM
📖 第 1 页 / 共 3 页
字号:
.public   _FIQ;
.public   _IRQ0;
.public   _IRQ1;
.public   _IRQ2;
.public   _IRQ3;
.public   _IRQ4;
.public   _IRQ5;
.public   _IRQ6;
.public   _IRQ7;
.public   _BREAK;

//----------------------------------------------------------------------------*/
.include     SPT6605.inc                //hardware definition

//----------------------------------------------------------------------------*/
.RAM

LcdYear:           .DW        0;
LcdMonDayHr:       .DW        0;
LcdMinSec:         .DW        0;

TwoHzIntFlag:      .DW        0;

GlobalFlag1:       .DW        0;
.const   B_KeyReady         = 0x0001;


//----------------------------------------------------------------------------*/
KeyScan512HzTmr:   .DW        0;
KeyScanFlag:       .DW        0;
KeyIntFlag:        .DW        0;
KeyStatusBuf:      .DW        8 DUP(0);

//----------------------------------------------------------------------------*/
Year:              .DW        0;
MonDayHr:          .DW        0;
MinSec:            .DW        0;
BatLevel:          .DW        0;
CidCnt:            .DW        0;

//----------------------------------------------------------------------------*/
.const   StackBottom        = 0x03FF;

//----------------------------------------------------------------------------*/
.code
.public _main;
_main:
        INT     OFF;                    //Disable Interrupt
        R1 = 0;
        [P_WakeUp] = R1;                //disable all wakeup sources
        [P_Int] = R1;
        R1 = 0x55AA;                    //clear Watchdog
        [P_Watchdog_Clr] = R1;
        SP = StackBottom;               //initialize stack
        R1 = B_8KHz+B_512Hz+B_128Hz+B_2Hz+B_Enable32768+B_Strong32768;
        [P_TimeBaseSet] = R1;           // it's very important to keep 32KHz
                                        // crystal running in strong mode
        R1 = [P_WakeUpClr];
        [P_WakeUpClr] = R1;             //clear all wakeup hardware flags

        R1 = B_NormalCpuClock;
        [P_SystemClock] = R1;           // 1MHz/4 - for normal operation

        CALL    F_InitHardWare;         //reset hardware
        CALL    F_ClrAllSRAM;

        R1 = 2005;                      //initialize date and time
        [Year] = R1;
        R1 = 1*1024 + 1*32;
        [MonDayHr] = R1;
        R1 = 0;
        [MinSec] = R1;
        R1 = 0x7000;
        [BatLevel] = R1;

        CALL    F_InitLcd;              //clear LCD dots, turn on LCD and
                                        // set LCD contrast
        CALL    F_InitDisplay;

        R1 = [P_IntClr];
        [P_IntClr] = R1;                //clear all interrupt requirement
        R1 = B_512HzInt+B_2HzInt+B_IoaInt;
        [P_Int] = R1;                   //set interrupt sources
        INT     FIQ,IRQ;
//----------------------------------------------------------------------------------------
MainLoop:
        R1 = 0x55AA;                    //Clear Watchdog
        [P_Watchdog_Clr] = R1;

        CALL    F_KeyScan;              //scan keyboard

        R1 = [TwoHzIntFlag];
        JZ      MainLoop;
        R1 = 0;
        [TwoHzIntFlag] = R1;

        R1 = [P_Seg6];
        R1 ^= B_Com8;                   //blinking colon ":"
        [P_Seg6] = R1;

        JMP     MainLoop;

//////////////////////////////////////////////////////////////////////////////////////////
//  Functions for Main Program
//////////////////////////////////////////////////////////////////////////////////////////

//----------------------------------------------------------------------------//
F_InitHardWare:
        R1 = 0;
        [P_IOA_Data] = R1;
        [P_IOA_Dir] = R1;
        [P_IoaWakeUp] = R1;
        R1 = 0x8000;                    //Enable IOA7 internal Pull-high resistor
        [P_IOA_PullR] = R1;

        R1 = 0;
        [P_IOB_Data] = R1;
        R1 = 0x00FF;
        [P_IOB_Dir] = R1;

        R1 = 0;
        [P_IOC_Data] = R1;
        R1 = 0x00FF;
        [P_IOC_Dir] = R1;

        R1 = 0;
        [P_IOD_Data] = R1;
        R1 = 0x00FF;
        [P_IOD_Dir] = R1;

        R1 = 0x000F;                    //IOC0 & IOC1 provide interrupt/wakeup
        [P_IOCD_Ctrl] = R1;             // at both rising & falling edges

        R1 = 0;
        [P_BatDet] = R1;
        [P_AdcCtrl] = R1;
        [P_AgcCtrl] = R1;
        [P_PgaInSelect] = R1;
        [P_Tmr_Ctrl] = R1;
        [P_DtmfTone] = R1;
        [P_Ch0Envelope] = R1;
//        [P_KeyScanCtrl] = R1;           //disable Key-Scan funcion that
//        [P_KeyScanMode] = R1;           // share pins with LCD segments
//        [P_KeyScanPort] = R1;
        [P_RiDet] = R1;
        [P_LineDetCtrl] = R1;

        R1 = 0x0080;                    //Enable Auto Key Scan
        [P_KeyScanCtrl] = R1;
        R1 = 0x007F;                    //IOA0~6 serve as Key Input port
        [P_KeyScanMode] = R1;
        R1 = 0;
        [P_KeyScanPort] = R1;
        RETF;

//----------------------------------------------------------------------------------------
F_ClrAllSRAM:
        BP = 0;
        R1 = 0;
ClrSRAMLoop:
        [BP++] = R1;
        CMP     BP,0x03FF;
        JNZ     ClrSRAMLoop;
        RETF;

//----------------------------------------------------------------------------*/
F_InitLcd:
        CALL    F_ClrLcd;       //clear all Lcd dots

        R1 = B_Duty+B_LcdEn + 0x000F;
        [P_LcdCtrl] = R1;
        RETF;

F_ClrLcd:
        R1 = 0;
        R2 = P_Seg0;
ClrLcdLoop:
        [R2++] = R1;
        CMP     R2,P_Seg39;
        JBE     ClrLcdLoop;
        RETF;

//****************************************************************************//
// State and vector definitions for keyboard scan
// The format is as follows:
// V_StateVector           .DW      Address of Subroutine
// .const  S_StateName              = State Number

V_KeyScan:
V_WaitKeyInterrup:         .DW        F_WaitKeyInterrupt;
.const   S_WaitKeyInterrup          = V_WaitKeyInterrup - V_KeyScan;
V_DelayToScanKey:          .DW        F_DelayToScanKey;
.const   S_DelayToScanKey           = V_DelayToScanKey - V_KeyScan;
V_KeyCodeMapping:          .DW        F_KeyCodeMapping;
.const   S_KeyCodeMapping           = V_KeyCodeMapping - V_KeyScan;
//----------------------------------------------------------------------------------------
F_KeyScan:
        R1 = [KeyScanFlag];
        R1 &= 0x000F;
        R1 += V_KeyScan;
        PC = [R1];
        PC = [R1];
//----------------------------------------------------------------------------------------
F_WaitKeyInterrupt:
        R1 = [KeyIntFlag];
        JZ      WaitKeyInterrupt_99;

        R1 = 30*512/1000;
        [KeyScan512HzTmr] = R1;
        R1 = S_DelayToScanKey;
        [KeyScanFlag] = R1;

WaitKeyInterrupt_99:
        RETF;

//----------------------------------------------------------------------------------------
F_DelayToScanKey:
        R1 = [KeyScan512HzTmr];
        JNZ     WaitKeyInterrupt_99;

        [KeyIntFlag] = R1;              //clear interrupt flag caused by key bounce
        [P_IOA_Dir] = R1;               //set IOA as input
        R1 = 0xFF00;                    //set internal pull high resistor
        [P_IOA_PullR] = R1;
        [P_KeyScanMode] = R1;           //disable key scan interrupt sources

        BP = KeyStatusBuf;
        R1 = 0x0081;                    //enable normal key scan mode and disable LCD driver signal
        [P_KeyScanCtrl] = R1;

        R1 = 0xFFFE;                    //scan line 1
        [P_KeyScanPort] = R1;
        NOP;
        R1 = [P_IOA_Data];
        R1 &= 0x007F;
//        R1 ^= 0x007F;
        R1 |= [BP];
        [BP++] = R1;
        
        R1 = 0xFFFD;                    //scan line 2
        [P_KeyScanPort] = R1;
        NOP;
        R1 = [P_IOA_Data];
        R1 &= 0x007F;
//        R1 ^= 0x007F;
        R1 |= [BP];
        [BP++] = R1;
                
        R1 = 0xFFFB;                    //scan line 3
        [P_KeyScanPort] = R1;
        NOP;
        R1 = [P_IOA_Data];
        R1 &= 0x007F;
//        R1 ^= 0x007F;
        R1 |= [BP];
        [BP++] = R1;

        R1 = 0xFFF7;                    //scan line 4
        [P_KeyScanPort] = R1;
        NOP;
        R1 = [P_IOA_Data];
        R1 &= 0x007F;
//        R1 ^= 0x007F;
        R1 |= [BP];
        [BP++] = R1;

        R1 = 0xFFEF;                    //scan line 5
        [P_KeyScanPort] = R1;
        NOP;
        R1 = [P_IOA_Data];
        R1 &= 0x007F;
//        R1 ^= 0x007F;
        R1 |= [BP];
        [BP++] = R1;

        R1 = 0xFFDF;                    //scan line 6
        [P_KeyScanPort] = R1;
        NOP;
        R1 = [P_IOA_Data];
        R1 &= 0x007F;
//        R1 ^= 0x007F;
        R1 |= [BP];
        [BP++] = R1;

        R1 = 0xFFBF;                    //scan line 7
        [P_KeyScanPort] = R1;
        NOP;
        R1 = [P_IOA_Data];
        R1 &= 0x007F;
//        R1 ^= 0x007F;
        R1 |= [BP];
        [BP++] = R1;

        R1 = 0xFF7F;                    //scan line 8
        [P_KeyScanPort] = R1;
        NOP;
        R1 = [P_IOA_Data];
        R1 &= 0x007F;
//        R1 ^= 0x007F;
        R1 |= [BP];
        [BP++] = R1;

        R1 = 0x0080;
        [P_KeyScanCtrl] = R1;
        R1 = 0x007F;
        [P_KeyScanMode] = R1;
        R1 = 0;
        [P_KeyScanPort] = R1;

        R1 = 0x8000;
        [P_IOA_PullR] = R1;

        R1 = S_KeyCodeMapping;
        [KeyScanFlag] = R1;
        RETF;

//----------------------------------------------------------------------------------------
F_KeyCodeMapping:
        BP = KeyStatusBuf;
GetChangedKey:
        R1 = [BP];
        R1 ^= 0x007F;
        R2 = R1 LSR 4;
        R2 = R2 LSR 4;
        R1 &= 0x007F;
        
        R2 ^= R1;
        R2 &= R1;
        R2 = R2 LSL 4;
        R2 = R2 LSL 4;
        R1 |= R2;
        [BP++] = R1;
        CMP     BP,KeyStatusBuf+7;
        JBE     GetChangedKey;

//----------------------------------------
        R1 = 0;                         //R1 - row number
SearchKeyLoop:
        BP = R1+KeyStatusBuf;
        R2 = [BP];
        R2 &= 0x7F00;
        JNZ     FindKeyChanged;         //test changed key
        R1 += 1;
        CMP     R1,8;
        JNZ     SearchKeyLoop;
        JMP     FinishedKeyCodeMapping;

FindKeyChanged:                         //R1 - row number
        R4 = KeyStatusBuf;
CheckOtherPressedKey:
        CMP     R4,BP;
        JZ      SkipCurrentLine;
        R3 = [R4];
        TEST    R3,0x007F;
        JNZ     FinishedKeyCodeMapping; //other key is still pressed
SkipCurrentLine:
        R4 += 1;
        CMP     R4,KeyStatusBuf+8;
        JNZ     CheckOtherPressedKey;

        R1 += 1;

        R3 = R1;                        //R1 = R1 * 7
        R1 = R1 LSL 3;
        R1 -= R3;
GetColumnLoop:
        R1 -= 1;
        R2 = R2 LSL 1;
        JPL     GetColumnLoop;
        TEST    R2,0x7FFF;
        JNZ     FinishedKeyCodeMapping; //more than one key pressed

        R1 += TB_KeyCode;
        R1 = [R1];                      //get key_code
        R2 = [GlobalFlag1];
        TEST    R2,B_KeyReady;
        JNZ     SomeKeyIsPressed;

⌨️ 快捷键说明

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