Jump to content
Sign in to follow this  
asimo

clear bit?

Recommended Posts

First one clears just one bit (T0IF) from a variable INTCON.

 

Another one is trying to set a value to (possibly) constant variable called T0IF;

Share this post


Link to post
Share on other sites

asimo, just wondering how you came up with the screen name.  Is it from Isac Asimov, the writer of the three laws of Robotics from the March 1942 magazine publication Astounding the story called "Runaround" In wich he established his three fundemental laws of robotics.  The most recent publication was with Robin Williams in Bicentennial Man (Movie), in which these three laws came in a holographic form from his heads holographic display.  Or are you refering to the Honda ASIMO project which I would most likely believe was named after Asimov.  It is such a striking resembelence it is uncanny.

Share this post


Link to post
Share on other sites
Guest kolitham

Is there a way to define bit(s) as variables and read and write to them via assigning variables? [ Hi-tech C has this]

 

Appreciate advice.

 

Thanks & Regards

 

Kolitham

Share this post


Link to post
Share on other sites
Is there a way to define bit(s) as variables and read and write to them via assigning variables? [ Hi-tech C has this]

No, but its something we all end up requesting sooner or later :)

Share this post


Link to post
Share on other sites
Guest Dave

Stringer,

 

(Guest @ Mar. 02 2004,06:28)

Is there a way to define bit(s) as variables and read and write to them via assigning variables? [ Hi-tech C has this]

 

No, but its something we all end up requesting sooner or later

 

This type of functionality will be included in the new compiler that is currently under development :)

 

Regards

Dave

Share this post


Link to post
Share on other sites

(sorry for my English)

 

but if I write T0IF=..

               GIE=...

 

it does't work

 

ex

 

 

 

#pragma CLOCK_FREQ 4000000

 

//------------------------------------------------

void interrupt( void )

{

 PORTB ^= 0x80;            // complement PORTB:7

 T0IF=0;   // clear TMR0 overflow flag

}

//------------------------------------------------

 

main()

{

 OPTION_REG = 7;       // set prescaler to 1:256

 clear_bit(TRISB,7);   // set PORTB:7 as OUTPUT

 

 GIE =1;  // enable interrupts

 T0IE =1; // enable TMR0 overflow bit

 

 while(1)

 {

   clear_wdt();

 }

}

 

 

clear...(..) and TOIF=0

have the same meaning????

Share this post


Link to post
Share on other sites
Guest asimo

(sorry for my english)

 

hi,

but T0IF=0 and clear....()  have the same meaning in c2c?

can I use the firt one?

Share this post


Link to post
Share on other sites

T0IF, T0IE, GIE, etc. are all just variables defining bit positions. They aren't pointers or anything like that. So even if you could change them, you would just change the value they currently have instead the bit in some other variable.

 

In case I was unclear: it doesn't work like that, just keep using the clear_bit()-function.

Share this post


Link to post
Share on other sites
Guest asimo

#include

#pragma CLOCK_FREQ 20000000

 

 

main()

{

 

int distanza;

trisd=0x00;

 

adcon0=0x81;                 //0b10000001

 

adcon1=0x80;                 //0b10000000

 

while(1)

{

    adcon0=0x08;

    distanza = 0;

    while((adcon0&0x04)==0x00);

   

    distanza = adresl+(adresh<<8);

 

    if(distanza>266){portd=0x10;}

else if((distanza<=266)&&(distanza>204)){portd=0x20;}

else {portd=0x30; }  

 

}

}

 

there ara no error in the code

but this prog. doesn't work

can sombody correct it.

Share this post


Link to post
Share on other sites
Guest Dave

Asimo,

 

I think you should provide a description of what the programs meant to be doing, otherwise we are just left to guess.

 

Also when you say it "doesn't work" please explain further.

Do you mean it doesn't compile?

If it doesn't work as expected, what did you expect to happen, and what is happening?

 

Regards

Dave

Share this post


Link to post
Share on other sites
Guest asimo

This a sample program for gp2d12 sensor.

the sensor have a output Voltage(0,4-2,4V)

 

#include

#pragma CLOCK_FREQ 20000000

 

 

main()

{

 

int distance;

trisd=0x00;

 

adcon0=0x81;  //0b10000001 ->set port A anal.input,vcc ref V

 

adcon1=0x80; //0b10000000 --> Right justified

 

while(1)

{

   adcon0=0x08;  //ADGO =1

   distance = 0;

   while((adcon0&0x04)==0x00);  //wait ADGO=0

   

   distance = adresl+(adresh<<8); //value of adresL-H = 10bit

 

   if(distance>266){portd=0x10;}

else if((distance<=266)&&(distance>204)){portd=0x20;}

else {portd=0x30; }  

 

}

}

 

thera are no error when compile

 

the display connected to portd shows "3" and it dosn t change value if the sensor is close or far an object

 

I tried use the picc lite (ht-soft.com) with this same program and it works. why with picant it doest work there are some mistake in this code.

(pic16f877)

thx

Share this post


Link to post
Share on other sites

Whats wrong with it?

 

I would try to divide this line to multiple parts:

distance = adresl+(adresh<<8);

 

Like this:

distance = adresh;

distance <<= 8;

distance = distance+adresl;

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...