/****************************************************************************/ /* 8050 Demo */ /* */ /* Compiler: MSC 6.00 */ /* Compile mode: large */ /* Project file: */ /* 8050.c */ /* ..\Lib\8000L.Lib [2004/07/26 or later] */ /* MiniOS7 v2.00.1 [2003/11/05 or later] */ /* */ /* Warning:(English) */ /* A channel may be destroyed if it is subjected to an input */ /* signal(Vcc) while it is configured to be an output channel. */ /* Please remove the external signal which connects to DI, */ /* before changing the channel status from DI mode to DO mode */ /* */ /* 警告:(Traditional-Chinese) */ /* 8050上有一個通道設定為DI且此通道有訊號輸入(Vcc),如果此時將此通道的 */ /* 狀態設定為DO,則這個通道可能會損壞 */ /* 通道狀態由DI改為DO之前,請先將DI的外部輸入線路移除 */ /* */ /* [25/Jul/2004] by Sean */ /****************************************************************************/ #include #include #include #include "..\..\..\..\Lib\8000e.h" #define MSC unsigned int NumberInput(int mode) { /* Parameter: mode: 16 denotes Hex others denotes DEC Return: return a interger number */ unsigned char sTemp[20]; unsigned int iRet; #ifdef MSC LineInput(sTemp,20); if(mode==16) sscanf(sTemp,"%x",&iRet); else sscanf(sTemp,"%d",&iRet); // iRet=atoi(sTemp); #else if(mode==16) Scanf("%x",&iRet); else Scanf("%d",&iRet); #endif return iRet; } void main (void) { int i,iTemp,iRet,iQuit; unsigned char cSlot,cMode[3]; unsigned int iChannel,imode; unsigned char sTemp[20]; unsigned int DOdata; Print("/*******************/\n\r"); Print("/* 8050 demo */\n\r"); Print("/* */\n\r"); Print("/* [20,Oct,2003] */\n\r"); Print("/*******************/\n\r"); Print("\n\r"); Print("Slot(0~3 or 0~7)="); cSlot=NumberInput(10); Print("The 8050 is plugged on the Slot%d\n\r\n\r",cSlot); while(1) { Print(" 0) Set DIO configuration\n\r"); Print(" 1) Get DIO configuration\n\r"); Print(" 2) Write DIO\n\r"); Print(" 3) Read DIO\n\r"); Print(" 4) Write signal channel DIO\n\r"); Print(" 5) Read signal channel DIO\n\r"); Print(" 6) Quit\n\r"); Print(" Please choose(0~6):"); iTemp=NumberInput(10); switch(iTemp) { case 0: Print("\r\nPlease Input the new configured value(Hex) (1:input,0: output):"); DOdata=NumberInput(16)& 0xffff; UDIO_WriteConfig_16(cSlot,DOdata& 0xffff); break; case 1: DOdata=UDIO_ReadConfig_16(cSlot); Print("\r\nThe configured value is %X\r\n",DOdata); break; case 2: Print("\r\nPlease Input the DO Data(Hex):"); DOdata=NumberInput(16)& 0xffff; UDIO_DO16(cSlot,DOdata); Delay(5); //Due to hardware limitation. It must delay 5 ms or more as reading di value, //after writing DO value. Print("\r\nThe DI data is %X\r\n",UDIO_DI16(cSlot)); break; case 3: DOdata=UDIO_DI16(cSlot); Print("\r\nThe DI data is %X\r\n",DOdata); break; case 4: Print("\r\nPlease Input the channel(0~15):"); iChannel=NumberInput(10)& 0xf; Print("\r\nPlease Input Output value(0:OFF,1:ON):"); iRet=NumberInput(10)& 0xf; if(iChannel>15 || iRet>1) Print("The invalid command, please input again\r\n"); else { DOdata=UDIO_DI16(cSlot); if(iRet) DOdata|= 1<< iChannel; else DOdata &= ~(1<15) Print("The invalid command, please input again\r\n"); else { DOdata=UDIO_DI16(cSlot); DOdata=DOdata>> iChannel & 0x1; Print("\r\nThe %d channel of DI is %X (0:OFF, 1:ON)\r\n",iChannel,DOdata); } break; case 6: exit(0); break; } Print("Please any key to continue\n\r\n\r"); Getch(); } }