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

Business process orientation (bpo), BUSINESS PROCESS ORIENTATION (BPO) ...

BUSINESS PROCESS ORIENTATION (BPO) The idea of BPO is used consistently with Server markets. The idea of business process orientation (BPO) is stand upon the work of Deming (Wa

Marketing, how a hotel applies marketing concept on business

how a hotel applies marketing concept on business

Brief history of sculpture, Do you guys provide Brief History of Sculpture ...

Do you guys provide Brief History of Sculpture assignment help? I need writing a report on Brief History of Sculpture and it is about 2000 words. Let me know. I need to buy your so

Psychology, what would be a negative correlation between tall and short peo...

what would be a negative correlation between tall and short people and driving speed

Explain the grief cycle using examples, Grief is a cycle with different sta...

Grief is a cycle with different stages. It is common for people to move back and forth erratically through these stages or even go through the complete cycle several times. It is

Benchmark - information governance, Need help with a 1500 word executive su...

Need help with a 1500 word executive summary that contains the following information: Overview of information governance framework

HIV/AIDS, some myths and misconceptions that still prevail amongst many com...

some myths and misconceptions that still prevail amongst many community members concerning the transmission of HIV

How does social control establish unity, Question 01 Discuss the theories ...

Question 01 Discuss the theories of socialization Question 02 How does social control establish unity? Question 03 Based on which levels does man adapt himself to

Key features of ems, Key features of EMS: Serves as a tool to develop envi...

Key features of EMS: Serves as a tool to develop environmental performance. Provides a systematic method for managing an organization's environmental behavior. Is that aspect of t

Business communication, i have to submit 1000 words assignment of business ...

i have to submit 1000 words assignment of business communication process about two incidents. one has to be a good incident and a successful one and other one a bad incident becau

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