Thanks for all the input guys. Unfortunately, we've not had any luck on this end in getting the altered connections to work. At this point, we've decided to admit defeat and just cut the tracks on the PCB and fix it by soldering in some extra wires.
Sorry to be a pain, but do you think any of you might be able to help with another issue we're having?
Basically, we want to define an integer called "noofsteps" that is incremented when a tiltswitch connection is made.
We can probably work out how to get that to work:
I'm guessing something along the lines of:
Code:
IF (TILT_SWITCH_INPUT==1)
{
noofsteps++;
}
However, we're having nightmare trying to do the simple task of printing the value of this integer to the screen.
We've tried
Code:
int noofsteps = 35;
char TopMessage[]
char BotMessage[] = " Hear me roar "
sprintf(TopMessage, "%d", noofsteps);
But depending on the combination of "'s, ;s and )s we just get %d displayed on the screen, or the compiler fails to build as we're changing variable type from integer to character.
If I explain the general functionality of the program, it might help:
The program is to be a Pedometer that counts the number of steps that the user makes. It will display this, the distance travelled, the calories burned, and also the temperature of the user (read in through a thermistor through an ADC) in a series of display screens that the user can cycle through by pressing a button.
This is how we thought about doing the program:
Code:
int noofsteps = 0 // This variable, "noofsteps" is a running count of the number of steps that the user has taken. It is to be incremented every time a tiltswitch makes a connection.
int stridelength = 70 // This variable, "stridelength" is the stride length of the user. At the start of the program, the user can press the forward button or the backward button to increment or decrement "stridelength" by 5 cm.
int distancetravelled = 0 // This variable will be used to calculate the distance that the user has travelled by multiplying "noofsteps" by "stridelength".
int caloriesburned = 0 // This variable stores the running total calores burned by mutiplying "distancetravelled" by various factors (can't remember off the top of my head but say for the sake of argument 2000).
int bodytemp = 0 // This variable will be written to using the ADC and will output the user's body temperature as they exercise.
int screenmode = 0 // This variable controls which message is read from both of the arrays and displayed on the LCD screen.
ARRAY_1[] // This array will contain all of the messages that will be displayed on the top line of the LCD, one for each display screen.
"You have walked"
"You have travelled"
"You have burned"
"You are at"
ARRAY_2[] // This array will contain all of the messages that will be displayed on the bottom line of the LCD, one for each display screen.
"noofsteps"
"distancetravelled"
"caloriesburned"
"bodytemp"
I don't know how to make it clear here that the screen should write the VALUE of the integer 'noofsteps', not just write the word "noofsteps". Is there some sort of identifier that goes in front of noofsteps to tell the program that it's a variable, and not just the word?
I then have the functions that I had originally:
Code:
LCDWrite(int LCDData, int RSValue)
{
PORTC = (LCDData >> 4) & 0x0F; // Get High 4 Bits for Output
RS = RSValue;
E = 1; E = 0; // Toggle the High 4 Bits Out
PORTC = LCDData & 0x0F; // Get Low 4 Bits for Output
RS = RSValue;
E = 1; E = 0; // Toggle the Low 4 Bits Out
if ((0 == (LCDData & 0xFC)) && (0 == RSValue))
n = Fivems; // Set Delay Interval
else
n = TwoHundredus;
for (k = 0; k < n; k++); // Delay for Character
} // End LCDWrite
main()
{
PORTC = 0; // Start with Everything Low
CMCON0 = 7; // Turn off Comparators
ANSEL = 0; // Turn off ADC
TRISC = 0; // All of PORTC are Outputs
// Initialize LCD
j = Twentyms;
for (i = 0; i < j; i++); // Wait for LCD to Power Up
PORTC = 3; // Start Initialization Process
E = 1; E = 0; // Send Reset Command
j = Fivems;
for (i = 0; i < j; i++);
E = 1; E = 0; // Repeat Reset Command
j = TwoHundredus;
for (i = 0; i < j; i++);
E = 1; E = 0; // Repeat Reset Command Third Time
j = TwoHundredus;
for (i = 0; i < j; i++);
PORTC = 2; // Initialize LCD 4 Bit Mode
E = 1; E = 0;
j = TwoHundredus;
for (i = 0; i < j; i++);
LCDWrite(0b00101000, 0); // LCD is 4 Bit I/F, 2 Line
LCDWrite(0b00000001, 0); // Clear LCD
LCDWrite(0b00000110, 0); // Move Cursor After Each Character
LCDWrite(0b00001110, 0); // Turn On LCD and Enable Cursor
for (i = 0; TopMessage[i] != 0; i++)
LCDWrite(TopMessage[i], 1);
LCDWrite(0b11000000, 0); // Move Cursor to the Second Line
for (i = 0; BotMessage[i] != 0; i++)
LCDWrite(BotMessage[i], 1);
while(1 == 1); // Finished
} // End cLCD
Basically, I want to pull a message out of one array, pull a stored number out of the other array and put them on the screen. I anticipated that we'd be able to do this using the integer "screenmode" which gets incremented when the user presses the forward button. I thought about trying:
Code:
for (i = 0; TopMessage[screenmode] != 0; screenmode++)
LCDWrite(TopMessage[screenmode], 1);
LCDWrite(0b11000000, 0); // Move Cursor to the Second Line
for (i = 0; BotMessage[screenmode] != 0; screenmode)
LCDWrite(BotMessage[screenmode], 1)
but I'm pretty sure that's wrong. From my LIMITED understanding of the code, I think the above code takes the first character of the message " Hello world", converts the 'H' into a binary number, then sends that to the LCD. I'm suspicious that changing the 'i's to 'screenmode's in the above snippet will cripple it.
Arg!
Sorry if this sounds like gibberish, it's been a LONG and frustrating day. I don't have a point of help for this project at the university or any lectures on C programming, so the coursework basically involves teaching myself C. It's not as if it's even a programming related course (it's practically art and design!) so I'm having a hard time getting my noggin around it.
If any other information would help you guys (a flow diagram, circuit, datasheets, etc.) please let me know and I'll try and get them up.
Thanks for any help any of you may be able to give. Sorry if any of these questions are stupid, I have less than basic knowledge of C.
JT