// tmc10vw.cpp : implementation of the CTmc10View class // #include "stdafx.h" #include "tmc10.h" #include "tmc10doc.h" #include "tmc10vw.h" #include "dio.h" void init_watchdog(); void reload_watchdog(); void Delay(unsigned t); unsigned Base; #ifdef _DEBUG #undef THIS_FILE static char BASED_CODE THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTmc10View IMPLEMENT_DYNCREATE(CTmc10View, CView) BEGIN_MESSAGE_MAP(CTmc10View, CView) //{{AFX_MSG_MAP(CTmc10View) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTmc10View construction/destruction CTmc10View::CTmc10View() { // TODO: add construction code here } CTmc10View::~CTmc10View() { } ///////////////////////////////////////////////////////////////////////////// // CTmc10View drawing void CTmc10View::OnDraw(CDC* pDC) { CTmc10Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here CClientDC dc(this); int i,y=0,tt=100; char ch[80]; unsigned in1,in2; short sAB; float fAB; Base=0x200; sAB=DIO_ShortSub2((short)1, (short)2); sprintf(ch,"DIO_ShortSub2(1,2)=%d",sAB); dc.TextOut(0,(y++)*16,ch); fAB=DIO_FloatSub2((float)1.0, (float)2.0); sprintf(ch,"DIO_FloatSub2(1.0,2.0)=%f",fAB); dc.TextOut(0,(y++)*16,ch); DIO_OutputByte(Base+5,0x55); in1=DIO_InputByte(Base+4); in2=DIO_InputByte(Base+5); sprintf(ch,"DO=0x55, DI1=%x DI2=%x",in1,in2); dc.TextOut(0,(y++)*16,ch); DIO_OutputByte(Base+5,0xAA); in1=DIO_InputByte(Base+4); in2=DIO_InputByte(Base+5); sprintf(ch,"DO=0xAA, DI1=%x DI2=%x",in1,in2); dc.TextOut(0,(y++)*16,ch); DIO_OutputByte(Base+5,0x00); in1=DIO_InputByte(Base+4); in2=DIO_InputByte(Base+5); sprintf(ch,"DO=0x00, DI1=%x DI2=%x",in1,in2); dc.TextOut(0,(y++)*16,ch) ; DIO_OutputByte(Base+5,0xff); in1=DIO_InputByte(Base+4); in2=DIO_InputByte(Base+5); sprintf(ch,"DO=0xFF, DI1=%x DI2=%x",in1,in2); dc.TextOut(0,(y++)*16,ch); /* refer to "TMC-10 user manual" Sec. 3.7 Watchdog timer(P28)*/ /* refer to "TMC-10 user manual" Sec. 3.7 Watchdog timer(P28)*/ /* refer to "TMC-10 user manual" Sec. 3.7 Watchdog timer(P28)*/ /* refer to "TMC-10 user manual" Sec. 3.7 Watchdog timer(P28)*/ /* refer to "TMC-10 user manual" Sec. 3.7 Watchdog timer(P28)*/ /* refer to "TMC-10 user manual" Sec. 3.7 Watchdog timer(P28)*/ DIO_ResetIntCount(); DIO_InstallIrq(Base,5); in1=DIO_GetIntCount(); sprintf(ch,"Init IntCount=0",in1); dc.TextOut(0,(y++)*16,ch); init_watchdog(); for (i=0; i<1000; i++) { Delay(1); reload_watchdog(); /* simulate normal operation */ } in1=DIO_GetIntCount(); sprintf(ch,"EndOfReload IntCount=%d",in1); dc.TextOut(0,(y++)*16,ch); for (i=0; i<3; i++) { Delay(1000); in1=DIO_GetIntCount(); sprintf(ch,"[%d] : Delay IntCount=%d",i,in1); dc.TextOut(0,(y++)*16,ch); } /* refer to "TMC-10 user manual" for more examples */ /* change inportb --> DIO_InputByte */ /* change outportb --> DIO_OutputByte */ } /* -------------------------------------------------------------------- */ void init_watchdog() { DIO_OutputByte(Base+4,2); /* select 8254 chip_3 --> counter 7,8,9 */ DIO_OutputByte(Base+3,0xb0); /* mode_0,counter 9 */ DIO_OutputByte(Base+2,0xff); /* low byte first */ DIO_OutputByte(Base+2,0xff); /* high byte */ } /* -------------------------------------------------------------------- */ void reload_watchdog() { DIO_OutputByte(Base+3,0xb0); /* mode_0,counter 9 */ DIO_OutputByte(Base+2,0xff); /* low byte first */ DIO_OutputByte(Base+2,0xff); /* high byte */ } void Delay(unsigned t) { unsigned i,j,k; for (i=0; iIsKindOf(RUNTIME_CLASS(CTmc10Doc))); return (CTmc10Doc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CTmc10View message handlers