Status
Not open for further replies.

#### AtomSoft

##### Well-Known Member
hey i just edited the above code. Use the one with

Code:
//REV2
at the top

#### dawson

##### New Member
That last one now produces:

">Option A"
"Option B"

"Option B"
">Option C"

so it misses Option B

#### AtomSoft

##### Well-Known Member
i has to be your hardware then. I have that code working flawless in Proteus. Ill post a video... using mikroC pro and proteus to test it

#### dawson

##### New Member
I had a look and noticed there was no delay for switch presses I have now added in a delay for each press and it is working

Thanks for all the help.

#### AtomSoft

##### Well-Known Member
heh no problem you are right tho:

Code:
unsigned char WaitForInput(void){
unsigned char done = 0; //DONE Var will determine if done and hold key

while(!done){                                  //while done == 0
Delay_ms(10);
}
if (Button(&PORTA, UP, 1, 0)){
Delay_ms(10);
done = UP;
}
if (Button(&PORTA, DOWN, 1, 0)){
Delay_ms(10);
done = DOWN;
}
}
return done;                                  //Return our done/key var
}
Thats way better

#### dawson

##### New Member
Yea thats how it now works with the delays

#### dawson

##### New Member
just one more problem, when i combine it to my temp sensor code it waits for the button then wats ti read temp then there is delays in temp before it comes back round to wait for MENU to be pressed so you have to get the timing right when pressing it.

here is the code:
Code:
 do {
switch(WaitForInput()){
Delay_ms(100);
break;
}
} while (1);
is there a better way of waiting for a button press while it is doing the temprature reading?

#### AtomSoft

##### Well-Known Member
The best way is with interrupts. But thats not my strong point heh you can ask around for that.

I can barely do it in C18 i can imagin MikroC is simpler but i would have to learn it more

#### AtomSoft

##### Well-Known Member
also interrupts are on PORTRB line.. If you want to test another way is to check the MENU button with the temp code itself. Like through in:
Code:
               if (Button(&PORTA, MENU, 1, 0))
MainMenu();
every now and then to check for the press

#### AtomSoft

##### Well-Known Member
This is my new temperature code:

Code:
      for(tmp=0;tmp<5;tmp++){
ADCON0bits.GO = 1;          //Start the conversion
result <<= 8;               //Shift over Result 8 bits to the left
result |= ADRESL;           //OR in our LOW byte to finish off out INT
avg[tmp] = result;
DelayMS(40);
}
result = 0;
for(tmp=0;tmp<5;tmp++){
result += avg[tmp];
}
result /= 5;
if(result==oldresult) goto tSame;

DegC = (result*5)/10;
DegC--;

DegF = DegC * 9;
DegF/=5;
DegF+=32;
//clear LCD temp buffer
for(tmp=0;tmp<16;tmp++)
lcdtmp[tmp] = ' ';

if(MyView == 'F'){
lcdtmp[0] = DECtoASCII(DegF,'h');
lcdtmp[1] = DECtoASCII(DegF,'l');
lcdtmp[2] = 0xDF;
lcdtmp[3] = 'F';
lcdtmp[4] = ' ';
} else {
lcdtmp[0] = DECtoASCII(DegC,'h');
lcdtmp[1] = DECtoASCII(DegC,'l');
lcdtmp[2] = 0xDF;
lcdtmp[3] = 'C';
lcdtmp[4] = ' ';
}
LCD_LINE(2);
LCD_STR((unsigned rom char*)"Temp: ");

LCD_STR2(lcdtmp);
DelayMS(DelayTime);

oldresult = result;
As you can see i test the button every now and then .. this way i have a better chance without interrupts

Last edited:

#### dawson

##### New Member
ok, not sure if i understand all that lol, will have a look through what I have and try and figure out the rest.

Thanks again for all the help

#### AtomSoft

##### Well-Known Member
heh no problem if you need help just ask ok

#### dawson

##### New Member
Sure will, thanks you have taught me a lot rther than just saying do this... cause i said so.

Thanks

#### AtomSoft

##### Well-Known Member
thanks for saying thanks! heh i like helpin

Status
Not open for further replies.