📄 vdipnew.c
字号:
{
delay_ms(10); // Wait a bit and retry synchronisation
}
}
}
if (Got_Big_E == 0x01)
{
VNC1L_Small_e();
while (RX_FIFO_COUNT < 0x02)
{
delay_ms(10); // Wait for 2 byte response
}
serial_readfromrxfifo(&FIFOByte1); // Check that remaining 2 bytes are 'e' and 0x0D
serial_readfromrxfifo(&FIFOByte2);
if ((FIFOByte1 == 'e') && (FIFOByte2 == 0x0D))
{
Got_Small_e = 0x01; // If small e found, then synchronised
}
}
return Got_Small_e;
}
//*****************************************************************************************
//
// Look for disk - assumes long command set being used
//
//*****************************************************************************************
char VNC1L_FindDisk() // Return 0x01 if disk is found, else return 0x00
{
char FIFOByte1 = 0x00;
char FIFOByte2 = 0x00;
char FIFOByte3 = 0x00;
char FIFOByte4 = 0x00;
char FIFOByte5 = 0x00;
serial_sendbyte(0x0D); // Send carriage return
while (RX_FIFO_COUNT < 0x05); // Wait until at least 5 bytes in the Rx FIFO
serial_readfromrxfifo(&FIFOByte1); // Read bytes out of Rx FIFO
serial_readfromrxfifo(&FIFOByte2);
serial_readfromrxfifo(&FIFOByte3);
serial_readfromrxfifo(&FIFOByte4);
serial_readfromrxfifo(&FIFOByte5);
if ((FIFOByte1 == 'D') && (FIFOByte2 == ':') && (FIFOByte3 == 0x5C) && (FIFOByte4 == '>') && (FIFOByte5 == 0x0D)) // Check for prompt
{
return 0x01; // If prompt found, then return disk available
}
else
{
while (RX_FIFO_COUNT > 0x00)
{
serial_readfromrxfifo(&FIFOByte1); // Read any additional bytes out of the FIFO
}
return 0x00; // Return no disk available
}
}
//*****************************************************************************************
//
// Open file for write command (OPW) using long command set
//
//*****************************************************************************************
void VNC1L_OpenFile()
{
char FIFOByte = 0x00;
serial_sendbyte('O'); // Send 'O'
serial_sendbyte('P'); // Send 'P'
serial_sendbyte('W'); // Send 'W'
serial_sendbyte(' '); // Send ' '
serial_sendbyte('h'); // Send 'h'
serial_sendbyte('e'); // Send 'e'
serial_sendbyte('l'); // Send 'l'
serial_sendbyte('l'); // Send 'l'
serial_sendbyte('o'); // Send 'o'
serial_sendbyte('.'); // Send '.'
serial_sendbyte('t'); // Send 't'
serial_sendbyte('x'); // Send 'x'
serial_sendbyte('t'); // Send 't'
serial_sendbyte(0x0D); // Send carriage return
while (RX_FIFO_COUNT < 0x05) // Wait until at least 5 bytes in the Rx FIFO
{
delay_ms(10); // Wait for 5 byte response("D:\>" + 0x0D)
}
while (RX_FIFO_COUNT > 0x00)
{
serial_readfromrxfifo(&FIFOByte); // Read response bytes form FIFO
}
}
//*****************************************************************************************
//
// Write to file command (OPW) using long command set
//
//*****************************************************************************************
void VNC1L_WriteToFile(char *buffer, int number_character)
{
int j, stringlength = number_character;
char FIFOByte = 0x00;
serial_sendbyte('W'); // Send 'W'
serial_sendbyte('R'); // Send 'R'
serial_sendbyte('F'); // Send 'F'
serial_sendbyte(' '); // Send ' '
serial_sendbyte(0x00); // Send 0x00 - Number of bytes to write MSB
serial_sendbyte(0x00); // Send 0x00
serial_sendbyte(0x00); // Send 0x00
serial_sendbyte(0x52); // Send 0x0E - Number of bytes to write LSB
serial_sendbyte(0x0D); // Send carriage return
if (stringlength>=80)
{
for (j=0;j<=80;j++)
{
serial_sendbyte(*buffer++);
}
}
if (stringlength<80)
{
for (j=0;j<=stringlength;j++)
{
serial_sendbyte(*buffer++);
}
for (j=stringlength+1;j<=80;j++)
{
serial_sendbyte(*buffer++);
}
}
serial_sendbyte(0x0D); // Send carriage return
serial_sendbyte(0x0A); // Send line feed
serial_sendbyte(0x0D); // Send carriage return
while (RX_FIFO_COUNT < 0x05) // Wait until at least 5 bytes in the Rx FIFO
{
delay_ms(10); // Wait for 5 byte response("D:\>" + 0x0D)
}
while (RX_FIFO_COUNT > 0x00)
{
serial_readfromrxfifo(&FIFOByte); // Read response bytes form FIFO
}
}
//*****************************************************************************************
//
// Close file command (CLF) using long command set
//
//*****************************************************************************************
void VNC1L_CloseFile()
{
char FIFOByte = 0x00;
serial_sendbyte('C'); // Send 'C'
serial_sendbyte('L'); // Send 'L'
serial_sendbyte('F'); // Send 'F'
serial_sendbyte(' '); // Send ' '
serial_sendbyte('h'); // Send 'h'
serial_sendbyte('e'); // Send 'e'
serial_sendbyte('l'); // Send 'l'
serial_sendbyte('l'); // Send 'l'
serial_sendbyte('o'); // Send 'o'
serial_sendbyte('.'); // Send '.'
serial_sendbyte('t'); // Send 't'
serial_sendbyte('x'); // Send 'x'
serial_sendbyte('t'); // Send 't'
serial_sendbyte(0x0D); // Send carriage return
while (RX_FIFO_COUNT < 0x05) // Wait until at least 5 bytes in the Rx FIFO
{
delay_ms(10); // Wait for 5 byte response("D:\>" + 0x0D)
}
while (RX_FIFO_COUNT > 0x00)
{
serial_readfromrxfifo(&FIFOByte); // Read response bytes form FIFO
}
}
//*****************************************************************************************
//*****************************************************************************************
//*****************************************************************************************
//
// Interrupt routines go here
// Use receive character interrupt to add received characters to the RX FIFO
//
//*****************************************************************************************
//*****************************************************************************************
//*****************************************************************************************
void serial_IT(void) interrupt 4
{
if (RI == 1) /* if reception occur */
{
RI = 0; /* clear reception flag for next reception */
serial_addtorxfifo();
}
}
//*****************************************************************************************
//*****************************************************************************************
//*****************************************************************************************
//
// Main line code
//
//*****************************************************************************************
//*****************************************************************************************
//*****************************************************************************************
void main()
{
char Sync = 0x00;
P2=0x00;
VNC1L_State = VNC1L_Idle; // Initialise state to idle
serial_init(9600, FLOW_RTS_CTS); // Initialise Baud rate and flow control
delay_s(1); // Allow some time for power up
if (VNC1L_Sync() == Synchronised) // Synchronise to Vinculum
{
while (1) // Main state machine - do not return from here
{
switch (VNC1L_State)
{
case VNC1L_Idle:
Sync = VNC1L_Sync();
P2=0X00;
P2_0=1;
if (VNC1L_FindDisk() == GotDisk) // Check for disk
{
VNC1L_State = VNC1L_DiskAvailable; // Update state to indicate disk found
}
break;
case VNC1L_DiskAvailable:
P2_1=1;
VNC1L_OpenFile(); // Send open file for write command (OPW) - file name "hello.txt"
VNC1L_State = VNC1L_WriteFile; // Update state to indicate file has been created and can be written
break;
case VNC1L_WriteFile:
P2_2=1;
VNC1L_WriteToFile(reset_screen,40); // Send write file command (WRF) - write "Hello World!"
VNC1L_State = VNC1L_EndFile; // Update state to indicate file has been written and can now be closed
break;
case VNC1L_EndFile:
P2_3=1;
VNC1L_CloseFile(); // Send close file command (CLF)
VNC1L_State = VNC1L_WaitForRemove; // Update state to indicate witing for disk to be removed
break;
case VNC1L_WaitForRemove:
P2_4=1;
Sync = VNC1L_Sync();
if (VNC1L_FindDisk() != GotDisk) // Check for disk
{
VNC1L_State = VNC1L_Idle; // Update state to indicate disk has been removed and return to idle
}
P2=0XFF;
break;
default:
P2_5=1;
VNC1L_State = VNC1L_Idle; // Default to idle state
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -