Home › Forums › Microcontrollers › PIC Microcontroller › PIC 18F458 interfacing with load cell and glcd
- This topic has 1 reply, 2 voices, and was last updated 8 years ago by Ligo George.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
March 16, 2015 at 2:44 am #11039YuvrajParticipant
I tried to interface load cell with instrument amp with PIC18F458 and display the result on glcd , i wrote code on mikro c but it is showing errors and i’m unable sort out those errors…please help..will this program work on for proteus simulation ?
Int Digital_Value; Double t; Char table[17]={0,1,2,3,0,4,5,6,0,7,8,9,0,10,0,11,0}; Char txt[4] ; Char volt1[13]; Unsigned float tint,tint1,tint2,tint3,tint4,tint5,tint6,tint7,tint8,tint9; Unsigned float tint10; Unsigned float slope,weight,tavgfloat; // t must be defined as float or int Unsigned char var1, var2, Kp, Kp1,i; Unsigned int tavg,tavg1; Char attempts=0; Void main() { GLCD_Init (&PORTC,0,1,2,3,4,5,&PORTD); Glcd_Set_Font(FontSystem5x8, 5, 8, 32); Glcd_Fill(0); // Clear screen Usart_Init(2400); INTCON = 0; Keypad_init(&PORTB) ; GLCD_Write_Text("RCOEM",1,1,1); GLCD_Write_Text("WEIGHT:",1,11,1); OPTION_REG = 0x80; ADCON1 = 1; // configure AN3 Vref+, and Vref - as Vss TRISA = 0b110110; // 0 means input while (1) { while(!keypad_Read()) { delay_ms(10); for(i=0;i<10;i++) { Digital_Value = ADC_read(0); // get ADC value 8 bit =255 t=2.823*Digital_Value/1023.0; t=(t-0.658)/1.362; // becomes x (weight) tint=t*1000; tint10=tint9; tint9=tint8; tint8=tint7; tint7=tint6; tint6=tint5; tint5=tint4; tint4=tint3; tint3=tint2; tint2=tint1; tint1=tint; delay_us(200); //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ if (Usart_Data_Ready()) // If data is received { b = Usart_Read(); // Read the received data Usart_Write(b); // Send data via USART } //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ } tavg=(tint+tint1+tint2+tint3+tint4+tint5+tint6+tint7+tint8+tint9)/10; tavg1=tavg%10; tavg=tavg-tavg1; if (tavg1>=0 && tavg1<=5) tavg1=2; if (tavg1>=6 && tavg1<=9) tavg1=7; tavg=tavg+tavg1; tavgfloat=tavg/1000.0; //#################################################### Weight = tavgfloat; // y = ax + b // ##### eleminate exponential term ################# if(weight<1.0) { weight=weight*1000; if(weight<2.01) {weight=1.001;} floattostr(weight,volt1); volt1[8]='g'; volt1[9]='m'; volt1[10]=' '; } else { floattostr(weight,volt1); volt1[8]='k'; volt1[9]='g'; volt1[10]=' '; } GLCD_Write_Text(volt1,1,21,1); //y,x Delay_ms(500) ; //########################################## } while(!keypad_Read()); //wait for key 1 press Delay_ms(10); //debounce time kp=keypad_Released(); //wait for release var1=kp; //store var1 into kp var1 =table[kp] ; ByteToStr(var1,txt); GLCD_Write_Text(txt,20,30,1); Delay_ms(100); } }
March 16, 2015 at 4:11 pm #11045Ligo GeorgeKeymasterWhat are the errors ?
You should use small letters for int, char, float etc.
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.