0 on floating point math numbers even if strictly

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: – – – – (double) j 2.0 ((double) j)/k j/((double) k) (double) (j/k) (int) 6.824786 UCSD: Physics 121; 2008 • We will use the inpout32.dll package inpout32.dll 0.666667 0.666667 0.000000 (integer math already done) 6 • lesson is to take care when mixing variable types • also, get into habit of putting .0 on floating point math numbers, even if strictly unnecessary – – – – – parallel port access in linux/unix is very straightforward Windows 98 and before was also easy new Hardware Abstraction Layer (HAL) gets in the way this inpout32 package bridges the HAL see www.logix4u.net to get the package (already installed on WLH-2120 machines) – http://www.hytherion.com/beattidp/comput/pport.htm for test programs • Can also access via LPT file handle – discussed at end of lecture – runs 25 times slower than the inpout32 version • because you have to open/close the port all the time Winter 2008 17 Winter 2008 18 UCSD: Physics 121; 2008 UCSD: Physics 121; 2008 Sample code (stripped down to fit on slide) Looping to make a waveform #include <stdio.h> #include <conio.h> #include <windows.h> #define PPORT_BASE 0x378 typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum); oupfuncPtr oup32fp; short outval = 0; for (;;) // way to make infinite loop: ^C kills { outval += 1; outval %= 256; Out32(PPORT_BASE,outval); } void Out32(short portaddr, short datum){ (oup32fp)(portaddr,datum); } int main(void) { HINSTANCE hLib; short x=0xAA; • The code above makes a ramp of output values, then cuts down to zero and starts again – repeat until Ctrl-C kills it // value to write (expr. in hex) – the outval is increased by 1 hLib = LoadLibrary("inpout32.dll"); oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32"); Out32(PPORT_BASE,x); • Each time: • statement equivalent to o utval = outval + 1 – then mod by 256 (256 // the actual output command 0 , and start over) • statement is equivalent to outval = outval % 256 FreeLibrary(hLib); return 0; } Winter 2008 Lecture 12 19...
View Full Document

This note was uploaded on 01/30/2014 for the course PHYS 121 taught by Professor Staff during the Winter '08 term at UCSD.

Ask a homework question - tutors are online