I am begineer with this microcontroller (C167) or system embeded and i had have some problems with my program when i run this directy on the hardware. The problem is that i can't use float numbers in my microcontroller but i don't known if is because the microcontroller or software don't support this or I have driving bad the memory models of micro. In the program happen the next. unsigned char CODEC (unsigned char num) { //code of decimal to ACSII switch (num){ //here pass of digid number to ASCII code } retuned(num); } void main (void){ // setting the Variables unsigned char datos=0; unsigned int b=0, resultado=0; unsigned int a=0; float valor=0; .... . . . . part of program no interesting . . ////END LCD CARACTERES. while(1){ wait(900); P7 = 0x01; // Registro Display clear. //clean display lcd(Limpia la pantalla). Activar(0); // 0 if is register and //1 if is Date. resultado = ADC_read (0); /* Get the converted value */ valor = resultado*VREF*.0009775; //(1/1023)=.0009775 step cuantifiqued. a = floor(valor) P7 = CODEC(a); //printf("valor entero= %d,valor real = %f V\r", P7, valor); Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. ...... . . . . . . }//end while and end the program. In debugged this code runs good in the two modes with monitor and simulate. But in the microcontroller don't run good appear E that in may table of convert is Error and this only happen if the number is > 9. But if puts in this same code the next runs good in the microcontroller. //valor = resultado*VREF*.0009775; //(1/1023)=.0009775 step cuantifiqued. valor=3.4261;//for example a = floor(valor) P7 = CODEC(a); //printf("valor entero= %d,valor real = %f V\r", P7, valor); Activar(1); // this funtion puts on display the number. Please somebody help me, and sorry for my inglish if something is no clear please send me a e-mail to oliver_g_t@hotmail.com
I put all code i hope that it is more clear #include <reg167.h> #include <STDIO.H> #include <INTRINS.H> #define VREF 5 /* ADC Voltage Reference */ sbit P2_0 = P2^0; //Declarate the pin to use. sbit DP2_0 = DP2^0; //Directive in/out pin configuration. sbit ODP2_0 = ODP2^0; //Directive open drain. sbit P2_1 = P2^1; sbit DP2_1 = DP2^1; sbit ODP2_1 = ODP2^1; sbit P2_2 = P2^2; sbit DP2_2 = DP2^2; sbit ODP2_2 = ODP2^2; sbit P2_3 = P2^3; sbit DP2_3 = DP2^3; unsigned int ADC_read (unsigned char channel) { get a signal }< unsigned char CODEC (unsigned char num) { //This table convert to decimal to ASCII switch (num){ case 0: num = 0x30; //0011 0000 break; case 1: num = 0x31; //0011 0001 ..... . . . . . . . . case 9: num = 0x39; //0011 1001 break; default:num = 0x45; //0100 0101 break; } //TERMINA SWITCH return (num); // Value de return }//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------- //-------------------------- F U N T I O N W A I T -------------------- void wait (unsigned long r) { }// END FUNTION OF WAIT. //RUTINE OF ACTIVATION OF INTRUCTIONS. void Activar (bit s){ wait(1); //P2_0: Sinal de register: 0 in is a instruction, 1 is a date. if (s == 0) { P2_0 = 0; } else { P2_0 = 1; } P2_1=0; //Sinal of lec/write: 0 write a date and 1 read a date to the LCD. P2_2=1; wait(1); P2_2=0; wait(1); }////// E N D F U N T I O N //////// //_______________________________________________________________________________ void main (void){ unsigned char cnv_ascii; unsigned int resultado=0, cnv_ent=0; unsigned long b=0; float valor; // CONFIGURATION OF PINS. P7 = 0x00; // Declarate the pins to use (10 bits in off) DP7 = 0xFF;// Declarate the direction I/O of bit (in out) ODP7= 0x00; // 0 push-pull mode -- 1 open drain mode. /* the direction the pin is declarate as in with a 0 and out with a 1 */ DP2_0 = 1; // out DP2_1 = 1; // out DP2_2 = 1; // out DP2_3 = 0; // in /* 0 push-pull mode -- 1 open drain mode.*/ ODP2_0 = 0; ODP2_1 = 0; ODP2_2 = 0; //CONFIGURATION INITIAL OF LCD DRIVE hitachi HD44780. //SUGGESS. WACH OF DATASHEETS. //Pins to ground. P7 = 0x00; //Lines of control. P2_0=0; //Sinal of register: 0 in of a instruction, 1 of a date. P2_1=0; //Sinal of read/write: 0 write a date and 1 reads a date of LCD. P2_2=0; //Activation of modul LCD. /*El number of this rutine of wait is in miliseg*/ wait(20); /*------------------------ STEP 1 ----------------*/ //Indicate a configuration of bus to use if is 8 or 4 bits. //P7 = DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0. P7 = 0x3C; // DB5 indicate of register of funtion set // DB4 indicate if we want 8 bits o 4 in the bus of dates. // DB3 Indicate with how many lines we want to work. Activar(0); // 0 IF IS REGISTER AND 1 IF IS DATE. P7 = 0x1C; // Register Display / cursor shift. // DB3 shift display o move cursor. // DB2 Move cursor to left or righ. Activar(0); P7 = 0x0F; // Register Display ON / OFF. // DB2 to active display. // DB1 active cursor // DB0 active blink cursor. Activar(0); P7 = 0x06; // Register mode set // DB1 determine acvance of cursor before put a caracter. // DB0 chance of display or freeze this. Activar(0); // 0 IF IS REGISTER AND 1 IF IS DATE. P7 = 0x01; // Register Display clear. (Clean to display). Activar(0); // 0 IF IS REGISTER AND 1 IF IS DATE. /****************** CONFIGURATION END *******************************/ //-------------------------------------------------------------------------/ //IN OF DATES P7 = 0x4F; //0100 1111 'O' Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. P7 = 0x6C; //0110 1100 'l' Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. P7 = 0x69; //0110 1001 'i' Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. P7 = 0x76; //0111 0110 'v' Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. P7 = 0x65; //0111 0101 'e' Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. P7 = 0x72; //0111 0010 'r' Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. P7 = 0x8F; //1000 1111 ' ' Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. ////LCD CARACTERS. while(P2_3==0){}//Waits until push a button. while(1){ wait(900); P7 = 0x01; // Register Display clear. (Limpia la pantalla). Activar(0); // 0 SI ES REGISTRO Y 1 SI ES DATO. resultado = ADC_read (0); /* Get the converted value */ valor = resultado*VREF*.0009775; //(1/1023)=.0009775 //valor=4.275;If i puts this the display works correctly //EJEMPLO 4.275 cnv_ent = valor; //Get 4. cnv_ascii = cnv_ent; cnv_ascii = cnv_ascii + 0x30; P7 = cnv_ascii; Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. P7 = 0x2E; //0010 1110 'punto' Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. valor = valor - cnv_ent; // 4.275 - 4 = .275 valor = valor * 10; // 2.75 cnv_ent = valor; // 2 cnv_ascii = cnv_ent; cnv_ascii = cnv_ascii + 0x30; P7 = cnv_ascii; Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. valor = valor - cnv_ent; //Of value below 2.75 -2=.75 valor = valor * 10; //7.5 cnv_ent = valor; //7 cnv_ascii = cnv_ent; cnv_ascii = cnv_ascii + 0x30; P7 = cnv_ascii; Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. valor = valor - cnv_ent; //7.5 - 7 = .5 cnv_ent = valor * 10; //5 cnv_ascii = cnv_ent; cnv_ascii = cnv_ascii + 0x30; P7 = cnv_ascii; Activar(1); // 0 SI ES REGISTRO Y 1 SI ES DATO. }//while cicle infinit }//MAIN ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////OK this is all my code and my problem is LCD don't display The result get to ADC. if i use varibles point float. just if i puts directly over the variable float value way? I don't known bucause i need help.thank for you anwers best regards Oliver Campos.