📄 demo2nd.asm
字号:
mov a, 0x2A ;
mov ClockDelayT0, a ;
ClockDelayLoop:
delay 0x60 ;
dzsn ClockDelayT0 ;
goto ClockDelayLoop ;
//--- End of Delay --
//---
inc u10Sec ; // 1/100 Sec
mov a, u10Sec ;
sub a, 0x0A;
t1sn flag.0 ;
goto LCMUpdateClockShow;
//---- 1/10 Sec
clear u10Sec;
inc u100Sec; // 1/10 Sec
mov a, u100Sec;
sub a, 0x0A;
t1sn flag.0 ;
goto LCMUpdateClockShow;
//---- 1 Sec
clear u100Sec;
inc s1Sec; // 1 Sec
mov a, s1Sec;
sub a, 0x0A;
t1sn flag.0 ;
goto LCMUpdateClockShow;
//---- 10 Sec
clear s1Sec;
inc s10Sec; // 10 Sec
mov a, s10Sec;
sub a, 0x06;
t1sn flag.0 ;
goto LCMUpdateClockShow;
//---- 1 Min
clear s10Sec;
inc m1Min; // 1 Min
mov a, m1Min;
sub a, 0x0A;
t1sn flag.0 ;
goto LCMUpdateClockShow;
//---- 10 Min
clear m1Min;
inc m10Min; // 10 Min
mov a, m10Min;
sub a, 0x06;
t1sn flag.0 ;
goto LCMUpdateClockShow;
//---- 1 Hour
clear m10Min;
inc h1Hour; // 1 Hour
mov a, h1Hour;
sub a, 0x0A;
t1sn flag.0 ;
goto LCMUpdateClockShow;
//---- 10 Hour
clear h1Hour;
inc h10Hour; // 10 Hour
mov a, h1Hour;
sub a, 0x0A;
t1sn flag.0 ;
goto LCMUpdateClockShow;
//---
clear h10Hour;
LCMUpdateClockShow:
mov a, 0xcf; // Cursor position
call LCM_WriteCommandData;
delay 0x40;
mov a, u10Sec ;
or a, 0x30;
set1 LCMrs; // RS high,
call LCM_WriteCommandData;
set0 LCMrs; // RS low
mov a, 0xce; // Cursor position
call LCM_WriteCommandData;
delay 0x40;
mov a, u100Sec ;
or a, 0x30;
set1 LCMrs; // RS high,
call LCM_WriteCommandData;
set0 LCMrs; // RS low
mov a, 0xcc; // Cursor position
call LCM_WriteCommandData;
delay 0x40;
mov a, s1Sec ;
or a, 0x30;
set1 LCMrs; // RS high,
call LCM_WriteCommandData;
set0 LCMrs; // RS low
mov a, 0xcb; // Cursor position
call LCM_WriteCommandData;
delay 0x40;
mov a, s10Sec ;
or a, 0x30;
set1 LCMrs; // RS high,
call LCM_WriteCommandData;
set0 LCMrs; // RS low
mov a, 0xc9; // Cursor position
call LCM_WriteCommandData;
delay 0x40;
mov a, m1Min ;
or a, 0x30;
set1 LCMrs; // RS high,
call LCM_WriteCommandData;
set0 LCMrs; // RS low
mov a, 0xc8; // Cursor position
call LCM_WriteCommandData;
delay 0x40;
mov a, m10Min ;
or a, 0x30;
set1 LCMrs; // RS high,
call LCM_WriteCommandData;
set0 LCMrs; // RS low
mov a, 0xc6; // Cursor position
call LCM_WriteCommandData;
delay 0x40;
mov a, h1Hour ;
or a, 0x30;
set1 LCMrs; // RS high,
call LCM_WriteCommandData;
set0 LCMrs; // RS low
mov a, 0xc5; // Cursor position
call LCM_WriteCommandData;
delay 0x40;
mov a, h10Hour ;
or a, 0x30;
set1 LCMrs; // RS high,
call LCM_WriteCommandData;
set0 LCMrs; // RS low
//--
///----- PWM Control ---
//--
t1sn MusicCtrl.0; // asychronize with melody ?
goto ClockControlLED;
mov a, MusicFr;
ceqsn a, 0xFF;
goto NoMuteFrequencyLEDControl;
clear LED_Rpwm;
clear LED_Gpwm;
clear LED_Bpwm;
goto LEDPWM_UpdateExit;
NoMuteFrequencyLEDControl:
mov LED_Rpwm, a;
mov LED_Gpwm, a;
mov LED_Bpwm, a;
goto LEDPWM_UpdateExit;
ClockControlLED:
mov a, u100Sec ;
ceqsn a, 0x00;
goto LEDPWM_UpdateExit;
mov a, LED_Rpwm;
add a, 0x02;
mov LED_Rpwm, a;
mov a, LED_Gpwm;
add a, 0x08;
mov LED_Gpwm, a;
mov a, LED_Bpwm;
add a, 0x04;
mov LED_Bpwm, a;
LEDPWM_UpdateExit:
goto ClockDemoLoop ;
//------------------------------------------------------
//--- Prcoessor #2 LCM Controller Subroutine libraries
//------------------------------------------------------
LCM_EnTrigger:
set1 LCMen ; //En = 1
delay 0x18 ;
set0 LCMen ; // En= 0, Falling edge active
nop ;
ret ;
LCM_WriteCommandData:
// Write High Nibble bits
mov LCMArgu, a
set0 LCMd4;
set0 LCMd5;
set0 LCMd6;
set0 LCMd7;
t0sn LCMArgu.4;
set1 LCMd4;
t0sn LCMArgu.5;
set1 LCMd5;
t0sn LCMArgu.6;
set1 LCMd6;
t0sn LCMArgu.7;
set1 LCMd7;
// mov pd, a; // latch High Nibble Data Bus
call LCM_EnTrigger; //
set0 LCMd4; // clear Data bus
set0 LCMd5;
set0 LCMd6;
set0 LCMd7;
t0sn LCMArgu.0;
set1 LCMd4;
t0sn LCMArgu.1;
set1 LCMd5;
t0sn LCMArgu.2;
set1 LCMd6;
t0sn LCMArgu.3;
set1 LCMd7;
call LCM_EnTrigger ; //
ret ;
//========== end of MCU2 program ===========//
//========== start of MCU3 program =========//
//*************************************************************
//------ Processor-3 Program routine ------------------
//*************************************************************
// Processor 3 Demo is for PS/2 Mouse Interface
//-- Receiced the data from PS/2 Mouse Data and echo to RS232
//---- Processor 3 Running in 500KHz ----
fpp3boot:
// SP Setting for Processor 2
mov a, 0xE8 ;
mov sp, a ;
// enable another Processors
mov a, 0x1F;
mov fppen, a; // enable processor 4
fpp3MainLoop:
//---- Reset Command---
mov a, 0xFF;
mov PS2HostCommand, a;
set1 PS2Ctrl.7; // Parity !
call SendHostCommandToPS2;
//--
//----- return Success ?!
ceqsn a, 0x00;
goto PS2_Reset_Fail;
//--
call PS2_ReadDeviceData;
mov a, PS2DeviceData;
mov PS2_Ack, a;
ceqsn a, 0xFA;
goto PS2_Reset_Fail;
mov Tx1Buf, a;
call Tx1putc_hex;
//-- blank space --
mov a, 0x20;
mov Tx1Buf, a;
call Tx1putc;
//---
call PS2_ReadDeviceData;
mov a, PS2DeviceData;
mov PS2_BAT, a;
//---
call PS2_ReadDeviceData;
mov a, PS2DeviceData;
mov PS2_DeviceID, a;
//---
mov a, PS2_BAT;
mov Tx1Buf, a;
call Tx1putc_hex;
//-- blank space --
mov a, 0x20;
mov Tx1Buf, a;
call Tx1putc;
//--
mov a, PS2_DeviceID;
mov Tx1Buf, a;
call Tx1putc_hex;
//--
call Tx1Printf_LFCR;
//---
//---- Set Enable Command---
mov a, 0xF4;
mov PS2HostCommand, a;
set0 PS2Ctrl.7; // Parity !
call SendHostCommandToPS2;
//----- return Success ?!
ceqsn a, 0x00;
goto PS2_Reset_Fail;
//--
call PS2_ReadDeviceData;
mov a, PS2DeviceData;
mov PS2_Ack, a;
//
ceqsn a, 0xFA;
goto PS2_Reset_Fail;
//--- Normal Function ----
PS2_Normal_Loop:
call PS2_ReadDeviceData;
mov a, PS2DeviceData;
mov PS2_MouseB1, a;
//---
call PS2_ReadDeviceData;
mov a, PS2DeviceData;
mov PS2_MouseB2, a;
//---
call PS2_ReadDeviceData;
mov a, PS2DeviceData;
mov PS2_MouseB3, a;
//--
mov a, PS2_MouseB1;
mov Tx1Buf, a;
call Tx1putc_hex;
//-- blank space --
mov a, 0x20;
mov Tx1Buf, a;
call Tx1putc;
//--
mov a, PS2_MouseB2;
mov Tx1Buf, a;
call Tx1putc_hex;
//-- blank space --
mov a, 0x20;
mov Tx1Buf, a;
call Tx1putc;
//--
mov a, PS2_MouseB3;
mov Tx1Buf, a;
call Tx1putc_hex;
//-- blank space --
mov a, 0x20;
mov Tx1Buf, a;
call Tx1putc;
//---
call Tx1Printf_LFCR;
delay 0xff;
delay 0xff;
goto PS2_Normal_Loop;
//
PS2_Reset_Fail:
call PS2_DelaySometime;
call PS2_DelaySometime;
goto fpp3MainLoop; // goto Motor Begin;
//========== end of MCU3 program ===========//
SendHostCommandToPS2:
//---
mov a, 0x32;
mov PS2TimeOutCLK, a;
mov a, 0x08 ; // define SPI bit length = 8
mov PS2Shiftbit, a;
//---
//---
PS2DAT_Output;
PS2CLK_Output;
delay 0x1D; // delay 60uSec at least !
set0 PS2CLK; // Host Ack Command
delay 0xC8; // delay 60uSec at least !
set0 PS2DAT;
delay 0x4A;
set1 PS2CLK;
PS2CLK_Input; // make PS2_Clk is input
//---wait Start bit
wait0 PS2CLK; // Host clock Low
//---
// wait1 PS2CLK; // Host clock High
PS2_HostCommand_Out:
src PS2HostCommand;
swapc PS2DAT; // data out
//
wait1 PS2CLK; // wait clock high
wait0 PS2CLK; // wait clock low
dzsn PS2Shiftbit;
goto PS2_HostCommand_Out;
//--- Send Parity ---
t1sn PS2Ctrl.7;
goto PS2_HostParity;
set1 PS2DAT;
goto PS2_HostParityEnd;
PS2_HostParity:
set0 PS2DAT; //if parity is zero !!
PS2_HostParityEnd:
wait1 PS2CLK; // wait clock High
wait0 PS2CLK; // wait clock Low
//---
set1 PS2DAT;
//--- End of bit
nop;
PS2DAT_Input; // make PS2_Dat is input
//-- Ack Bit --
Wait_PS2_Ack: // Wait PS2 Acknowledge !
t1sn PS2DAT;
goto PS2_Ack_OK;
dzsn PS2TimeOutCLK;
goto Wait_PS2_Ack;
//------ PS2 Time-Out Fail !!----
delay 0x40;
ret 0x01; // return FAIL !!
PS2_Ack_OK:
delay 0x40;
ret 0x00; // return success !
//---
//==================================================
//--
//==================================================
PS2_ReadDeviceData:
mov a, 0x08 ; // define SPI bit length = 8
mov PS2Shiftbit, a;
PS2_KeyBoardScanRead:
wait0 PS2DAT; // wait PS2.Data low
wait1 PS2CLK; // Make Sure Clock High !
wait0 PS2CLK; // wait PS2.Clock Low, Start bit
wait1 PS2CLK; // wait PS2.Clock High
PS2_KeyBoardShiftIn:
wait0 PS2CLK; // wait PS2.Clock Low, sampling data pin
swapc PS2DAT;
src PS2DeviceData;
wait1 PS2CLK; // wait PS2.Clock High, Next Bit
dzsn PS2Shiftbit;
goto PS2_KeyBoardShiftIn;
wait0 PS2CLK; // wait PS2.Clock Low, parity bit
wait1 PS2CLK; //
wait0 PS2CLK; // wait PS2.Clock Low, Stop bit
wait1 PS2CLK; //
ret;
//------------------
//========== start of MCU4 program =========//
//*************************************************************
//------ Processor-4 Program routine ------------------
//*************************************************************
// Processor 4 is Demo a Stepper Motor Control, and the
// Enable/inhibit command is from IR-Command
//---- Processor 4 Running in 500KHz ----
fpp4boot:
// SP Setting for Processor 4
mov a, 0xEC ;
mov sp, a ;
// enable another Processors
mov a, 0x3F;
mov fppen, a; // enable processor 5
//--
mov a, ha@MOTORTab ; // Reload the base Address of Table
mov hb@MotorPt, a ;
clear MotorPhase;
clear MotorSpeed; // set default motor speed, Slowest!
clear MotorCtrl;
// set1 MotorCtrl.0;
fpp4MainLoop:
StepperMotorBegin:
t1sn MotorCtrl.0; // wait Motor Enable !
goto StepperMotorBegin;
//-- Motor On ---
inc MotorPhase;
mov a, MotorPhase;
and a, 0x03;
mov MotorPhase, a;
mov a, la@MOTORTab ; // Reload the base Address of Table
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -