Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

problem placing 3 bytes in a variable and divide it

Status
Not open for further replies.

redsuns

New Member
hello, i now have 3 bytes that need to place as first byte,second byte and third byte in a variable then converted into a decimal number ,
but the result is 0, can anyone help
supposely the b1,b2 and b3 for me is variable

CODE:
#include <stdlib.h>
unsigned char fb,sb;
unsigned int count,size;
unsigned long packages,temp,b1,b2,b3;
float temppack;
char pac_show [sizeof(unsigned long)*8+1];

void main(void)
{
b1 = 0xF5;
b2 = 0xCE;
b3 = 0x12;
temp=b1;
temp<<8;
temp+=b2;
temp<<8;
temp+=b3;
temppack=temp/506;
packages = (unsigned long) temppack;
ultoa(packages,pac_show,10);
LCD_sendstring(pac_show);
}
 
Try changing it to,
Code:
void main(void)
{
    b1 = 0xF5;
    b2 = 0xCE;
    b3 = 0x12;
    temp=b1;
    temp<<[COLOR="red"]=[/COLOR]8;
    temp+=b2;
    temp<<[COLOR="red"]=[/COLOR]8;
    temp+=b3;
    temppack=temp/506;
    packages = (unsigned long) temppack;
    ultoa(packages,pac_show,10);
    LCD_sendstring(pac_show);
}

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top