Discussion in "8051 Discussion Forum" started by    romel_emperado    Nov 3, 2010.
Mon Jan 10 2011, 11:11 PM
nice one guys! Haha

python is weird language but good...
Tue Jan 11 2011, 05:55 PM
do let me know when you make some progress
Tue Jan 11 2011, 11:59 PM
sure ajay. But its very difficult to make a progress hehe.
i have a based code but it is in tcl language my big problem is converting it to python. Wtf! Hehe

i cant get a help here since you don know tcl and python.
Wed Jan 12 2011, 12:01 AM
later i will attach the complete source code i will let you see what is tcl language..
Wed Jan 12 2011, 10:05 AM
guys what do you mean by this

struct br
{
	// BLUEROBIN_OFF, BLUEROBIN_SEARCHING, BLUEROBIN_CONNECTED, BLUEROBIN_ERROR
	BlueRobin_state_t 	state;
	
	// BLUEROBIN_NO_UPDATE, BLUEROBIN_NEW_DATA
	BlueRobin_update_t	update;
	
	// Chest strap ID	
	u32	cs_id;

	// User settings
	u8 		user_sex;
	u16		user_weight;
	
	// Heart rate (1 bpm)
	u8 		heartrate;
	
	// Calories (1 kCal) - calculated from heart rate, user weight and user sex
	u32 	calories;
	
	// Speed (0.1 km/h) - demo version range is 0.0 to 25.5km/h 
	u8 		speed;
	
	// Distance (1 m)
	u32 	distance;
	
	// 0=display calories, 1=display distance
	u8		caldist_view;
};
extern struct br sBlueRobin;


what do you mean by this extern struct br sBlueRobin;

and i found a function looks like this

if (sBlueRobin.caldist_view == 0) 	sBlueRobin.caldist_view = 1;
	else								sBlueRobin.caldist_view = 0;



it seems that it calls the variable sBlueRobin.caldist_view

but why using "." or dot

when i will use struct br ??? what is br? is it variable?

when i declar a variable like this
s32 weight;


what do the s32 mean?? hehe i need explaination.. Im using that in my code without understanding i just seen that in some examples in the web.. hehe


[ Edited Wed Jan 12 2011, 12:26 PM ]
Wed Jan 12 2011, 12:08 PM
actually Im using that code above. I modified it and its working fine... i just used that without understanding and now i need someone to explain that to me.... hehehe eheheh thanks in advance..... heheh

Wed Jan 12 2011, 02:48 PM
thats how structures in C/C++ are used. it looks like you never used structure.
here is a quick reference

Defining structure
//defining structure
struct mystruct {
    int a;
    char b;
    char c[10];
    int d[10];
};

Now mystruct is name of structure. a,b,c and d are members of structure. its like grouping set of variables in a single datatype and giving your own name to it.

to use a structure, you first need to create an instance of the structure. and members of structure can only be accessed through that instance.

//defining instance of struct
struct mystruct x,y,*z;

so x and y are two instances of structure. and z is a pointer to mystruct.

using structure is very simple, lets say you want to equate members of structure x with y then you will do like this.
x.a = y.a;
x.b = y.b;

memcpy(x.c, y.c, 10); //copy character array


Pointers work a little different way we use dot (.) incase of structure variables to access the members but incase of pointers we use arrows (->) e.g.
z = &x; //z has address of x, or say z points to x now.
y.a = z->
a; //you see the difference now?
y.b = z->
b;
//its same with all.. just replace . with ->


Initializing structure:
structures are initialized just like we do in arrays. each member is separated by comma and complete thing is enclosed in curly brackets.
x = {10, 'c', "hello", {10,20,30,40,50,60,70,80,90,100}};

//partially defining structure
y = {30, 'y', "world"};
//now the integer array  will automatically be initialized to 0.


Working example:
lets take an example, I want to make database of user accounts in C. I can have total of 100 users. user info will have username, password, age etc. so if you just do it in traditional style what you will do is.. you will create three arrays to store information of each user.
//array style..
char username[100][20]; //100 usernames each of length 20 max
char password[100][15]; //100 passwords each of length 15 max
int age[100]; //array to store age of 100 users

now if you write code using the above style you will have to manage lot of arrays which might get your code look very complex. So now lets see structure style for the same..
struct users {
char username[20];
char password[15];
int age;
};

that defines a custom data type with name users. now lets create 100 users.

struct users user[100];
//we define array of 100 1 structure for each user.


lets make simple login checker now.. a function that checks if entered user details are correct or not.

int checkuser(struct users input){
    int i;
    int status = 0;
    //we have 100 users so loop will go from 0 to 99
    //checking each user..
    for(i=0; i<100; i++){
        if(strcmp(input.username, user[i].username) == 0){ //check if username is there in database or not
            if(strcmp(input.password, user[i].password) == 0){ //check if password matches
                status = 1; //set status to 1 so that we say input user is available in database
                break; //break out of loop, we are done with checking
            } else {
                status = -1; //username is there but password incorrect
                break; //break out of loop.
            }
        }
    }
    if(i == 100){
        //if i reaches 100 it means username not available in database
	status = -2;
    }
    return status; //return status to caller function
}


well i think small tutorial on structures is good enough hope you now learn how to use structures, how to pass structure as a varaible to function, defining a structure pointer and variable etc.
 romel_emperado like this.
Tags structures in cusing structure in embedded cembedded c and structuresdata structures in embedded cembedded c tutorial structures
Thu Jan 13 2011, 05:37 AM
thank you very much ajay.. your tut is very detailed and understandable... thanks for your effort yar!!! heheeh I love u... hehe
Thu Jan 13 2011, 01:43 PM
how about this ajay

#define DISPLAY_DEFAULT_VIEW			(0u)


i know how to use #define varName but what is this
(0u)
thing??
Fri Jan 14 2011, 03:17 PM
guys i need help again... How do i call the function mx_cal(); ?? what is that u8 line parameter? i dont have idea how do i call that from the function i made below which is burned_cal();



// system
#include "project.h"

// driver
#include "display.h"
#include "ports.h"

// logic
#include "romel.h"
#include "clock.h"
#include "date.h"
#include "user.h"

// Global Variable section
struct br mel;
s8 weight2, time;
s8 met2;
float kcal;


// Prototypes section



void display_romel(u8 line, u8 update)
{
	if (update == DISPLAY_LINE_UPDATE_FULL)	
	{
		display_chars(LCD_SEG_L2_5_0, (u8 *)" CAL0", SEG_ON);
	}
}



void mx_cal(u8 line)
{
	u8 select;
	s32 weight;
	s32 met;

	// Clear display
	clear_display_all();
	
	// Convert global variables to local variables
	//kcalories 	=      mel.calories/1000;
	met		    =      mel.met_value/1000;
	if (sys.flag.use_metric_units)	weight = mel.user_weight;
	else							weight = ((s32)mel.user_weight * 2205) / 1000; // Convert kg to lb

	// Init value index
	select = 0;
	
	
		// Loop values until all are set or user breaks	set
	while(1) 
	{
		// Idle timeout : exit without saving 
		if (sys.flag.idle_timeout) break;

		// Button STAR (short): save, then exit 
		if (button.flag.star) 
		{
			// Store local variables in global structure
			//mel.calories 	= kcalories*1000;
			//mel.user_sex 	= sex;
			mel.met_value		= met*1000;
			if (sys.flag.use_metric_units)	mel.user_weight = weight;
			else							mel.user_weight = (weight * 1000) / 2205;
			
			// Set display update flag
			display.flag.line1_full_update = 1;

			break;
		}

		switch (select)
		{

			case 0:	// Set user weight
			            clear_line(LINE2);
						if (sys.flag.use_metric_units)
						{
							display_chars(LCD_SEG_L2_1_0, (u8 *)"KG", SEG_ON);
							set_value(&weight, 3, 2, USER_WEIGHT_MIN_KG, USER_WEIGHT_MAX_KG, SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_4_2, display_value1);
							 
						}
						else
						{
							display_chars(LCD_SEG_L2_1_0, (u8 *)"LB", SEG_ON);
							set_value(&weight, 3, 2, USER_WEIGHT_MIN_LB, USER_WEIGHT_MAX_LB, SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_4_2, display_value1);
							weight2 = weight;
						}
						select = 1;
						break;
						
			case 1:   //Set MET
						display_chars(LCD_SEG_L2_1_0, (u8 *)"ME", SEG_ON);
						set_value(&met, 3, 2, USER_WEIGHT_MIN, USER_METS_MAX, SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_4_2, display_value1);
						met2 = met;
						select = 0;
						break;
					

		}
	}	

	// Clear button flags
	button.all_flags = 0;
}


//calorie expernditure forMULa

void burned_cal(void)
{
		if(sTime.second == 60)
		{
				time++;
		}
		
		kcal = ((met2 * 3.5 * (weight2/2.2)) / 200) * time;
}







[ Edited Sat Jan 15 2011, 08:09 AM ]

Get Social

Information

Powered by e107 Forum System

Conversation

Wed Jan 22 2020, 07:16 PM
MINU CHAUDHARY
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.
Tue Jan 14 2020, 08:08 AM
shubham kharade
when i am trying to simulate the program in Proteus 8 professional, I am getting some errors as cannot find module file dhtxx.md can u help me
Tue Dec 17 2019, 02:44 PM
Devangi
hello..i am programming industrial timer using 8051 with 24lc64 eeprom. i have query in storing the 3 diff value in eeprom with enter button. can anyone share c code ?
Tue Dec 17 2019, 11:30 AM
Andrius
Hello. Can anyone share the code in Bascon and scheme in Proteus?
Thu Nov 21 2019, 01:30 PM
raj2555
how to interface 8051 microcontroller with NRF24L01+ module
ExperimenterUK
Sat Oct 12 2019, 11:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 11:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 08:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 09:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 08:09 PM
@Ismail ..post in forum, give details

Downloads

Comments

Nippy56
Sun Jan 19 2020, 02:13 AM
usb5962
Sat Jan 11 2020, 10:42 AM
elt
Tue Jan 07 2020, 06:53 PM
mg3914697
Tue Jan 07 2020, 12:42 PM
afds43
Sun Dec 29 2019, 05:54 AM
Rupeshpatil
Fri Dec 27 2019, 06:14 PM
pyxus
Sat Dec 14 2019, 12:31 PM
Istika
Thu Dec 12 2019, 12:04 PM

Online

Guests: 20, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38116
Newest member: Nippy56
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jan 17 2020, 10:24 PM
We will need the circuit diagram.A Proteus simulat...
Billz Avatar
Posted By Billz
Sat Jan 11 2020, 05:43 PM
hi everyone please attached files are my c code fo...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jan 07 2020, 08:18 PM
Not a stupid question.Setting up "Eclipse" can be...
elt Avatar
Posted By elt
Tue Jan 07 2020, 07:06 PM
So i have just began learning programming micros a...
Billz Avatar
Posted By Billz
Mon Jan 06 2020, 09:22 PM
I think it would be better if you guys try to come...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jan 06 2020, 12:22 AM
Can you post a circuit diagram and any code you ha...
Billz Avatar
Posted By Billz
Sun Jan 05 2020, 08:17 PM
Need help regarding C code (specifically for PIC 1...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Dec 30 2019, 06:42 PM
Can you give more details of your problem.
Rupeshpatil Avatar
Posted By Rupeshpatil
Fri Dec 27 2019, 06:21 PM
How to copy program my old microcontroller to new ...
ilylily07 Avatar
Posted By ilylily07
Thu Dec 12 2019, 02:26 PM
wil do.thank you for your advice!