Das Open-Control-Projekt - Die Alternative zur C-Control-I


Das Forum zur C-Control-1
Welche C-Control-Varianten existieren?
Übersicht - Suchen - Neueste 50 Beiträge - Neuer Beitrag - Login - Registrieren
INFO - FAQ - CC2-Forum - CCPro-Forum 

 Re: My programm didn't works Kategorie: Programmierung Basic (von Hans - 29.10.2006 13:02)
 Als Antwort auf Re: My programm didn't works von Achim - 29.10.2006 1:22
Hans nutzt:  CC1-M-Unit V1.2/2.0
Thanks for your answer
I know that the NOR isn't correct
but the AND isn't correct too
because

 Temp=&B00000001
 IF AdIn>140 THEN Var1=Var1 OR Temp ELSE Var1=Var1 AND Temp

IF VAR1=1101
   AND  0001(Temp)
      = 0001

there must be a simpel sollution
but I don't see it.


'poort
DEFINE ADin            AD[1]
DEFINE PoortA         PORT[1]
DEFINE poortB         PORT[2]
DEFINE poortC         PORT[3]
DEFINE poortD         PORT[4]

'VAR
DEFINE Ieen           BIT[1]
DEFINE Itwee         BIT[2]
DEFINE Idrie          BIT[3]
DEFINE Ivier          BIT[4]
DEFINE I              BYTE[1]
DEFINE Var1        WORD[2]
DEFINE Temp       WORD[3]

#Ingangen
 Temp=&B00000001
 FOR I=0 to 15
 PortA=Ieen   'BCD code
 PortB=Itwee
 PortC=Idrie
 PortD=Ivier
 IF AdIn>140 THEN Var1=Var1 OR Temp ELSE Var1=Var1 NOR Temp
 Temp=Temp SHL 1
NEXT



> > I want to store 16 equation ( ON(1) or OFF(0) ) in 1 WORD
> > So that I can read it out later.
>
> >  IF AdIn>140 THEN Var1=Var1 OR Temp ELSE Var1=Var1 NOR Temp
>
> If you have a word with one bit set to 1 and the others set to 0 like your temp-variable (which is called a "mask") then you set this particular bit in a different variable by or-ing it bitwise, that is correct.
>
> But you erase it not by nor-ing it, but rather by and-ing it bitwise with the one's complement of the mask. Example (four bits for better readability):
>
> Set the bit:
> Mask: 0010
> Var: 0000
> Or: 0010
> Bit set, ok.
>
> Mask: 0010
> Var: 1111
> Or: 1111
> Bit still set, ok
>
> Erase the bit:
> Mask: 0010
> Var: 0000
> Nor: 1101
> Bit not set, other bits modified: incorrect!
>
> Mask: 0010
> 1's comp: 1101
> Var: 0000
> and: 0000
> Bit still erased, correct
>
> Mask: 0010
> 1's comp 1101
> Var: 1111
> and: 1101
> Bit erased, correct
>
> HTH
>
> Bye
>  Achim

 Antwort schreiben

Bisherige Antworten:

Re: My programm didn't works (von Achim - 29.10.2006 15:42)
    Re: My programm didn't works (von Hans - 29.10.2006 17:27)