I´m working on a calculator but my atoi function isn´t working, its just converting the first digit as I enter it to my array. Any ideas ?
#include <hidef.h> // for EnableInterrupts macro
#include "derivative.h" // include peripheral declarations
#include "lcd.h" // lcd utility functions
#include <stdlib.h>
//#include <extras_stdlib.h>
char texto[5];
char keypressed,noper;
char nBuffer[6];
int a,b,tst,result=0;
char keyPadMatrix[13] =
{
'1','2','3',
'4','5','6',
'7','8','9',
'*','0','#',
0x00
};
void main(void) {
char i;
LCDinit();
//MCU_init(); /* call Device Initialization */
/* ### Init_GPIO init code */
/* PTFDD: PTFDD3=1,PTFDD2=1,PTFDD1=1,PTFDD0=1 */
PTADD |= (unsigned char)0x0F;
/* ### Init_GPIO init code */
/* PTBPE: PTBPE7=1,PTBPE6=1,PTBPE5=1,PTBPE4=1 */
PTCPE |= (unsigned char)0xF0;
/* PTBDD: PTBDD7=0,PTBDD6=0,PTBDD5=0,PTBDD4=0 */
PTCDD &= (unsigned char)~0x00;
/* ### */
/* include your code here */
// inicializo mi buffer
nBuffer[0] = ' ';
nBuffer[1] = ' ';
nBuffer[2] = ' ';
nBuffer[3] = ' ';
nBuffer[4] = ' ';
nBuffer[5] = 0; /*AQUI*/
for(;
{ //ciclo infinito
//* este IF solo ocurre cuando se presiona *, basicamente es un clr
borra el array, las variables y el display */
if (keypressed == '*'){ //borrar
LCDClearScreen();
nBuffer[0] = ' ';
nBuffer[1] = ' ';
nBuffer[2] = ' ';
nBuffer[3] = ' ';
nBuffer[4] = ' ';
a = 0;
b = 0;
result = 0;
}
keypressed = ScanKeyMatrix();
if (keypressed != 0x00){
for (i = 0; i < 4; i++){
nBuffer[i] = nBuffer[i+1];
}
nBuffer[4] = keypressed;
//a = atoi(nBuffer); //capturo el valor del buffer = al valor en pantalla
LCDClearScreen();
LCDputchar(nBuffer[0]);
LCDputchar(nBuffer[1]);
LCDputchar(nBuffer[2]);
LCDputchar(nBuffer[3]);
LCDputchar(nBuffer[4]);
}
//aqui debo revisar si alguna operacion matematica ha sido escogida
/*Si se presiona push button este realiza una operación según el Case NOPER*/
if (!(PTAD_PTAD4)){
a = atoi(nBuffer); //capturo el valor del buffer = al valor en pantalla
LCDClearScreen(); //limpio pantalla
tst = 1;
noper = 1; //suma
nBuffer[0] = ' '; //
nBuffer[1] = ' '; //* el buffer almacena los teclasos de forma FIFO son 5 posiciones porque 16 bits = $FF = 65535 = 5 numeros */
nBuffer[2] = ' ';
nBuffer[3] = ' ';
nBuffer[4] = ' ';
while ( !(PTAD_PTAD4) ){
}
}