<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=12&amp;t=8720&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-10-05T18:13:07+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=12&amp;t=8720&amp;mode</id>
<entry>
<author><name><![CDATA[pikczu]]></name></author>
<updated>2014-10-05T18:13:07+01:00</updated>
<published>2014-10-05T18:13:07+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8720&amp;p=97745#p97745</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8720&amp;p=97745#p97745"/>
<title type="html"><![CDATA[Re: Operacje na bitach maskowanie]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8720&amp;p=97745#p97745"><![CDATA[
Dobra już sobie poradziłem żeby uzyskać zamierzony efekt maskowania dla PWM0 czyli <span style="font-size: 150%; line-height: normal">01010110</span><br />Najpierw robię maskowanie tak jak dla włączenia led0 czyli <span style="color: #000000"><span style="font-size: 150%; line-height: normal">const led0_on   =&amp;B11111100</span></span> i dopiero w tedy maskuje ponownie<br /><span style="color: #000000"><span style="font-size: 150%; line-height: normal">const led0_PWM0 =&amp;B00000010</span></span><br />Podobne kroki wykonuje aby wyłączyć led0  z PWM0<br />[syntax=basic4gl]case 2 ' led0 off<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br />         bufor(5) = bufor(5) and led0_on      'AND zerowanie<br />         bufor(5) = bufor(5) or led0_off      ' OR ustwianie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))[/syntax]<br /><br />cały kod:[syntax=basic4gl]' i2c controlling single led of pca9551<br /><br />'Pawel 2014<br />'-----------------------------------------------------------------------------------------<br /><br />$Regfile = &quot;m2560def.dat&quot;<br />$Crystal = 16000000<br />$hwstack = 40<br />$swstack = 16<br />$framesize = 32<br />$BAUD = 19200<br /><br /><br />'configure the scl and sda pins<br />Config Sda = PortG.5   'pin4<br />Config Scl = PortE.3  'pin 5<br />I2cinit<br />dim choice as byte<br />dim b as byte<br /><br />dim bufor(10) as byte<br /><br />const i2crd=193<br />const i2cwr= 192<br /><br />const led0_on   =&amp;B11111100  'zerowanie AND maska 0 reszta bitów ustawiona na 1<br />const led0_off  =&amp;B00000001  ' ustawianie OR maska 1 reszta bitów ustawiona na 0<br />const led0_PWM0 =&amp;B00000010 ' make sureyou send first off mask then<br />const led0_PWM1 =&amp;B00000011  'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led1_on   =&amp;B11110011<br />const led1_off  =&amp;B00000100<br />const led1_PWM0 =&amp;B00001000<br />const led1_PWM1 =&amp;B00001100 'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led2_on   =&amp;B11001111<br />const led2_off  =&amp;B00010000<br />const led2_PWM0 =&amp;B00100000<br />const led2_PWM1 =&amp;B00110000 'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led3_on   =&amp;B00111111<br />const led3_off  =&amp;B01000000<br />const led3_PWM0 =&amp;B10000000<br />const led3_PWM1 =&amp;B11000000 'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led4_on   =&amp;B11111100<br />const led4_off  =&amp;B00000001<br />const led4_PWM0 =&amp;B00000010<br />const led4_PWM1 =&amp;B00000011 'use OR  after default condition 01010101 to change to  PWM1<br /><br /><br />const led5_on   =&amp;B11110011<br />const led5_off  =&amp;B00000100<br />const led5_PWM0 =&amp;B00001000<br />const led5_PWM1 =&amp;B00001100 'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led6_on   =&amp;B11001111<br />const led6_off  =&amp;B00010000<br />const led6_PWM0 =&amp;B00100000<br />const led6_PWM1 =&amp;B00110000 'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led7_on   =&amp;B00111111<br />const led7_off  =&amp;B01000000<br />const led7_PWM0 =&amp;B01000000<br />const led7_PWM1 =&amp;B11000000 'use OR  after default condition 01010101 to change to  PWM1<br /><br /><br /><br />const 0to3led_off =&amp;B01010101<br />const 0to3led_on  =&amp;B00000000<br /><br />const 4to7led_off =&amp;B01010101<br />const 4to7led_on  =&amp;B00000000<br /><br /><br />Do<br /><br />   Input &quot;0-read all ,1- led0 on  2- led0 off ,3 led0 PWM1 , 4 led0 PWM0  &quot; , Choice<br />   'uwaga po kazdej zmianie nie zapomnij odczytac aktualnego stanu<br />   'NACISNIJ 0<br /><br />   Select Case Choice<br />      Case 0 'Set LED0 on<br />         waitms 200<br />         I2cstart<br />         I2cwbyte i2cwr<br />         I2cwbyte &amp;B00010001<br />         i2crepstart<br />         I2cwbyte i2crd<br />         I2crbyte bufor(1),ack   'prescaler 0<br />         I2crbyte bufor(2),ack   'PWM 0<br />         i2crbyte bufor(3),ack   'prescaler 1<br />         I2crbyte bufor(4),ack   'pwm 1<br />         I2crbyte bufor(5),ack   'led 0 to 3<br />         I2crbyte bufor(6),ack   'led 4 to 7<br />         I2crbyte bufor(7),nack  'inputs<br />         i2cstop<br /><br /><br />      case 1 'Set LED0 on<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br /><br />         bufor(5) = bufor(5) and led0_on      'AND zerowanie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br /><br />      case 2 ' led0 off<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br />         bufor(5) = bufor(5) and led0_on      'AND zerowanie<br />         bufor(5) = bufor(5) or led0_off      ' OR ustwianie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br />      case 3 'led0 pwm1<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br /><br />         bufor(5) = bufor(5) or led0_PWM1<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br />         case 4 'led0 PWM0<br />          i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br /><br />         bufor(5) = bufor(5) and led0_on<br />         bufor(5) =bufor(5) or led0_PWM0<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br /><br />         '(<br />         case 5' led 2 on    'AND zerowanie<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br /><br />         bufor(5) = bufor(5) and led2_on      'AND zerowanie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br /><br /><br />         case 6 'led2 off<br /><br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br />         bufor(5) = bufor(5) or led2_off       ' OR ustwianie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br /><br /><br /><br />         case 7 'led3 on     'AND zerowanie<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br /><br />         bufor(5) = bufor(5) and led3_on       'AND zerowanie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br /><br />         case 8 'led3 off<br /><br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br />         bufor(5) = bufor(5) or led3_off       ' OR ustwianie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br /><br />         ')<br />      case 9' all on<br />         I2cstart                                                 ' Generate start code<br />         I2cwbyte i2cwr<br /><br />      I2cwbyte  &amp;B00010001  '10001 sub adres  plus auto increment<br />        I2cwbyte &amp;B11111111  '255 prescaler 0<br />         I2cwbyte &amp;B10000000   '128 PWM 0<br />         I2cwbyte &amp;B11111111   '255 prescaler 1<br />         I2cwbyte &amp;B10000000 ' 128 pwm 1<br />         I2cwbyte &amp;B00000000'  led 0 to 3<br />         I2cwbyte &amp;B00000000'led 4 to 7<br />         I2cstop<br /><br /><br /><br /><br />      case 10  'all off<br />         I2cstart                                                 ' Generate start code<br />         I2cwbyte i2cwr<br />         I2cwbyte  &amp;B00010001  '10001 sub adres  plus auto increment<br />         'bit 4 is auto increment i should look in to pdf to remind myself what is this doing<br />         I2cwbyte &amp;B11111111  '255 prescaler 0<br />         I2cwbyte &amp;B10000000   '128 PWM 0<br />         I2cwbyte &amp;B11111111  '255 prescaler 1<br />         I2cwbyte &amp;B10000000 ' 128 pwm 1<br />         I2cwbyte &amp;B01010101'  led 0 to 3<br />         I2cwbyte &amp;B01010101'led 4 to 7<br />         I2cstop<br />       case 11  'set PWM<br />          I2cstart                                                 ' Generate start code<br />         I2cwbyte i2cwr<br />         I2cwbyte 3<br />         I2cwbyte &amp;B00000110    '255 prescaler 1<br />         I2cstop<br /><br />      case else: print&quot; zastanów sie co robisz !&quot;<br />   End Select<br /><br />   waitms 500<br />   print<br />   print &quot;bufor1 &quot; ;bin(bufor(1))<br />   print<br />   print &quot;bufor2 &quot; ;bin(bufor(2))<br />   print<br />   print &quot;bufor3 &quot; ;bin(bufor(3))<br />   print<br />   print &quot;bufor4 &quot; ;bin(bufor(4))<br />   print<br />   print &quot;bufor5 &quot; ;bin(bufor(5))<br />   print<br />   print &quot;bufor6 &quot; ;bin(bufor(6))<br />   print<br />   print &quot;bufor7 &quot; ;bin(bufor(7))<br /><br />Loop<br /><br />End[/syntax]<br /><br />PS. Jeśli macie jakieś lepsze lub alternatywne rozwiązanie chętnie przetestuję.<br />Pozdrawiam <br />Paweł<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=154">pikczu</a> — 5 paź 2014, o 18:13</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[pikczu]]></name></author>
<updated>2014-10-05T17:02:23+01:00</updated>
<published>2014-10-05T17:02:23+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8720&amp;p=97738#p97738</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8720&amp;p=97738#p97738"/>
<title type="html"><![CDATA[Operacje na bitach maskowanie]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8720&amp;p=97738#p97738"><![CDATA[
Witam<br />Walczę z maskowaniem bitów jak w temacie. <br />Mam układ PCA9551 jest to bardzo ciekawy  migacz led na szynę i2C<br /><a href="http://www.nxp.com/documents/data_sheet/PCA9551.pdf"  class="postlink">http://www.nxp.com/documents/data_sheet/PCA9551.pdf</a><br />W opisie rejestrów widnieją poszczególne stany dla ledów.<br /><a href="http://forum.atnel.pl/_obrazki/o/154/51cf4081592534d511232cf9cdf28f6c.jpg"  class="postlink"><img src="http://forum.atnel.pl/_obrazki/o/thumb/154/51cf4081592534d511232cf9cdf28f6c.jpg" alt="Obrazek" /></a><br />Narysowałem tabelę dla lepszej widoczności<br /><br /><a href="http://forum.atnel.pl/_obrazki/o/154/6a930e2f4e467eead9aa239f45171b4d.jpg"  class="postlink"><img src="http://forum.atnel.pl/_obrazki/o/thumb/154/6a930e2f4e467eead9aa239f45171b4d.jpg" alt="Obrazek" /></a><br />Stan spoczynku to <span style="font-size: 150%; line-height: normal">01010101</span> LEdy od 0 do 3 wyłączone<br />Utworzyłem stałe zawierające maski żeby ułatwić sobie zadanie.<br />[syntax=basic4gl]const led0_on   =&amp;B11111100[/syntax]<br />Niestety utknąłem na masce dla PWM0. poprzednie maski dla LED0_0N, LED0_OFF są proste i działają bez problemu.<br />W masce dla LED0_PWM0 muszę wyzerować bit 0 i ustawić bit 1 niby proste ale utknąłem.<br /><br />cały kod: <br />[syntax=basic4gl]' i2c controlling single led of pca9551<br /><br />'Pawel 2014<br />'-----------------------------------------------------------------------------------------<br /><br />$Regfile = &quot;m2560def.dat&quot;<br />$Crystal = 16000000<br />$hwstack = 40<br />$swstack = 16<br />$framesize = 32<br />$BAUD = 19200<br /><br /><br />'configure the scl and sda pins<br />Config Sda = PortG.5   'pin4<br />Config Scl = PortE.3  'pin 5<br />I2cinit<br />dim choice as byte<br />dim b as byte<br /><br />dim bufor(10) as byte<br /><br />const i2crd=193<br />const i2cwr= 192<br /><br />const led0_on   =&amp;B11111100  'zerowanie maska 0 reszta bitów ustawiona na 1<br />const led0_off  =&amp;B00000001  ' ustawianie maska 1 reszta bitów ustawiona na 0<br />const led0_PWM0 =&amp;B00000010<br />const led0_PWM1 =&amp;B00000011  'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led1_on   =&amp;B11110011<br />const led1_off  =&amp;B00000100<br />const led1_PWM0 =&amp;B00001000<br />const led1_PWM1 =&amp;B00001100 'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led2_on   =&amp;B11001111<br />const led2_off  =&amp;B00010000<br />const led2_PWM0 =&amp;B00100000<br />const led2_PWM1 =&amp;B00110000 'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led3_on   =&amp;B00111111<br />const led3_off  =&amp;B01000000<br />const led3_PWM0 =&amp;B10000000<br />const led3_PWM1 =&amp;B11000000 'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led4_on   =&amp;B11111100<br />const led4_off  =&amp;B00000001<br />const led4_PWM0 =&amp;B00000010<br />const led4_PWM1 =&amp;B00000011 'use OR  after default condition 01010101 to change to  PWM1<br /><br /><br />const led5_on   =&amp;B11110011<br />const led5_off  =&amp;B00000100<br />const led5_PWM0 =&amp;B00001000<br />const led5_PWM1 =&amp;B00001100 'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led6_on   =&amp;B11001111<br />const led6_off  =&amp;B00010000<br />const led6_PWM0 =&amp;B00100000<br />const led6_PWM1 =&amp;B00110000 'use OR  after default condition 01010101 to change to  PWM1<br /><br />const led7_on   =&amp;B00111111<br />const led7_off  =&amp;B01000000<br />const led7_PWM0 =&amp;B01000000<br />const led7_PWM1 =&amp;B11000000 'use OR  after default condition 01010101 to change to  PWM1<br /><br /><br /><br />const 0to3led_off =&amp;B01010101<br />const 0to3led_on  =&amp;B00000000<br /><br />const 4to7led_off =&amp;B01010101<br />const 4to7led_on  =&amp;B00000000<br /><br />Do<br /><br />   Input &quot;0-read all ,1- led0 on  2- led0 off ,3 led0 PWM1&quot; , Choice<br />   'uwaga po kazdej zmianie nie zapomnij odczytac aktualnego stanu<br />   'NACISNIJ 0<br /><br />   Select Case Choice<br />      Case 0 'Set LED0 on<br />         waitms 200<br />         I2cstart<br />         I2cwbyte i2cwr<br />         I2cwbyte &amp;B00010001<br />         i2crepstart<br />         I2cwbyte i2crd<br />         I2crbyte bufor(1),ack   'prescaler 0<br />         I2crbyte bufor(2),ack   'PWM 0<br />         i2crbyte bufor(3),ack   'prescaler 1<br />         I2crbyte bufor(4),ack   'pwm 1<br />         I2crbyte bufor(5),ack   'led 0 to 3<br />         I2crbyte bufor(6),ack   'led 4 to 7<br />         I2crbyte bufor(7),nack  'inputs<br />         i2cstop<br /><br /><br />      case 1 'Set LED0 on<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br /><br />         bufor(5) = bufor(5) and led0_on      'AND zerowanie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br /><br />      case 2 ' led0 off<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br /><br />         bufor(5) = bufor(5) or led0_off      ' OR ustwianie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br />      case 3 'led0 pwm1<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br /><br />         bufor(5) = bufor(5) or led0_PWM1<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br />         '(case 4  'led1 off<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br />         bufor(5) = bufor(5) or led1_off      ' OR ustwianie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br />         case 5' led 2 on    'AND zerowanie<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br /><br />         bufor(5) = bufor(5) and led2_on      'AND zerowanie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br /><br />         case 6 'led2 off<br /><br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br />         bufor(5) = bufor(5) or led2_off       ' OR ustwianie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br /><br />         case 7 'led3 on     'AND zerowanie<br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br /><br />         bufor(5) = bufor(5) and led3_on       'AND zerowanie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br /><br />         case 8 'led3 off<br /><br />         i2cstart<br />         i2cwbyte i2cwr<br />         i2cwbyte 5<br />         bufor(5) = bufor(5) or led3_off       ' OR ustwianie<br />         i2cwbyte  bufor(5)<br />         i2cstop<br />         print &quot;bufor 5= &quot;; bin(bufor(5))<br /><br />         ')<br />      case 9' all on<br />         I2cstart                                                 ' Generate start code<br />         I2cwbyte i2cwr<br />         I2cwbyte  &amp;B00010001  '10001 sub adres  plus auto increment<br />         I2cwbyte &amp;B11111111  '255 prescaler 0<br />         I2cwbyte &amp;B10000000   '128 PWM 0<br />         I2cwbyte &amp;B11111111  '255 prescaler 1<br />         I2cwbyte &amp;B10000000 ' 128 pwm 1<br />         I2cwbyte &amp;B00000000'  led 0 to 3<br />         I2cwbyte &amp;B00000000'led 4 to 7<br />         I2cstop<br /><br /><br />      case 10  'all off<br />         I2cstart                                                 ' Generate start code<br />         I2cwbyte i2cwr<br />         I2cwbyte  &amp;B00010001  '10001 sub adres  plus auto increment<br />         'bit 4 is auto increment i should look in to pdf to remind myself what is this doing<br />         I2cwbyte &amp;B11111111  '255 prescaler 0<br />         I2cwbyte &amp;B10000000   '128 PWM 0<br />         I2cwbyte &amp;B11111111  '255 prescaler 1<br />         I2cwbyte &amp;B10000000 ' 128 pwm 1<br />         I2cwbyte &amp;B01010101'  led 0 to 3<br />         I2cwbyte &amp;B01010101'led 4 to 7<br />         I2cstop<br /><br /><br />      case else: print&quot; zastanów sie co robisz !&quot;<br />   End Select<br /><br />   waitms 500<br />   print<br />   print &quot;bufor1 &quot; ;bin(bufor(1))<br />   print<br />   print &quot;bufor2 &quot; ;bin(bufor(2))<br />   print<br />   print &quot;bufor3 &quot; ;bin(bufor(3))<br />   print<br />   print &quot;bufor4 &quot; ;bin(bufor(4))<br />   print<br />   print &quot;bufor5 &quot; ;bin(bufor(5))<br />   print<br />   print &quot;bufor6 &quot; ;bin(bufor(6))<br />   print<br />   print &quot;bufor7 &quot; ;bin(bufor(7))<br /><br />Loop<br /><br />End[/syntax]<br />Pozdrawiam <br />Paweł<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=154">pikczu</a> — 5 paź 2014, o 17:02</p><hr />
]]></content>
</entry>
</feed>