Fredy Pachon

How to manipulate one bit in a register?

Discussion created by Fredy Pachon on Feb 5, 2008
Latest reply on Feb 7, 2008 by Fredy Pachon
Hi,
I have a little trouble.
I need to change one bit  in  one register on my program,  if that bit is zero chage to one a vice-versa.


#include <hidef.h>
#include "derivative.h"
int dato;                 
DDRA=0x00;
PTA=dato;

how I can ask about seven bit y my variable "dato" and change only that bit?
 I have tried to use this:

asm bclr 7, dato          //if I use this, I have a mistake when a compile   ( "invalid opcode or ":" expected)


also I try with this:

DDRA=0x00;          //first port as input
dato =PTA;            
change();


void change (void){
 

 DDRA=0xFF;      //then por as output
 PTA=dato;
 
        if (PTA_PTA7==1){
        PTA_PTA7=0;
        dato=PTA;}
         else{
             if (PTA_PTA7==0){
             PTA_PTA7=1;
             dato=PTA;}
              else{}
             }
          dato=PTA;
         
}

When I simulate this program  it works,  but I think there isn't to useful and so complicated   ¿I can manipule only one bit in the variable "dato"?


thanks for your answers.

Regars,
Fredy


Outcomes