NXC C programs, Other Subject

Assignment Help:
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();
}
}
}

Related Discussions:- NXC C programs

Nursing, what are the written material information in nursing

what are the written material information in nursing

Organizational behaviour, 2. If you were one of the other foremen, what cou...

2. If you were one of the other foremen, what could you do to make Rajinder’s transition easier?

What are the main health hazards associated with lasers, Question: a) ...

Question: a) Name the two main types of vibration that could affect workers' health. What is the maximum Exposure Limit Value for hand-arm vibration that an employee may be

Theory of career development, Question: a) Describe in detail, one theo...

Question: a) Describe in detail, one theory of career development and one theory on decision making. b) Describe how these theories, you outlined, contribute to effective

Alternatives to digital currency, ALTERNATIVES Officially digital money...

ALTERNATIVES Officially digital money or electronic is a representation, or a system of credits and debits, used (but not restricted to this) to swap value, within a different

Composition 2, 1. explain why it is important to put observations in writin...

1. explain why it is important to put observations in writing. How can observation enrich our writing? 2. At what point could making an observation halt or obstruct the writing pr

Evaluation of religious beliefs in the film "Life of pi", Write a essay on ...

Write a essay on what you deem to be the judgement of "the search for god and life''s meaning" in the movie, Life of pi

Overtaken rules - traffic congestion, Overtaken Rules - Traffic Congestion ...

Overtaken Rules - Traffic Congestion There are several precaution steps should be taken into consideration to inhibit accidents when one vehicle overtaking and passing the oth

Explain the immediate and future effect of healthy habits, Discuss the fami...

Discuss the family, social, and intimate relationships of the person in the case study below. Identify any role changes that have occurred. Explain the immediate and future

FINANCE FOR PROFESSIONALS, Making use of any accounting techniques or frame...

Making use of any accounting techniques or frameworks relating to financial and/or management accounting, that could be used, critically evaluate how you or your manager are served

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd