Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

Sort By

USER REQUESTS

first | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 last
Rodrigo Silva
rodrigo_rodrigues789

posted on 2014/10/17 04:28:03 AM CEST

Other Codes

Problems using the ASIN function using variables

Hello,
I'm using the accelerometer MMA7361 to convert the slope in degrees.
I'm having problems doing the following equation by the compiler:

degrees = asin ((reading1 - 1.65) / 0.8; // this formula was removed from the Freescale website "Aplication Note AN3107 - Measuring Tilt with Low-g Accelerometers"

where:
degrees (Float)
Reading1 (int) used to convert A / D value in tension.

The value shows only "0" and not know why. I think there is a problem with my variable or the "asin" function.

........................................Program.......................................................................
while (1){

Leitura = Adc_Read(0); //Faz a leitura do canal AN0 (X)
Leitura = Leitura / 0.20459; //a variável Leitura. Faz em seguida a operação
IntToStr(Leitura, texto); //para apresentar o valor entre 0 a 5000mV
Glcd_Write_Text(texto, 40, 3, 1);

//Transformar em Graus
Leitura1 = Adc_Read(0); //Faz a leitura do canal AN0 (X)
Leitura1 = Leitura1 / 0.20459; //a variável Leitura. Faz em seguida a operação

graus = asin ((Leitura1 - 1.65) / 0.8;

IntToStr(graus, texto1);
Glcd_Write_Text(texto1, 40, 5, 1);
delay_ms(250);

if (graus > 40) {
RELE = 1;
LED = 1;
}
else {
RELE = 0;
LED = 0;
}

}
}


Thinh Nguyen
ThinhNguyen

posted on 2014/09/02 02:01:56 AM CEST

Other Codes

RTOS for MikroC Pro for ARM

I looking for A RTOS on mikorC pro for Arm which can work on STM32F107VC!

Tomer Sonnenschien
tomersonn11

posted on 2014/07/04 03:20:23 PM CEST

Other Codes

Magic switch board for pic18f45k22

Hi everyone,

I'm trying to do a verison of mine to the magic switch board and since i'm new in this business,i would appreciate your help.
As a first stage i want to write a program which has three phases.

First phase- learning mode: the user turns on the four first bits of "PORT B" on. Each bit he turns-on does the following things: 1) turns-on one of the four first bits of "PORT C" on. (it doesn't matter which bit he touches and when, the first four bits of "PORT C" will be turned on from right to left)
2) every bit of "PORTB" will get a number from 1-4 accordingly, and the numbers will be sent into array in the order the user turned them on(For example, if the user turned on the third bit of "PORT B" first, the first member in the array will be 3) . Each time a number gets into the array it will be locked to the bit at "PORT C" which it turns-on (for example- 3 turns on the third bit of "PORT C", 1 turns-on the zero bit of "PORT C"...)

Second phase- Play back mode: now that the system knows which bit at "PORT B" lights which bit at "PORT C" each time the user will touch a bit from "PORT B" it will turn on the specific bit from "PORT C" which he was assigned to.

Third phase- Zeroing the system: after about 10 seconds the system will retrieve its Initial Settings.

Here is an example to the magic switch board: http://www.youtube.com/watch?v=0lGP8nQLANU

this is the code which i'm working in: // Magic switch board for pic18k45f22
short number,state,tmp;
int i=0;
int connect[4]={17,17,17,17}; // Array that holds the lighting sequence of LATC
int flag_0=0, flag_1=0, flag_2=0, flag_3=0;
sbit red at LATC0_BIT;
sbit green at LATC1_BIT;
sbit yellow at LATC2_BIT;
sbit blue at LATC3_BIT;

void Light(short number ) // Function that lights up LATC
{

switch(number)
{
case 1:
red=1;
yellow=green=blue=0;
break;
case 2:
red=green=1;
yellow=blue=0;
break;
case 3:
red=green=yellow=1;
blue=0;
break;
case 4:
red=green=yellow=blue=1;
break;
}
} // End of void Light function

short CountBit(short num) // Function that converts binary number to decimal number
{
short b,c;
for (b=0; num != 0; num = num >> 1)

if (num &1)
b++;
return b;
}

void Light_2(short state)
{
for (i=0;i<=3;i++)
{
tmp=state &1;
if (tmp)
Light (connect[i]);
state=state>>1;
}
}

void main()
{
ANSELC=0;
ANSELB=0;

TRISC=0;
LATC=0;
number=LATB&0X0F;

while(1)
{
while (i<=3) // The teaching stage
{
if (flag_0==0)
{
if (LATB0_BIT==1)
{
connect[i]=1;
flag_0=1;
i++;
}
}
if (flag_1==0)
{
if (LATB1_BIT==1)
{
connect[i]=2;
flag_1=1;
i++;
}
}
if (flag_2==0)
{
if (LATB2_BIT==1)
{
connect[i]=3;
flag_2=1;
i++;
}
}
if (flag_3==0)
{
if (LATB3_BIT==1)
{
connect[i]=4;
flag_3=1;
i++;
}
}
number=LATB&0X0F;
number=CountBit(number);
Light(number);
}// End of teaching stage

number=LATB&0X0F;
number=CountBit(number);
Light(number);


if (state!=PORTB)
{
state=PORTB;
Light_2(state);
}

}if (LATB==0)
red==green==yellow==blue==0;
}

thomas thong
THOMAS_THONG

posted on 2014/07/04 12:38:41 PM CEST

Other Codes

Flash memory

write flash memory with library for PIC18, it's run, but I can't read flash if I don't use library. Writing is OK
TBLPTRL = Lo(address);
TBLPTRH = Hi(address);
TBLPTRU = Higher(address);

EECON1.EEPGD = 1;
EECON1.CFGS = 0;
EECON1.WREN = 1;
EECON1.FREE = 1;
INTCON.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1.WR = 1;
INTCON.GIE = 1;
asm TBLRD*- ;

FSR0L = Lo(data_w[64]);
FSR0H = Hi(data_w[64]);

i = 0;
while (i <64) {
TABLAT = POSTINC0;
asm {
TBLWT+*
}
i++;

EECON1.EEPGD = 1;
EECON1.CFGS = 0;
EECON1.WREN = 1;
INTCON.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1.WR = 1;
}
INTCON.GIE = 1;
EECON1.WREN = 0;

INTCON = saveintcon;


Please can help me!

kalaiyarasu k krishnamoorthi
artsking91

posted on 2014/03/03 04:44:24 PM CET

Other Codes

pic 18f4550 mickroc bootloader hex file need

i need a hex file of 18f4550 pic microcontroller if any one having please upload for me my mail id is artsking91@gmail.com

first | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 last