NXC C programs, Other Subject

A description of each function used in the program.

Theree programs:

/* HiTechnic Experimenter''s Kit Program

Experiment - 6 Reaction Time Measurement

This program measures the time taken to press a button switch after an LED is turned on.

(c) HiTechnic 2009

*/
#include "NXCDefs.h"

#define PROTO_PORT IN_1

int currtime;
int deltatime;
int randomtime;
int inputdata;
int outputdata;
int count;
byte cmndbuf[]; // buffer for outbound I2C command
byte respbuf[]; // buffer for inbound I2C response

/* protoboard I/O map
42,43 - A0 input
44,45 - A1 input
46,47 - A2 input
48,49 - A3 input
4A,4B - A4 input
4C - B inputs
4D - B outputs
4E - B controls
*/

void readdata()
{
ArrayInit(cmndbuf, 0, 2); // set the buffer to hold 2 values
cmndbuf[0] = 0x02; // set write to channel
cmndbuf[1] = 0x4C; // to set read address
count=1; // 1 byte to read
I2CBytes(PROTO_PORT, cmndbuf, count, respbuf); // issue I2C write command and read the byte back
inputdata=respbuf[0]&0x03;
}

void writedata()
{
ArrayInit(cmndbuf, 0, 3); // set the buffer to hold 3 values
cmndbuf[0] = 0x02; // set write to channel
cmndbuf[1] = 0x4D; // to set write address
cmndbuf[2] = outputdata; // to set write data
count=0; // no bytes to read
I2CBytes(PROTO_PORT, cmndbuf, count, respbuf); // issue I2C write command and read the byte back
}

task main()
{
SetSensorLowspeed(PROTO_PORT); // set sensor port 1 to low speed serial (I2C)
Wait(100);

ArrayInit(cmndbuf, 0, 3); // set the buffer to hold 3 values
cmndbuf[0] = 0x02; // set write to channel
cmndbuf[1] = 0x4E; // to set write address
cmndbuf[2] = 0x30; // to write 001111
count=0; // no bytes to read
I2CBytes(PROTO_PORT, cmndbuf, count, respbuf); // issue I2C write command
Wait(100);

while (TRUE)
{
outputdata=0;
writedata();
ClearScreen();
TextOut(20, LCD_LINE2, "running");
randomtime=Random(5000)+5000;
Wait(randomtime);

outputdata=0x10;
writedata();
currtime=CurrentTick();

inputdata=0x00;
while(inputdata!=0x01)
{
readdata();
}
deltatime=CurrentTick()-currtime;
ClearScreen();
NumOut(20, LCD_LINE2, deltatime);

inputdata=0x00;
while(inputdata!=0x03)
{
readdata();
}
}
}
Posted Date: 4/25/2012 8:36:24 PM | Location : United States







Related Discussions:- NXC C programs, Assignment Help, Ask Question on NXC C programs, Get Answer, Expert's Help, NXC C programs Discussions

Write discussion on NXC C programs
Your posts are moderated
Related Questions


In developing our awareness of Indigenous Australians, including their historical perspectives, culture and lifestyles, it is important that we recognise and understand the develop

1. What is a feedback mechanism in the context of climate? 2. Provide and explain one example of a positive feedback that begins with air temperature. 3. Provide and explain

History of Documentaries: The earliest documentaries in the US and France were either short newsreels, instructional pictures, records of current events, or travelogues (termed ac

Car Following Behavior of Driver - Traffic Congestion and Safety on the Road   Understanding car following contributes significantly to an understanding of traffic flow. Car

why are colonies useful to have if a nation is thinking about going to war?

Question: a) In the context of e-banking or e-commerce, outline some of the risks associated with informational websites and transactional websites. b) In addition to tr

Using C# on PC, read a binary file, send it to the STM32 microcontroller via PC''s USB and STM32''s USB. The STM32 then saved this binary file into an I2C EEPROM. Of course it need

The division of political power between the states and the national government has been a continuing source of conflict throughout American history. Write an essay on this controve